Files
bux-lang/tests/golden/generics/expected.c
T

4853 lines
114 KiB
C

/* Generated by Bux Compiler (LIR backend) */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
typedef struct TaskHandle TaskHandle;
typedef struct Mutex Mutex;
typedef struct RwLock RwLock;
typedef struct JsonValue JsonValue;
typedef struct JsonParser JsonParser;
typedef struct StringBuilder StringBuilder;
typedef struct Channel_int Channel_int;
typedef struct Channel_float64 Channel_float64;
typedef struct Drop_FatPtr Drop_FatPtr;
/* Extern function declarations */
extern int bux_dir_exists(const char* path);
extern int bux_mkdir_if_needed(const char* path);
extern const char** bux_list_dir(const char* dir, const char* ext, int* out_count);
extern void PrintLine(const char* s);
extern void Print(const char* s);
extern void PrintInt(int n);
extern void PrintInt64(int64_t n);
extern void PrintFloat(double f);
extern void PrintBool(bool b);
extern const char* ReadLine(void);
extern const char* bux_read_file(const char* path);
extern int bux_write_file(const char* path, const char* content);
extern int bux_file_exists(const char* path);
extern double bux_sqrt(double x);
extern double bux_pow(double x, double y);
extern int64_t bux_abs_i64(int64_t x);
extern double bux_abs_f64(double x);
extern int64_t bux_min_i64(int64_t a, int64_t b);
extern int64_t bux_max_i64(int64_t a, int64_t b);
extern double bux_min_f64(double a, double b);
extern double bux_max_f64(double a, double b);
extern void* bux_alloc(unsigned int size);
extern void* bux_realloc(void* ptr, unsigned int size);
extern void bux_free(void* ptr);
extern int bux_mem_eq(void* a, void* b, unsigned int size);
extern const char* bux_path_join(const char* a, const char* b);
extern const char* bux_path_parent(const char* path);
extern const char* bux_path_ext(const char* path);
extern void bux_task_init(int num_workers);
extern void* bux_task_spawn(void* fn, void* arg);
extern void bux_task_join(void* handle);
extern void bux_task_sleep(int64_t ms);
extern void bux_task_yield(void);
extern int bux_task_current_id(void);
extern void bux_task_shutdown(void);
extern int bux_argc(void);
extern const char* bux_argv(int index);
extern const char* bux_getenv(const char* name);
extern int bux_setenv(const char* name, const char* value);
extern const char* bux_getcwd(void);
extern int bux_chdir(const char* path);
extern int64_t bux_time_ms(void);
extern int64_t bux_time_us(void);
extern void bux_sleep_ms(int64_t ms);
extern int bux_process_run(const char* cmd);
extern const char* bux_process_output(const char* cmd);
extern int bux_socket_create(void);
extern int bux_socket_reuse(int fd);
extern int bux_socket_bind(int fd, const char* addr, int port);
extern int bux_socket_listen(int fd, int backlog);
extern int bux_socket_accept(int fd);
extern int bux_socket_connect(int fd, const char* addr, int port);
extern int bux_socket_send(int fd, const char* data, int len);
extern const char* bux_socket_recv(int fd, int maxLen);
extern int bux_socket_close(int fd);
extern const char* bux_socket_error(void);
extern unsigned int bux_strlen(const char* s);
extern int64_t bux_str_to_int(const char* s);
extern void* bux_alloc(unsigned int size);
extern void bux_sha256(const char* data, int len, void* out);
extern void bux_hmac_sha256(const char* key, int keylen, const char* msg, int msglen, void* out);
extern int bux_random_bytes(void* buf, int len);
extern const char* bux_base64_encode(const char* data, int len);
extern const char* bux_base64_decode(const char* data, int len, int* outlen);
extern const char* bux_bytes_to_hex(void* data, int len);
extern void* bux_mutex_new(void);
extern void bux_mutex_lock(void* handle);
extern void bux_mutex_unlock(void* handle);
extern void bux_mutex_free(void* handle);
extern void* bux_rwlock_new(void);
extern void bux_rwlock_rdlock(void* handle);
extern void bux_rwlock_wrlock(void* handle);
extern void bux_rwlock_unlock(void* handle);
extern void bux_rwlock_free(void* handle);
extern void bux_exit(int code);
extern void bux_assert(int cond, const char* file, int line, const char* expr);
extern JsonValue JsonParser_ParseValue(JsonParser* p);
extern unsigned int bux_strlen(const char* s);
extern int bux_strcmp(const char* a, const char* b);
extern int bux_strncmp(const char* a, const char* b, unsigned int n);
extern char* bux_strcpy(char* dest, const char* src);
extern char* bux_strcat(char* dest, const char* src);
extern char* bux_strncpy(char* dest, const char* src, unsigned int n);
extern const char* bux_strstr(const char* haystack, const char* needle);
extern int bux_str_contains(const char* haystack, const char* needle);
extern unsigned int bux_str_offset(const char* pos, const char* base);
extern int bux_str_is_null(const char* s);
extern const char* bux_str_slice(const char* s, unsigned int start, unsigned int len);
extern const char* bux_str_trim_left(const char* s);
extern const char* bux_str_trim_right(const char* s);
extern const char* bux_str_trim(const char* s);
extern const char* bux_int_to_str(int64_t n);
extern int64_t bux_str_to_int(const char* s);
extern void* bux_sb_new(unsigned int initial_cap);
extern void bux_sb_append(void* sb, const char* s);
extern void bux_sb_append_int(void* sb, int64_t n);
extern void bux_sb_append_float(void* sb, double f);
extern void bux_sb_append_char(void* sb, char c);
extern const char* bux_sb_build(void* sb);
extern void bux_sb_free(void* sb);
extern unsigned int bux_str_split_count(const char* s, const char* delim);
extern const char* bux_str_split_part(const char* s, const char* delim, unsigned int index);
extern const char* bux_str_join2(const char* a, const char* b, const char* sep);
extern const char* bux_float_to_string(double f);
extern const char* bux_str_format(const char* pattern, const char* a0, const char* a1, const char* a2, const char* a3, const char* a4, const char* a5, const char* a6, const char* a7);
extern double bux_str_to_float(const char* s);
extern void bux_bounds_check(unsigned int index, unsigned int len);
extern void* bux_alloc(unsigned int size);
extern void* bux_realloc(void* ptr, unsigned int size);
extern void bux_free(void* ptr);
extern void bux_bounds_check(unsigned int index, unsigned int len);
extern void* bux_channel_new(int64_t capacity, int64_t elem_size);
extern void bux_channel_send(void* handle, void* elem);
extern int bux_channel_recv(void* handle, void* out);
extern void bux_channel_close(void* handle);
extern void bux_channel_free(void* handle);
extern unsigned int bux_hash_bytes(void* ptr, unsigned int size);
extern unsigned int bux_hash_string(const char* s);
extern unsigned int bux_hash_bytes(void* ptr, unsigned int size);
extern int bux_mem_eq(void* a, void* b, unsigned int size);
extern void* bux_alloc(unsigned int size);
extern void bux_free(void* ptr);
extern void bux_sha1(const char* data, int len, void* out);
extern void bux_sha256(const char* data, int len, void* out);
extern void bux_sha384(const char* data, int len, void* out);
extern void bux_sha512(const char* data, int len, void* out);
extern const char* bux_bytes_to_hex(void* data, int len);
extern const char* bux_base64_encode(const char* data, int len);
extern const char* bux_base64_decode(const char* data, int len, int* outlen);
extern const char* bux_base64url_encode(const char* data, int len);
extern const char* bux_base64url_decode(const char* data, int len, int* outlen);
extern void bux_hmac_sha256(const char* key, int keylen, const char* msg, int msglen, void* out);
extern void bux_hmac_sha384(const char* key, int keylen, const char* msg, int msglen, void* out);
extern void bux_hmac_sha512(const char* key, int keylen, const char* msg, int msglen, void* out);
extern const char* bux_bytes_to_hex(void* data, int len);
extern const char* bux_base64_encode(const char* data, int len);
extern int bux_random_bytes(void* buf, int len);
extern const char* bux_base64_encode(const char* data, int len);
extern const char* bux_bytes_to_hex(void* data, int len);
extern int bux_random_bytes(void* buf, int len);
extern const char* bux_aes_256_cbc_encrypt(const char* plain, int plainlen, const char* key, const char* iv, int* outlen);
extern const char* bux_aes_256_cbc_decrypt(const char* cipher, int cipherlen, const char* key, const char* iv, int* outlen);
extern const char* bux_aes_256_gcm_encrypt(const char* plain, int plainlen, const char* key, const char* iv, void* tag, int* outlen);
extern const char* bux_aes_256_gcm_decrypt(const char* cipher, int cipherlen, const char* key, const char* iv, const char* tag, int* outlen);
extern const char* bux_base64_encode(const char* data, int len);
extern unsigned int bux_str_split_count(const char* s, const char* delim);
extern const char* bux_str_split_part(const char* s, const char* delim, unsigned int index);
extern const char* bux_ecdsa_sign_p256(const char* key, int keylen, const char* data, int datalen, int* outlen);
extern int bux_ecdsa_verify_p256(const char* key, int keylen, const char* data, int datalen, const char* sig, int siglen);
extern const char* bux_ecdsa_sign_p384(const char* key, int keylen, const char* data, int datalen, int* outlen);
extern int bux_ecdsa_verify_p384(const char* key, int keylen, const char* data, int datalen, const char* sig, int siglen);
extern const char* bux_base64_encode(const char* data, int len);
extern const char* bux_base64_decode(const char* data, int len, int* outlen);
extern int bux_ed25519_keypair(void* pubKey, void* privKey);
extern int bux_ed25519_sign(const char* privKey, const char* data, int datalen, void* sig);
extern int bux_ed25519_verify(const char* pubKey, const char* sig, const char* data, int datalen);
extern const char* bux_base64_encode(const char* data, int len);
extern const char* bux_base64_decode(const char* data, int len, int* outlen);
extern const char* bux_rsa_sign_sha256(const char* key, int keylen, const char* data, int datalen, int* outlen);
extern const char* bux_rsa_sign_sha384(const char* key, int keylen, const char* data, int datalen, int* outlen);
extern const char* bux_rsa_sign_sha512(const char* key, int keylen, const char* data, int datalen, int* outlen);
extern int bux_rsa_verify_sha256(const char* key, int keylen, const char* data, int datalen, const char* sig, int siglen);
extern int bux_rsa_verify_sha384(const char* key, int keylen, const char* data, int datalen, const char* sig, int siglen);
extern int bux_rsa_verify_sha512(const char* key, int keylen, const char* data, int datalen, const char* sig, int siglen);
extern const char* bux_base64_encode(const char* data, int len);
extern const char* bux_base64_decode(const char* data, int len, int* outlen);
/* Constants */
#define JsonTagNull 0
#define JsonTagBool 1
#define JsonTagNumber 2
#define JsonTagString 3
#define JsonTagArray 4
#define JsonTagObject 5
#define AES_KEY_SIZE 32
#define AES_IV_SIZE 16
#define AES_GCM_TAG_SIZE 16
#define ED25519_PUBKEY_SIZE 32
#define ED25519_PRIVKEY_SIZE 32
#define ED25519_SIG_SIZE 64
typedef enum {
Result_Ok,
Result_Err
} Result_Tag;
typedef union {
int Ok_0;
const char* Err_0;
} Result_Data;
typedef struct {
Result_Tag tag;
Result_Data data;
} Result;
typedef enum {
Option_Some,
Option_None
} Option_Tag;
typedef union {
int Some_0;
} Option_Data;
typedef struct {
Option_Tag tag;
Option_Data data;
} Option;
typedef enum {
JwtAlg_HS256,
JwtAlg_HS384,
JwtAlg_HS512,
JwtAlg_RS256,
JwtAlg_RS384,
JwtAlg_RS512,
JwtAlg_ES256,
JwtAlg_ES384,
JwtAlg_EdDSA
} JwtAlg;
typedef struct TaskHandle {
void* handle;
} TaskHandle;
typedef struct Mutex {
void* handle;
} Mutex;
typedef struct RwLock {
void* handle;
} RwLock;
typedef struct JsonValue {
int tag;
bool boolVal;
double numVal;
const char* strVal;
JsonValue* arrData;
unsigned int arrLen;
unsigned int arrCap;
const char** objKeys;
JsonValue* objValues;
unsigned int objLen;
unsigned int objCap;
} JsonValue;
typedef struct JsonParser {
const char* src;
unsigned int pos;
unsigned int len;
const char* error;
} JsonParser;
typedef struct StringBuilder {
void* handle;
} StringBuilder;
typedef struct Channel_int {
void* handle;
} Channel_int;
typedef struct Channel_float64 {
void* handle;
} Channel_float64;
bool DirExists(const char* path);
bool Mkdir(const char* path);
const char** ListDir(const char* dir, const char* ext, int* count);
const char* ReadFile(const char* path);
bool WriteFile(const char* path, const char* content);
bool FileExists(const char* path);
double Sqrt(double x);
double Pow(double x, double y);
int64_t Abs(int64_t n);
double AbsF(double f);
int64_t Min(int64_t a, int64_t b);
double MinF(double a, double b);
double MaxF(double a, double b);
void* Alloc(unsigned int size);
void* Realloc(void* ptr, unsigned int size);
void Free(void* ptr);
bool MemEq(void* a, void* b, unsigned int size);
const char* Path_Join(const char* a, const char* b);
const char* Path_Parent(const char* path);
const char* Path_Ext(const char* path);
void Task_Init(int num_workers);
TaskHandle Task_Spawn(void* fn, void* arg);
void Task_Wait(TaskHandle t);
void Task_Sleep(int64_t ms);
void Task_Yield(void);
int Task_CurrentId(void);
void Task_Shutdown(void);
int Os_ArgsCount(void);
const char* Os_Args(int index);
const char* Os_GetEnv(const char* name);
bool Os_SetEnv(const char* name, const char* value);
const char* Os_GetCwd(void);
bool Os_Chdir(const char* path);
int64_t Time_NowMs(void);
int64_t Time_NowUs(void);
void Time_SleepMs(int64_t ms);
int Process_Run(const char* cmd);
const char* Process_Output(const char* cmd);
int Net_Create(void);
bool Net_SetReuse(int fd);
bool Net_Bind(int fd, const char* addr, int port);
bool Net_Listen(int fd, int backlog);
int Net_Accept(int fd);
bool Net_Connect(int fd, const char* addr, int port);
int Net_Send(int fd, const char* data);
const char* Net_Recv(int fd, int maxLen);
bool Net_Close(int fd);
const char* Net_LastError(void);
const char* Fmt_Format(const char* tmpl, const char** argStrs, int argCount);
const char* Fmt_Fmt1(const char* tmpl, const char* a1);
const char* Fmt_FmtInt(const char* tmpl, int64_t val);
const char* Fmt_FmtBool(const char* tmpl, bool val);
const char* Fmt_FmtFloat(const char* tmpl, double val);
const char* Fmt_Fmt2(const char* tmpl, const char* a1, const char* a2);
const char* Fmt_Fmt3(const char* tmpl, const char* a1, const char* a2, const char* a3);
const char* Crypto_Sha256(const char* data);
const char* Crypto_HmacSha256(const char* key, const char* message);
const char* Crypto_RandomBytes(int n);
const char* Crypto_Base64Encode(const char* s);
const char* Crypto_HmacSha256Raw(const char* key, const char* message);
const char* Crypto_Base64Decode(const char* s);
Mutex Mutex_New(void);
void Mutex_Lock(Mutex* m);
void Mutex_Unlock(Mutex* m);
void Mutex_Free(Mutex* m);
RwLock RwLock_New(void);
void RwLock_ReadLock(RwLock* rw);
void RwLock_WriteLock(RwLock* rw);
void RwLock_Unlock(RwLock* rw);
void RwLock_Free(RwLock* rw);
void Test_Exit(int code);
void Test_Assert(bool cond);
void Test_AssertEqInt(int a, int b);
void Test_AssertTrue(bool cond);
void Test_AssertFalse(bool cond);
void Test_Fail(const char* msg);
Result Result_NewOk(int value);
Result Result_NewErr(const char* msg);
bool Result_IsOk(Result r);
bool Result_IsErr(Result r);
int Result_Unwrap(Result r);
int Result_UnwrapOr(Result r, int fallback);
Option Option_NewSome(int value);
Option Option_NewNone(void);
bool Option_IsSome(Option o);
bool Option_IsNone(Option o);
int Option_Unwrap(Option o);
int Option_UnwrapOr(Option o, int fallback);
JsonValue Json_Null(void);
JsonValue Json_Bool(bool b);
JsonValue Json_Number(double n);
JsonValue Json_String(const char* s);
JsonValue Json_Array(void);
JsonValue Json_Object(void);
unsigned int Json_ArrayLen(JsonValue v);
JsonValue Json_ArrayGet(JsonValue v, unsigned int index);
void Json_ArrayPush(JsonValue* self, JsonValue val);
unsigned int Json_ObjectLen(JsonValue v);
JsonValue Json_ObjectGet(JsonValue v, const char* key);
bool Json_ObjectHas(JsonValue v, const char* key);
void Json_ObjectSet(JsonValue* self, const char* key, JsonValue val);
bool Json_IsNull(JsonValue v);
bool Json_AsBool(JsonValue v);
double Json_AsNumber(JsonValue v);
const char* Json_AsString(JsonValue v);
int JsonParser_Peek(JsonParser* p);
void JsonParser_Advance(JsonParser* p);
void JsonParser_SkipWhitespace(JsonParser* p);
bool JsonParser_Match(JsonParser* p, const char* expected);
const char* JsonParser_ParseString(JsonParser* p);
JsonValue JsonParser_ParseNumber(JsonParser* p);
JsonValue JsonParser_ParseArray(JsonParser* p);
JsonValue JsonParser_ParseObject(JsonParser* p);
JsonValue JsonParser_ParseValue(JsonParser* p);
JsonValue Json_Parse(const char* s);
void Json_StringifyImpl(StringBuilder* sb, JsonValue v);
const char* Json_Stringify(JsonValue v);
unsigned int String_Len(const char* s);
bool String_IsNull(const char* s);
bool String_Eq(const char* a, const char* b);
const char* String_Concat(const char* a, const char* b);
const char* String_Copy(const char* s);
bool String_StartsWith(const char* s, const char* prefix);
bool String_EndsWith(const char* s, const char* suffix);
bool String_Contains(const char* s, const char* substr);
const char* String_Slice(const char* s, unsigned int start, unsigned int len);
const char* String_Trim(const char* s);
const char* String_TrimLeft(const char* s);
const char* String_TrimRight(const char* s);
const char* String_FromInt(int64_t n);
int64_t String_ToInt(const char* s);
StringBuilder StringBuilder_New(void);
StringBuilder StringBuilder_NewCap(unsigned int cap);
void StringBuilder_Append(StringBuilder* sb, const char* s);
void StringBuilder_AppendInt(StringBuilder* sb, int64_t n);
void StringBuilder_AppendFloat(StringBuilder* sb, double f);
void StringBuilder_AppendChar(StringBuilder* sb, char c);
const char* StringBuilder_Build(StringBuilder* sb);
void StringBuilder_Free(StringBuilder* sb);
unsigned int String_SplitCount(const char* s, const char* delim);
const char* String_SplitPart(const char* s, const char* delim, unsigned int index);
const char* String_Join2(const char* a, const char* b, const char* sep);
const char* String_Chars(const char* s, unsigned int index);
const char* String_Find(const char* haystack, const char* needle);
unsigned int String_Offset(const char* pos, const char* base);
const char* String_Replace(const char* s, const char* old, const char* new);
double String_ToFloat(const char* s);
const char* String_FromBool(bool b);
const char* String_FromFloat(double f);
const char* String_Format1(const char* pattern, const char* a0);
const char* String_Format2(const char* pattern, const char* a0, const char* a1);
const char* String_Format3(const char* pattern, const char* a0, const char* a1, const char* a2);
void Channel_SendInt(Channel_int* ch, int value);
int Channel_RecvInt(Channel_int* ch);
void Channel_SendFloat64(Channel_float64* ch, double value);
double Channel_RecvFloat64(Channel_float64* ch);
const char* Hash_Sha1(const char* data);
const char* Hash_Sha256(const char* data);
const char* Hash_Sha384(const char* data);
const char* Hash_Sha512(const char* data);
void Hash_Sha256Raw(const char* data, void* out);
void Hash_Sha384Raw(const char* data, void* out);
void Hash_Sha512Raw(const char* data, void* out);
int Hash_Sha1Size(void);
int Hash_Sha256Size(void);
int Hash_Sha384Size(void);
int Hash_Sha512Size(void);
const char* Base64_Encode(const char* s);
const char* Base64_Decode(const char* s);
const char* Base64URL_Encode(const char* s);
const char* Base64URL_Decode(const char* s);
const char* Hmac_Sha256(const char* key, const char* message);
void Hmac_Sha256Raw(const char* key, const char* message, void* out);
const char* Hmac_Sha256Base64(const char* key, const char* message);
const char* Hmac_Sha384(const char* key, const char* message);
void Hmac_Sha384Raw(const char* key, const char* message, void* out);
const char* Hmac_Sha384Base64(const char* key, const char* message);
const char* Hmac_Sha512(const char* key, const char* message);
void Hmac_Sha512Raw(const char* key, const char* message, void* out);
const char* Hmac_Sha512Base64(const char* key, const char* message);
const char* Random_Bytes(int n);
const char* Random_Hex(int n);
const char* Random_Base64(int n);
unsigned int Random_Uint32(void);
const char* Aes_GenerateKey(void);
const char* Aes_GenerateIV(void);
const char* Aes_CbcEncrypt(const char* plain, const char* key, const char* iv);
const char* Aes_CbcDecrypt(const char* cipher, const char* key, const char* iv);
const char* Aes_GcmEncrypt(const char* plain, const char* key, const char* iv, void* tag);
const char* Aes_GcmDecrypt(const char* cipher, const char* key, const char* iv, const char* tag);
const char* Jwt_MakeHeader(JwtAlg alg);
const char* Jwt_Sign(JwtAlg alg, const char* signingInput, const char* key);
bool Jwt_Verify(JwtAlg alg, const char* signingInput, const char* signatureB64, const char* key);
const char* Jwt_Encode(const char* headerJson, const char* payloadJson, JwtAlg alg, const char* key);
bool Jwt_Decode(const char* token, JwtAlg alg, const char* key, const char** headerOut, const char** payloadOut);
const char* Jwt_EncodeHS256(const char* payloadJson, const char* secret);
const char* Jwt_EncodeHS384(const char* payloadJson, const char* secret);
const char* Jwt_EncodeHS512(const char* payloadJson, const char* secret);
const char* Jwt_EncodeRS256(const char* payloadJson, const char* pemPrivateKey);
const char* Jwt_EncodeES256(const char* payloadJson, const char* pemPrivateKey);
const char* Jwt_EncodeEdDSA(const char* payloadJson, const char* rawPrivKey);
const char* Ecdsa_SignP256(const char* pemPrivateKey, const char* data);
const char* Ecdsa_SignP256Base64(const char* pemPrivateKey, const char* data);
bool Ecdsa_VerifyP256(const char* pemPublicKey, const char* data, const char* signature);
bool Ecdsa_VerifyP256Base64(const char* pemPublicKey, const char* data, const char* signatureB64);
const char* Ecdsa_SignP384(const char* pemPrivateKey, const char* data);
const char* Ecdsa_SignP384Base64(const char* pemPrivateKey, const char* data);
bool Ecdsa_VerifyP384(const char* pemPublicKey, const char* data, const char* signature);
bool Ecdsa_VerifyP384Base64(const char* pemPublicKey, const char* data, const char* signatureB64);
bool Ed25519_Keypair(void* pubKey, void* privKey);
const char* Ed25519_KeypairBase64(void);
const char* Ed25519_Sign(const char* privKey, const char* data);
const char* Ed25519_SignBase64(const char* privKey, const char* data);
bool Ed25519_Verify(const char* pubKey, const char* signature, const char* data);
bool Ed25519_VerifyBase64(const char* pubKey, const char* signatureB64, const char* data);
const char* Rsa_SignSha256(const char* pemPrivateKey, const char* data);
const char* Rsa_SignSha384(const char* pemPrivateKey, const char* data);
const char* Rsa_SignSha512(const char* pemPrivateKey, const char* data);
const char* Rsa_SignSha256Base64(const char* pemPrivateKey, const char* data);
const char* Rsa_SignSha384Base64(const char* pemPrivateKey, const char* data);
const char* Rsa_SignSha512Base64(const char* pemPrivateKey, const char* data);
bool Rsa_VerifySha256(const char* pemPublicKey, const char* data, const char* signature);
bool Rsa_VerifySha384(const char* pemPublicKey, const char* data, const char* signature);
bool Rsa_VerifySha512(const char* pemPublicKey, const char* data, const char* signature);
bool Rsa_VerifySha256Base64(const char* pemPublicKey, const char* data, const char* signatureB64);
bool Rsa_VerifySha384Base64(const char* pemPublicKey, const char* data, const char* signatureB64);
bool Rsa_VerifySha512Base64(const char* pemPublicKey, const char* data, const char* signatureB64);
int Main(void);
int Max_int(int a, int b);
typedef struct Drop_VTable {
void (*Drop)(void* self);
} Drop_VTable;
typedef struct Drop_FatPtr {
void* data;
Drop_VTable* vtable;
} Drop_FatPtr;
bool DirExists(const char* path) {
int _t2;
int _t1;
_t1 = bux_dir_exists(path);
_t2 = (_t1 != 0);
return _t2;
}
bool Mkdir(const char* path) {
int _t4;
int _t3;
_t3 = bux_mkdir_if_needed(path);
_t4 = (_t3 != 0);
return _t4;
}
const char** ListDir(const char* dir, const char* ext, int* count) {
const char** _t5;
_t5 = bux_list_dir(dir, ext, count);
return _t5;
}
const char* ReadFile(const char* path) {
const char* _t6;
_t6 = bux_read_file(path);
return _t6;
}
bool WriteFile(const char* path, const char* content) {
int _t8;
int r;
int _t7;
_t7 = bux_write_file(path, content);
r = _t7;
_t8 = (r != 0);
return _t8;
}
bool FileExists(const char* path) {
int _t10;
int r;
int _t9;
_t9 = bux_file_exists(path);
r = _t9;
_t10 = (r != 0);
return _t10;
}
double Sqrt(double x) {
double _t11;
_t11 = bux_sqrt(x);
return _t11;
}
double Pow(double x, double y) {
double _t12;
_t12 = bux_pow(x, y);
return _t12;
}
int64_t Abs(int64_t n) {
int64_t _t13;
_t13 = bux_abs_i64(n);
return _t13;
}
double AbsF(double f) {
double _t14;
_t14 = bux_abs_f64(f);
return _t14;
}
int64_t Min(int64_t a, int64_t b) {
int64_t _t15;
_t15 = bux_min_i64(a, b);
return _t15;
}
double MinF(double a, double b) {
double _t16;
_t16 = bux_min_f64(a, b);
return _t16;
}
double MaxF(double a, double b) {
double _t17;
_t17 = bux_max_f64(a, b);
return _t17;
}
void* Alloc(unsigned int size) {
void* _t18;
_t18 = bux_alloc(size);
return _t18;
}
void* Realloc(void* ptr, unsigned int size) {
void* _t19;
_t19 = bux_realloc(ptr, size);
return _t19;
}
void Free(void* ptr) {
bux_free(ptr);
}
bool MemEq(void* a, void* b, unsigned int size) {
int _t21;
int _t20;
_t20 = bux_mem_eq(a, b, size);
_t21 = (_t20 != 0);
return _t21;
}
const char* Path_Join(const char* a, const char* b) {
const char* _t22;
_t22 = bux_path_join(a, b);
return _t22;
}
const char* Path_Parent(const char* path) {
const char* _t23;
_t23 = bux_path_parent(path);
return _t23;
}
const char* Path_Ext(const char* path) {
const char* _t24;
_t24 = bux_path_ext(path);
return _t24;
}
void Task_Init(int num_workers) {
bux_task_init(num_workers);
}
TaskHandle Task_Spawn(void* fn, void* arg) {
TaskHandle _t26;
void* _t25;
_t25 = bux_task_spawn(fn, arg);
_t26 = (TaskHandle){.handle = _t25};
return _t26;
}
void Task_Wait(TaskHandle t) {
void* _t27;
_t27 = t.handle;
bux_task_join(_t27);
}
void Task_Sleep(int64_t ms) {
bux_task_sleep(ms);
}
void Task_Yield(void) {
bux_task_yield();
}
int Task_CurrentId(void) {
int _t28;
_t28 = bux_task_current_id();
return _t28;
}
void Task_Shutdown(void) {
bux_task_shutdown();
}
int Os_ArgsCount(void) {
int _t29;
_t29 = bux_argc();
return _t29;
}
const char* Os_Args(int index) {
const char* _t30;
_t30 = bux_argv(index);
return _t30;
}
const char* Os_GetEnv(const char* name) {
const char* _t31;
_t31 = bux_getenv(name);
return _t31;
}
bool Os_SetEnv(const char* name, const char* value) {
int _t33;
int _t32;
_t32 = bux_setenv(name, value);
_t33 = (_t32 == 0);
return _t33;
}
const char* Os_GetCwd(void) {
const char* _t34;
_t34 = bux_getcwd();
return _t34;
}
bool Os_Chdir(const char* path) {
int _t36;
int _t35;
_t35 = bux_chdir(path);
_t36 = (_t35 == 0);
return _t36;
}
int64_t Time_NowMs(void) {
int64_t _t37;
_t37 = bux_time_ms();
return _t37;
}
int64_t Time_NowUs(void) {
int64_t _t38;
_t38 = bux_time_us();
return _t38;
}
void Time_SleepMs(int64_t ms) {
bux_sleep_ms(ms);
}
int Process_Run(const char* cmd) {
int _t39;
_t39 = bux_process_run(cmd);
return _t39;
}
const char* Process_Output(const char* cmd) {
const char* _t40;
_t40 = bux_process_output(cmd);
return _t40;
}
int Net_Create(void) {
int _t41;
_t41 = bux_socket_create();
return _t41;
}
bool Net_SetReuse(int fd) {
int _t43;
int _t42;
_t42 = bux_socket_reuse(fd);
_t43 = (_t42 == 0);
return _t43;
}
bool Net_Bind(int fd, const char* addr, int port) {
int _t45;
int _t44;
_t44 = bux_socket_bind(fd, addr, port);
_t45 = (_t44 == 0);
return _t45;
}
bool Net_Listen(int fd, int backlog) {
int _t47;
int _t46;
_t46 = bux_socket_listen(fd, backlog);
_t47 = (_t46 == 0);
return _t47;
}
int Net_Accept(int fd) {
int _t48;
_t48 = bux_socket_accept(fd);
return _t48;
}
bool Net_Connect(int fd, const char* addr, int port) {
int _t50;
int _t49;
_t49 = bux_socket_connect(fd, addr, port);
_t50 = (_t49 == 0);
return _t50;
}
int Net_Send(int fd, const char* data) {
int _t52;
unsigned int _t51;
_t51 = bux_strlen(data);
_t52 = (int)_t51;
int _t53;
_t53 = bux_socket_send(fd, data, _t52);
return _t53;
}
const char* Net_Recv(int fd, int maxLen) {
const char* _t54;
_t54 = bux_socket_recv(fd, maxLen);
return _t54;
}
bool Net_Close(int fd) {
int _t56;
int _t55;
_t55 = bux_socket_close(fd);
_t56 = (_t55 == 0);
return _t56;
}
const char* Net_LastError(void) {
const char* _t57;
_t57 = bux_socket_error();
return _t57;
}
const char* Fmt_Format(const char* tmpl, const char** argStrs, int argCount) {
int _t60;
int _t63;
int _t64;
int _t67;
int64_t _t68;
int _t69;
int _t71;
int _t72;
int _t75;
unsigned int _t76;
void* _t78;
void* _t79;
int _t80;
void* _t81;
StringBuilder sb;
StringBuilder _t58;
_t58 = StringBuilder_New();
sb = _t58;
unsigned int i;
i = 0;
unsigned int tmplLen;
unsigned int _t59;
_t59 = bux_strlen(tmpl);
tmplLen = _t59;
while1:;
_t60 = (i < tmplLen);
if (!_t60) goto wend3;
{
const char* ch;
const char* _t61;
_t61 = String_Chars(tmpl, i);
ch = _t61;
bool _t62;
_t62 = String_Eq(ch, "{");
if (!_t62) goto endif5;
{
unsigned int digitIdx;
_t63 = i + 1;
digitIdx = _t63;
_t64 = (digitIdx < tmplLen);
if (!_t64) goto endif7;
{
const char* digitCh;
const char* _t65;
_t65 = String_Chars(tmpl, digitIdx);
digitCh = _t65;
int64_t d;
int64_t _t66;
_t66 = bux_str_to_int(digitCh);
d = _t66;
bool __and_tmp_0;
_t67 = (d >= 0);
if (!_t67) goto else8;
_t68 = (int64_t)argCount;
_t69 = (d < _t68);
*(bool*)&__and_tmp_0 = _t69;
goto endif9;
else8:;
*(bool*)&__and_tmp_0 = 0;
endif9:;
bool _t70;
_t70 = *(bool*)&__and_tmp_0;
if (!_t70) goto endif11;
{
_t71 = i + 2;
i = _t71;
_t72 = (i < tmplLen);
if (!_t72) goto endif13;
{
const char* closeCh;
const char* _t73;
_t73 = String_Chars(tmpl, i);
closeCh = _t73;
bool _t74;
_t74 = String_Eq(closeCh, "}");
if (!_t74) goto endif15;
{
_t75 = i + 1;
i = _t75;
const char* argStr;
_t76 = (unsigned int)d;
const char* _t77;
_t77 = argStrs[_t76];
argStr = _t77;
_t78 = &sb;
StringBuilder_Append(_t78, argStr);
goto while1;
}
endif15:;
}
endif13:;
}
endif11:;
}
endif7:;
}
endif5:;
_t79 = &sb;
StringBuilder_Append(_t79, ch);
_t80 = i + 1;
i = _t80;
}
goto while1;
wend3:;
_t81 = &sb;
const char* _t82;
_t82 = StringBuilder_Build(_t81);
return _t82;
}
const char* Fmt_Fmt1(const char* tmpl, const char* a1) {
const char** _t85;
const char** args;
/* sizeof(const char*) */
void* _t84;
_t84 = bux_alloc(sizeof(const char*));
_t85 = (const char**)_t84;
args = _t85;
args[0] = a1;
const char* _t86;
_t86 = Fmt_Format(tmpl, args, 1);
return _t86;
}
const char* Fmt_FmtInt(const char* tmpl, int64_t val) {
const char* s;
const char* _t87;
_t87 = String_FromInt(val);
s = _t87;
const char* _t88;
_t88 = Fmt_Fmt1(tmpl, s);
return _t88;
}
const char* Fmt_FmtBool(const char* tmpl, bool val) {
const char* s;
const char* _t89;
_t89 = String_FromBool(val);
s = _t89;
const char* _t90;
_t90 = Fmt_Fmt1(tmpl, s);
return _t90;
}
const char* Fmt_FmtFloat(const char* tmpl, double val) {
const char* s;
const char* _t91;
_t91 = String_FromFloat(val);
s = _t91;
const char* _t92;
_t92 = Fmt_Fmt1(tmpl, s);
return _t92;
}
const char* Fmt_Fmt2(const char* tmpl, const char* a1, const char* a2) {
int _t94;
const char** _t96;
const char** args;
/* sizeof(const char*) */
_t94 = 2 * sizeof(const char*);
void* _t95;
_t95 = bux_alloc(_t94);
_t96 = (const char**)_t95;
args = _t96;
args[0] = a1;
args[1] = a2;
const char* _t97;
_t97 = Fmt_Format(tmpl, args, 2);
return _t97;
}
const char* Fmt_Fmt3(const char* tmpl, const char* a1, const char* a2, const char* a3) {
int _t99;
const char** _t101;
const char** args;
/* sizeof(const char*) */
_t99 = 3 * sizeof(const char*);
void* _t100;
_t100 = bux_alloc(_t99);
_t101 = (const char**)_t100;
args = _t101;
args[0] = a1;
args[1] = a2;
args[2] = a3;
const char* _t102;
_t102 = Fmt_Format(tmpl, args, 3);
return _t102;
}
const char* Crypto_Sha256(const char* data) {
int _t104;
void* _t106;
int len;
unsigned int _t103;
_t103 = String_Len(data);
_t104 = (int)_t103;
len = _t104;
void* hashBuf;
void* _t105;
_t105 = Alloc(32);
hashBuf = _t105;
bux_sha256(data, len, hashBuf);
const char* result;
_t106 = (void*)hashBuf;
const char* _t107;
_t107 = bux_bytes_to_hex(_t106, 32);
result = _t107;
Free(hashBuf);
return result;
}
const char* Crypto_HmacSha256(const char* key, const char* message) {
int _t109;
int _t111;
void* _t113;
int keylen;
unsigned int _t108;
_t108 = String_Len(key);
_t109 = (int)_t108;
keylen = _t109;
int msglen;
unsigned int _t110;
_t110 = String_Len(message);
_t111 = (int)_t110;
msglen = _t111;
void* hmacBuf;
void* _t112;
_t112 = Alloc(32);
hmacBuf = _t112;
bux_hmac_sha256(key, keylen, message, msglen, hmacBuf);
const char* result;
_t113 = (void*)hmacBuf;
const char* _t114;
_t114 = bux_bytes_to_hex(_t113, 32);
result = _t114;
Free(hmacBuf);
return result;
}
const char* Crypto_RandomBytes(int n) {
int _t115;
unsigned int _t116;
int _t119;
const char* _t120;
_t115 = (n <= 0);
if (!_t115) goto endif17;
{
return "";
}
endif17:;
void* buf;
_t116 = (unsigned int)n;
void* _t117;
_t117 = Alloc(_t116);
buf = _t117;
int _t118;
_t118 = bux_random_bytes(buf, n);
_t119 = (_t118 != 1);
if (!_t119) goto endif19;
{
Free(buf);
return "";
}
endif19:;
const char* result;
_t120 = (const char*)buf;
const char* _t121;
_t121 = bux_base64_encode(_t120, n);
result = _t121;
Free(buf);
return result;
}
const char* Crypto_Base64Encode(const char* s) {
int _t123;
unsigned int _t122;
_t122 = String_Len(s);
_t123 = (int)_t122;
const char* _t124;
_t124 = bux_base64_encode(s, _t123);
return _t124;
}
const char* Crypto_HmacSha256Raw(const char* key, const char* message) {
int _t126;
int _t128;
const char* _t130;
int keylen;
unsigned int _t125;
_t125 = String_Len(key);
_t126 = (int)_t125;
keylen = _t126;
int msglen;
unsigned int _t127;
_t127 = String_Len(message);
_t128 = (int)_t127;
msglen = _t128;
void* hmacBuf;
void* _t129;
_t129 = Alloc(32);
hmacBuf = _t129;
bux_hmac_sha256(key, keylen, message, msglen, hmacBuf);
const char* result;
_t130 = (const char*)hmacBuf;
const char* _t131;
_t131 = bux_base64_encode(_t130, 32);
result = _t131;
Free(hmacBuf);
return result;
}
const char* Crypto_Base64Decode(const char* s) {
int _t133;
void* _t134;
int outlen;
outlen = 0;
unsigned int _t132;
_t132 = String_Len(s);
_t133 = (int)_t132;
_t134 = &outlen;
const char* _t135;
_t135 = bux_base64_decode(s, _t133, _t134);
return _t135;
}
Mutex Mutex_New(void) {
Mutex _t137;
void* _t136;
_t136 = bux_mutex_new();
_t137 = (Mutex){.handle = _t136};
return _t137;
}
void Mutex_Lock(Mutex* m) {
void* _t138;
_t138 = m->handle;
bux_mutex_lock(_t138);
}
void Mutex_Unlock(Mutex* m) {
void* _t139;
_t139 = m->handle;
bux_mutex_unlock(_t139);
}
void Mutex_Free(Mutex* m) {
void* _t140;
_t140 = m->handle;
bux_mutex_free(_t140);
}
RwLock RwLock_New(void) {
RwLock _t142;
void* _t141;
_t141 = bux_rwlock_new();
_t142 = (RwLock){.handle = _t141};
return _t142;
}
void RwLock_ReadLock(RwLock* rw) {
void* _t143;
_t143 = rw->handle;
bux_rwlock_rdlock(_t143);
}
void RwLock_WriteLock(RwLock* rw) {
void* _t144;
_t144 = rw->handle;
bux_rwlock_wrlock(_t144);
}
void RwLock_Unlock(RwLock* rw) {
void* _t145;
_t145 = rw->handle;
bux_rwlock_unlock(_t145);
}
void RwLock_Free(RwLock* rw) {
void* _t146;
_t146 = rw->handle;
bux_rwlock_free(_t146);
}
void Test_Exit(int code) {
bux_exit(code);
}
void Test_Assert(bool cond) {
int _t147;
_t147 = (int)cond;
bux_assert(_t147, "", 0, "");
}
void Test_AssertEqInt(int a, int b) {
int _t148;
_t148 = (a != b);
if (!_t148) goto endif21;
{
PrintLine("ASSERT_EQ FAILED:");
PrintInt(a);
PrintLine(" != ");
PrintInt(b);
bux_exit(1);
}
endif21:;
}
void Test_AssertTrue(bool cond) {
int _t149;
_t149 = !cond;
if (!_t149) goto endif23;
{
PrintLine("ASSERT_TRUE FAILED");
bux_exit(1);
}
endif23:;
}
void Test_AssertFalse(bool cond) {
if (!cond) goto endif25;
{
PrintLine("ASSERT_FALSE FAILED");
bux_exit(1);
}
endif25:;
}
void Test_Fail(const char* msg) {
PrintLine("FAIL:");
PrintLine(msg);
bux_exit(1);
}
Result Result_NewOk(int value) {
Result _t150;
Result r;
_t150 = (Result){.tag = Result_Ok};
r = _t150;
r.data.Ok_0 = value;
return r;
}
Result Result_NewErr(const char* msg) {
Result _t151;
Result r;
_t151 = (Result){.tag = Result_Err};
r = _t151;
r.data.Err_0 = msg;
return r;
}
bool Result_IsOk(Result r) {
int _t153;
Result_Tag _t152;
_t152 = r.tag;
_t153 = (_t152 == Result_Ok);
return _t153;
}
bool Result_IsErr(Result r) {
int _t155;
Result_Tag _t154;
_t154 = r.tag;
_t155 = (_t154 == Result_Err);
return _t155;
}
int Result_Unwrap(Result r) {
int _t157;
Result_Tag _t156;
_t156 = r.tag;
_t157 = (_t156 != Result_Ok);
if (!_t157) goto endif27;
{
PrintLine("panic: unwrap on Err");
return 0;
}
endif27:;
Result_Data _t158;
_t158 = r.data;
int _t159;
_t159 = _t158.Ok_0;
return _t159;
}
int Result_UnwrapOr(Result r, int fallback) {
int _t161;
Result_Tag _t160;
_t160 = r.tag;
_t161 = (_t160 == Result_Ok);
if (!_t161) goto endif29;
{
Result_Data _t162;
_t162 = r.data;
int _t163;
_t163 = _t162.Ok_0;
return _t163;
}
endif29:;
return fallback;
}
Option Option_NewSome(int value) {
Option _t164;
Option o;
_t164 = (Option){.tag = Option_Some};
o = _t164;
o.data.Some_0 = value;
return o;
}
Option Option_NewNone(void) {
Option _t165;
_t165 = (Option){.tag = Option_None};
return _t165;
}
bool Option_IsSome(Option o) {
int _t167;
Option_Tag _t166;
_t166 = o.tag;
_t167 = (_t166 == Option_Some);
return _t167;
}
bool Option_IsNone(Option o) {
int _t169;
Option_Tag _t168;
_t168 = o.tag;
_t169 = (_t168 == Option_None);
return _t169;
}
int Option_Unwrap(Option o) {
int _t171;
Option_Tag _t170;
_t170 = o.tag;
_t171 = (_t170 != Option_Some);
if (!_t171) goto endif31;
{
PrintLine("panic: unwrap on None");
return 0;
}
endif31:;
Option_Data _t172;
_t172 = o.data;
int _t173;
_t173 = _t172.Some_0;
return _t173;
}
int Option_UnwrapOr(Option o, int fallback) {
int _t175;
Option_Tag _t174;
_t174 = o.tag;
_t175 = (_t174 == Option_Some);
if (!_t175) goto endif33;
{
Option_Data _t176;
_t176 = o.data;
int _t177;
_t177 = _t176.Some_0;
return _t177;
}
endif33:;
return fallback;
}
JsonValue Json_Null(void) {
JsonValue _t178;
_t178 = (JsonValue){.tag = JsonTagNull, .boolVal = 0, .numVal = 0.0, .strVal = "", .arrData = 0, .arrLen = 0, .arrCap = 0, .objKeys = 0, .objValues = 0, .objLen = 0, .objCap = 0};
return _t178;
}
JsonValue Json_Bool(bool b) {
JsonValue _t179;
_t179 = (JsonValue){.tag = JsonTagBool, .boolVal = b, .numVal = 0.0, .strVal = "", .arrData = 0, .arrLen = 0, .arrCap = 0, .objKeys = 0, .objValues = 0, .objLen = 0, .objCap = 0};
return _t179;
}
JsonValue Json_Number(double n) {
JsonValue _t180;
_t180 = (JsonValue){.tag = JsonTagNumber, .boolVal = 0, .numVal = n, .strVal = "", .arrData = 0, .arrLen = 0, .arrCap = 0, .objKeys = 0, .objValues = 0, .objLen = 0, .objCap = 0};
return _t180;
}
JsonValue Json_String(const char* s) {
JsonValue _t181;
_t181 = (JsonValue){.tag = JsonTagString, .boolVal = 0, .numVal = 0.0, .strVal = s, .arrData = 0, .arrLen = 0, .arrCap = 0, .objKeys = 0, .objValues = 0, .objLen = 0, .objCap = 0};
return _t181;
}
JsonValue Json_Array(void) {
JsonValue _t182;
_t182 = (JsonValue){.tag = JsonTagArray, .boolVal = 0, .numVal = 0.0, .strVal = "", .arrData = 0, .arrLen = 0, .arrCap = 0, .objKeys = 0, .objValues = 0, .objLen = 0, .objCap = 0};
return _t182;
}
JsonValue Json_Object(void) {
JsonValue _t183;
_t183 = (JsonValue){.tag = JsonTagObject, .boolVal = 0, .numVal = 0.0, .strVal = "", .arrData = 0, .arrLen = 0, .arrCap = 0, .objKeys = 0, .objValues = 0, .objLen = 0, .objCap = 0};
return _t183;
}
unsigned int Json_ArrayLen(JsonValue v) {
int _t185;
int _t184;
_t184 = v.tag;
_t185 = (_t184 != JsonTagArray);
if (!_t185) goto endif35;
{
return 0;
}
endif35:;
unsigned int _t186;
_t186 = v.arrLen;
return _t186;
}
JsonValue Json_ArrayGet(JsonValue v, unsigned int index) {
int _t188;
int _t191;
int _t187;
_t187 = v.tag;
_t188 = (_t187 != JsonTagArray);
if (!_t188) goto endif37;
{
JsonValue _t189;
_t189 = Json_Null();
return _t189;
}
endif37:;
unsigned int _t190;
_t190 = v.arrLen;
_t191 = (index >= _t190);
if (!_t191) goto endif39;
{
JsonValue _t192;
_t192 = Json_Null();
return _t192;
}
endif39:;
JsonValue* _t193;
_t193 = v.arrData;
JsonValue _t194;
_t194 = _t193[index];
return _t194;
}
void Json_ArrayPush(JsonValue* self, JsonValue val) {
int _t196;
int _t199;
int _t201;
int _t203;
JsonValue* _t205;
int _t206;
void* _t208;
int _t210;
JsonValue* _t212;
int _t216;
int _t195;
_t195 = self->tag;
_t196 = (_t195 != JsonTagArray);
if (!_t196) goto endif41;
{
return;
}
endif41:;
unsigned int _t197;
_t197 = self->arrLen;
unsigned int _t198;
_t198 = self->arrCap;
_t199 = (_t197 >= _t198);
if (!_t199) goto endif43;
{
unsigned int arrNewCap;
unsigned int _t200;
_t200 = self->arrCap;
arrNewCap = _t200;
_t201 = (arrNewCap == 0);
if (!_t201) goto else44;
{
self->arrCap = 4;
/* sizeof(JsonValue) */
_t203 = 4 * sizeof(JsonValue);
void* _t204;
_t204 = Alloc(_t203);
_t205 = (JsonValue*)_t204;
self->arrData = _t205;
}
goto endif45;
else44:;
{
unsigned int doubleCap;
_t206 = arrNewCap * 2;
doubleCap = _t206;
self->arrCap = doubleCap;
JsonValue* _t207;
_t207 = self->arrData;
_t208 = (void*)_t207;
/* sizeof(JsonValue) */
_t210 = doubleCap * sizeof(JsonValue);
void* _t211;
_t211 = Realloc(_t208, _t210);
_t212 = (JsonValue*)_t211;
self->arrData = _t212;
}
endif45:;
}
endif43:;
JsonValue* _t213;
_t213 = self->arrData;
unsigned int _t214;
_t214 = self->arrLen;
_t213[_t214] = val;
unsigned int _t215;
_t215 = self->arrLen;
_t216 = _t215 + 1;
self->arrLen = _t216;
}
unsigned int Json_ObjectLen(JsonValue v) {
int _t218;
int _t217;
_t217 = v.tag;
_t218 = (_t217 != JsonTagObject);
if (!_t218) goto endif47;
{
return 0;
}
endif47:;
unsigned int _t219;
_t219 = v.objLen;
return _t219;
}
JsonValue Json_ObjectGet(JsonValue v, const char* key) {
int _t221;
int _t224;
int _t230;
int _t220;
_t220 = v.tag;
_t221 = (_t220 != JsonTagObject);
if (!_t221) goto endif49;
{
JsonValue _t222;
_t222 = Json_Null();
return _t222;
}
endif49:;
unsigned int i;
i = 0;
while50:;
unsigned int _t223;
_t223 = v.objLen;
_t224 = (i < _t223);
if (!_t224) goto wend52;
{
const char** _t225;
_t225 = v.objKeys;
const char* _t226;
_t226 = _t225[i];
bool _t227;
_t227 = String_Eq(_t226, key);
if (!_t227) goto endif54;
{
JsonValue* _t228;
_t228 = v.objValues;
JsonValue _t229;
_t229 = _t228[i];
return _t229;
}
endif54:;
_t230 = i + 1;
i = _t230;
}
goto while50;
wend52:;
JsonValue _t231;
_t231 = Json_Null();
return _t231;
}
bool Json_ObjectHas(JsonValue v, const char* key) {
int _t233;
int _t235;
int _t239;
int _t232;
_t232 = v.tag;
_t233 = (_t232 != JsonTagObject);
if (!_t233) goto endif56;
{
return 0;
}
endif56:;
unsigned int i;
i = 0;
while57:;
unsigned int _t234;
_t234 = v.objLen;
_t235 = (i < _t234);
if (!_t235) goto wend59;
{
const char** _t236;
_t236 = v.objKeys;
const char* _t237;
_t237 = _t236[i];
bool _t238;
_t238 = String_Eq(_t237, key);
if (!_t238) goto endif61;
{
return 1;
}
endif61:;
_t239 = i + 1;
i = _t239;
}
goto while57;
wend59:;
return 0;
}
void Json_ObjectSet(JsonValue* self, const char* key, JsonValue val) {
int _t241;
int _t243;
int _t248;
int _t251;
int _t253;
int _t255;
const char** _t257;
int _t259;
JsonValue* _t261;
int _t262;
void* _t264;
int _t266;
const char** _t268;
void* _t270;
int _t272;
JsonValue* _t274;
int _t280;
int _t240;
_t240 = self->tag;
_t241 = (_t240 != JsonTagObject);
if (!_t241) goto endif63;
{
return;
}
endif63:;
unsigned int i;
i = 0;
while64:;
unsigned int _t242;
_t242 = self->objLen;
_t243 = (i < _t242);
if (!_t243) goto wend66;
{
const char** _t244;
_t244 = self->objKeys;
const char* _t245;
_t245 = _t244[i];
bool _t246;
_t246 = String_Eq(_t245, key);
if (!_t246) goto endif68;
{
JsonValue* _t247;
_t247 = self->objValues;
_t247[i] = val;
return;
}
endif68:;
_t248 = i + 1;
i = _t248;
}
goto while64;
wend66:;
unsigned int _t249;
_t249 = self->objLen;
unsigned int _t250;
_t250 = self->objCap;
_t251 = (_t249 >= _t250);
if (!_t251) goto endif70;
{
unsigned int objNewCap;
unsigned int _t252;
_t252 = self->objCap;
objNewCap = _t252;
_t253 = (objNewCap == 0);
if (!_t253) goto else71;
{
self->objCap = 4;
/* sizeof(const char*) */
_t255 = 4 * sizeof(const char*);
void* _t256;
_t256 = Alloc(_t255);
_t257 = (const char**)_t256;
self->objKeys = _t257;
/* sizeof(JsonValue) */
_t259 = 4 * sizeof(JsonValue);
void* _t260;
_t260 = Alloc(_t259);
_t261 = (JsonValue*)_t260;
self->objValues = _t261;
}
goto endif72;
else71:;
{
unsigned int doubleCap;
_t262 = objNewCap * 2;
doubleCap = _t262;
self->objCap = doubleCap;
const char** _t263;
_t263 = self->objKeys;
_t264 = (void*)_t263;
/* sizeof(const char*) */
_t266 = doubleCap * sizeof(const char*);
void* _t267;
_t267 = Realloc(_t264, _t266);
_t268 = (const char**)_t267;
self->objKeys = _t268;
JsonValue* _t269;
_t269 = self->objValues;
_t270 = (void*)_t269;
/* sizeof(JsonValue) */
_t272 = doubleCap * sizeof(JsonValue);
void* _t273;
_t273 = Realloc(_t270, _t272);
_t274 = (JsonValue*)_t273;
self->objValues = _t274;
}
endif72:;
}
endif70:;
const char** _t275;
_t275 = self->objKeys;
unsigned int _t276;
_t276 = self->objLen;
_t275[_t276] = key;
JsonValue* _t277;
_t277 = self->objValues;
unsigned int _t278;
_t278 = self->objLen;
_t277[_t278] = val;
unsigned int _t279;
_t279 = self->objLen;
_t280 = _t279 + 1;
self->objLen = _t280;
}
bool Json_IsNull(JsonValue v) {
int _t282;
int _t281;
_t281 = v.tag;
_t282 = (_t281 == JsonTagNull);
return _t282;
}
bool Json_AsBool(JsonValue v) {
int _t284;
int _t283;
_t283 = v.tag;
_t284 = (_t283 == JsonTagBool);
if (!_t284) goto endif74;
{
bool _t285;
_t285 = v.boolVal;
return _t285;
}
endif74:;
return 0;
}
double Json_AsNumber(JsonValue v) {
int _t287;
int _t286;
_t286 = v.tag;
_t287 = (_t286 == JsonTagNumber);
if (!_t287) goto endif76;
{
double _t288;
_t288 = v.numVal;
return _t288;
}
endif76:;
return 0.0;
}
const char* Json_AsString(JsonValue v) {
int _t290;
int _t289;
_t289 = v.tag;
_t290 = (_t289 == JsonTagString);
if (!_t290) goto endif78;
{
const char* _t291;
_t291 = v.strVal;
return _t291;
}
endif78:;
return "";
}
int JsonParser_Peek(JsonParser* p) {
int _t294;
int _t298;
unsigned int _t292;
_t292 = p->pos;
unsigned int _t293;
_t293 = p->len;
_t294 = (_t292 >= _t293);
if (!_t294) goto endif80;
{
return 0;
}
endif80:;
const char* _t295;
_t295 = p->src;
unsigned int _t296;
_t296 = p->pos;
int _t297;
_t297 = _t295[_t296];
_t298 = (int)_t297;
return _t298;
}
void JsonParser_Advance(JsonParser* p) {
int _t301;
int _t303;
unsigned int _t299;
_t299 = p->pos;
unsigned int _t300;
_t300 = p->len;
_t301 = (_t299 < _t300);
if (!_t301) goto endif82;
{
unsigned int _t302;
_t302 = p->pos;
_t303 = _t302 + 1;
p->pos = _t303;
}
endif82:;
}
void JsonParser_SkipWhitespace(JsonParser* p) {
int _t305;
int _t306;
int _t308;
int _t310;
while83:;
if (!1) goto wend85;
{
int c;
int _t304;
_t304 = JsonParser_Peek(p);
c = _t304;
bool __or_tmp_1;
bool __or_tmp_2;
bool __or_tmp_3;
_t305 = (c == 32);
if (!_t305) goto else86;
*(bool*)&__or_tmp_3 = 1;
goto endif87;
else86:;
_t306 = (c == 9);
*(bool*)&__or_tmp_3 = _t306;
endif87:;
bool _t307;
_t307 = *(bool*)&__or_tmp_3;
if (!_t307) goto else88;
*(bool*)&__or_tmp_2 = 1;
goto endif89;
else88:;
_t308 = (c == 10);
*(bool*)&__or_tmp_2 = _t308;
endif89:;
bool _t309;
_t309 = *(bool*)&__or_tmp_2;
if (!_t309) goto else90;
*(bool*)&__or_tmp_1 = 1;
goto endif91;
else90:;
_t310 = (c == 13);
*(bool*)&__or_tmp_1 = _t310;
endif91:;
bool _t311;
_t311 = *(bool*)&__or_tmp_1;
if (!_t311) goto else92;
{
JsonParser_Advance(p);
}
goto endif93;
else92:;
{
return;
}
endif93:;
}
goto while83;
wend85:;
}
bool JsonParser_Match(JsonParser* p, const char* expected) {
int _t314;
int _t316;
int _t317;
int _t320;
int _t323;
int _t324;
int _t326;
unsigned int elen;
unsigned int _t312;
_t312 = String_Len(expected);
elen = _t312;
unsigned int _t313;
_t313 = p->pos;
_t314 = _t313 + elen;
unsigned int _t315;
_t315 = p->len;
_t316 = (_t314 > _t315);
if (!_t316) goto endif95;
{
return 0;
}
endif95:;
unsigned int i;
i = 0;
while96:;
_t317 = (i < elen);
if (!_t317) goto wend98;
{
const char* _t318;
_t318 = p->src;
unsigned int _t319;
_t319 = p->pos;
_t320 = _t319 + i;
int _t321;
_t321 = _t318[_t320];
int _t322;
_t322 = expected[i];
_t323 = (_t321 != _t322);
if (!_t323) goto endif100;
{
return 0;
}
endif100:;
_t324 = i + 1;
i = _t324;
}
goto while96;
wend98:;
unsigned int _t325;
_t325 = p->pos;
_t326 = _t325 + elen;
p->pos = _t326;
return 1;
}
const char* JsonParser_ParseString(JsonParser* p) {
int _t328;
int _t331;
int _t332;
int _t334;
int _t336;
void* _t337;
int _t338;
void* _t339;
char _t340;
int _t341;
void* _t342;
char _t343;
int _t344;
void* _t345;
char _t346;
int _t347;
void* _t348;
char _t349;
int _t350;
void* _t351;
char _t352;
int _t353;
void* _t354;
char _t355;
int _t356;
void* _t357;
char _t358;
void* _t359;
char _t360;
void* _t361;
char _t362;
void* _t363;
char _t364;
int _t366;
void* _t367;
void* _t368;
void* _t370;
int _t327;
_t327 = JsonParser_Peek(p);
_t328 = (_t327 != 34);
if (!_t328) goto endif102;
{
p->error = "Expected string";
return "";
}
endif102:;
JsonParser_Advance(p);
StringBuilder sb;
StringBuilder _t329;
_t329 = StringBuilder_New();
sb = _t329;
while103:;
if (!1) goto wend105;
{
int c;
int _t330;
_t330 = JsonParser_Peek(p);
c = _t330;
bool __or_tmp_4;
_t331 = (c == 0);
if (!_t331) goto else106;
*(bool*)&__or_tmp_4 = 1;
goto endif107;
else106:;
_t332 = (c == 34);
*(bool*)&__or_tmp_4 = _t332;
endif107:;
bool _t333;
_t333 = *(bool*)&__or_tmp_4;
if (!_t333) goto endif109;
{
goto wend105;
}
endif109:;
_t334 = (c == 92);
if (!_t334) goto else110;
{
JsonParser_Advance(p);
int esc;
int _t335;
_t335 = JsonParser_Peek(p);
esc = _t335;
_t336 = (esc == 0);
if (!_t336) goto endif113;
{
p->error = "Unterminated string escape";
_t337 = &sb;
StringBuilder_Free(_t337);
return "";
}
endif113:;
_t338 = (esc == 110);
if (!_t338) goto else114;
{
_t339 = &sb;
_t340 = (char)10;
StringBuilder_AppendChar(_t339, _t340);
}
goto endif115;
else114:;
_t341 = (esc == 116);
if (!_t341) goto else116;
{
_t342 = &sb;
_t343 = (char)9;
StringBuilder_AppendChar(_t342, _t343);
}
goto endif117;
else116:;
_t344 = (esc == 114);
if (!_t344) goto else118;
{
_t345 = &sb;
_t346 = (char)13;
StringBuilder_AppendChar(_t345, _t346);
}
goto endif119;
else118:;
_t347 = (esc == 98);
if (!_t347) goto else120;
{
_t348 = &sb;
_t349 = (char)8;
StringBuilder_AppendChar(_t348, _t349);
}
goto endif121;
else120:;
_t350 = (esc == 102);
if (!_t350) goto else122;
{
_t351 = &sb;
_t352 = (char)12;
StringBuilder_AppendChar(_t351, _t352);
}
goto endif123;
else122:;
_t353 = (esc == 34);
if (!_t353) goto else124;
{
_t354 = &sb;
_t355 = (char)34;
StringBuilder_AppendChar(_t354, _t355);
}
goto endif125;
else124:;
_t356 = (esc == 92);
if (!_t356) goto else126;
{
_t357 = &sb;
_t358 = (char)92;
StringBuilder_AppendChar(_t357, _t358);
}
goto endif127;
else126:;
{
_t359 = &sb;
_t360 = (char)92;
StringBuilder_AppendChar(_t359, _t360);
_t361 = &sb;
_t362 = (char)esc;
StringBuilder_AppendChar(_t361, _t362);
}
endif127:;
endif125:;
endif123:;
endif121:;
endif119:;
endif117:;
endif115:;
JsonParser_Advance(p);
}
goto endif111;
else110:;
{
_t363 = &sb;
_t364 = (char)c;
StringBuilder_AppendChar(_t363, _t364);
JsonParser_Advance(p);
}
endif111:;
}
goto while103;
wend105:;
int _t365;
_t365 = JsonParser_Peek(p);
_t366 = (_t365 != 34);
if (!_t366) goto endif129;
{
p->error = "Unterminated string";
_t367 = &sb;
StringBuilder_Free(_t367);
return "";
}
endif129:;
JsonParser_Advance(p);
const char* result;
_t368 = &sb;
const char* _t369;
_t369 = StringBuilder_Build(_t368);
result = _t369;
_t370 = &sb;
StringBuilder_Free(_t370);
return result;
}
JsonValue JsonParser_ParseNumber(JsonParser* p) {
int _t373;
int _t375;
int _t376;
int _t379;
int _t381;
int _t382;
int _t386;
unsigned int start;
unsigned int _t371;
_t371 = p->pos;
start = _t371;
int c0;
int _t372;
_t372 = JsonParser_Peek(p);
c0 = _t372;
_t373 = (c0 == 45);
if (!_t373) goto endif131;
{
JsonParser_Advance(p);
}
endif131:;
while132:;
if (!1) goto wend134;
{
int c;
int _t374;
_t374 = JsonParser_Peek(p);
c = _t374;
bool __and_tmp_5;
_t375 = (c >= 48);
if (!_t375) goto else135;
_t376 = (c <= 57);
*(bool*)&__and_tmp_5 = _t376;
goto endif136;
else135:;
*(bool*)&__and_tmp_5 = 0;
endif136:;
bool _t377;
_t377 = *(bool*)&__and_tmp_5;
if (!_t377) goto else137;
{
JsonParser_Advance(p);
}
goto endif138;
else137:;
{
goto wend134;
}
endif138:;
}
goto while132;
wend134:;
int _t378;
_t378 = JsonParser_Peek(p);
_t379 = (_t378 == 46);
if (!_t379) goto endif140;
{
JsonParser_Advance(p);
while141:;
if (!1) goto wend143;
{
int c;
int _t380;
_t380 = JsonParser_Peek(p);
c = _t380;
bool __and_tmp_6;
_t381 = (c >= 48);
if (!_t381) goto else144;
_t382 = (c <= 57);
*(bool*)&__and_tmp_6 = _t382;
goto endif145;
else144:;
*(bool*)&__and_tmp_6 = 0;
endif145:;
bool _t383;
_t383 = *(bool*)&__and_tmp_6;
if (!_t383) goto else146;
{
JsonParser_Advance(p);
}
goto endif147;
else146:;
{
goto wend143;
}
endif147:;
}
goto while141;
wend143:;
}
endif140:;
const char* numStr;
const char* _t384;
_t384 = p->src;
unsigned int _t385;
_t385 = p->pos;
_t386 = _t385 - start;
const char* _t387;
_t387 = String_Slice(_t384, start, _t386);
numStr = _t387;
double n;
double _t388;
_t388 = String_ToFloat(numStr);
n = _t388;
JsonValue _t389;
_t389 = Json_Number(n);
return _t389;
}
JsonValue JsonParser_ParseArray(JsonParser* p) {
int _t392;
int _t395;
void* _t397;
int _t399;
int _t400;
JsonParser_Advance(p);
JsonValue arr;
JsonValue _t390;
_t390 = Json_Array();
arr = _t390;
JsonParser_SkipWhitespace(p);
int _t391;
_t391 = JsonParser_Peek(p);
_t392 = (_t391 == 93);
if (!_t392) goto endif149;
{
JsonParser_Advance(p);
return arr;
}
endif149:;
while150:;
if (!1) goto wend152;
{
JsonParser_SkipWhitespace(p);
JsonValue val;
JsonValue _t393;
_t393 = JsonParser_ParseValue(p);
val = _t393;
const char* _t394;
_t394 = p->error;
_t395 = (_t394 != "");
if (!_t395) goto endif154;
{
JsonValue _t396;
_t396 = Json_Null();
return _t396;
}
endif154:;
_t397 = &arr;
Json_ArrayPush(_t397, val);
JsonParser_SkipWhitespace(p);
int c;
int _t398;
_t398 = JsonParser_Peek(p);
c = _t398;
_t399 = (c == 93);
if (!_t399) goto endif156;
{
JsonParser_Advance(p);
return arr;
}
endif156:;
_t400 = (c == 44);
if (!_t400) goto else157;
{
JsonParser_Advance(p);
}
goto endif158;
else157:;
{
p->error = "Expected ',' or ']' in array";
JsonValue _t401;
_t401 = Json_Null();
return _t401;
}
endif158:;
}
goto while150;
wend152:;
}
JsonValue JsonParser_ParseObject(JsonParser* p) {
int _t404;
int _t407;
int _t410;
int _t414;
void* _t416;
int _t418;
int _t419;
JsonParser_Advance(p);
JsonValue obj;
JsonValue _t402;
_t402 = Json_Object();
obj = _t402;
JsonParser_SkipWhitespace(p);
int _t403;
_t403 = JsonParser_Peek(p);
_t404 = (_t403 == 125);
if (!_t404) goto endif160;
{
JsonParser_Advance(p);
return obj;
}
endif160:;
while161:;
if (!1) goto wend163;
{
JsonParser_SkipWhitespace(p);
const char* key;
const char* _t405;
_t405 = JsonParser_ParseString(p);
key = _t405;
const char* _t406;
_t406 = p->error;
_t407 = (_t406 != "");
if (!_t407) goto endif165;
{
JsonValue _t408;
_t408 = Json_Null();
return _t408;
}
endif165:;
JsonParser_SkipWhitespace(p);
int _t409;
_t409 = JsonParser_Peek(p);
_t410 = (_t409 != 58);
if (!_t410) goto endif167;
{
p->error = "Expected ':' after object key";
JsonValue _t411;
_t411 = Json_Null();
return _t411;
}
endif167:;
JsonParser_Advance(p);
JsonParser_SkipWhitespace(p);
JsonValue val;
JsonValue _t412;
_t412 = JsonParser_ParseValue(p);
val = _t412;
const char* _t413;
_t413 = p->error;
_t414 = (_t413 != "");
if (!_t414) goto endif169;
{
JsonValue _t415;
_t415 = Json_Null();
return _t415;
}
endif169:;
_t416 = &obj;
Json_ObjectSet(_t416, key, val);
JsonParser_SkipWhitespace(p);
int c;
int _t417;
_t417 = JsonParser_Peek(p);
c = _t417;
_t418 = (c == 125);
if (!_t418) goto endif171;
{
JsonParser_Advance(p);
return obj;
}
endif171:;
_t419 = (c == 44);
if (!_t419) goto else172;
{
JsonParser_Advance(p);
}
goto endif173;
else172:;
{
p->error = "Expected ',' or '}' in object";
JsonValue _t420;
_t420 = Json_Null();
return _t420;
}
endif173:;
}
goto while161;
wend163:;
}
JsonValue JsonParser_ParseValue(JsonParser* p) {
int _t422;
int _t424;
int _t427;
int _t429;
int _t431;
int _t435;
int _t439;
int _t443;
int _t444;
int _t446;
JsonParser_SkipWhitespace(p);
int c;
int _t421;
_t421 = JsonParser_Peek(p);
c = _t421;
_t422 = (c == 0);
if (!_t422) goto endif175;
{
p->error = "Unexpected end of input";
JsonValue _t423;
_t423 = Json_Null();
return _t423;
}
endif175:;
_t424 = (c == 34);
if (!_t424) goto endif177;
{
const char* _t425;
_t425 = JsonParser_ParseString(p);
JsonValue _t426;
_t426 = Json_String(_t425);
return _t426;
}
endif177:;
_t427 = (c == 123);
if (!_t427) goto endif179;
{
JsonValue _t428;
_t428 = JsonParser_ParseObject(p);
return _t428;
}
endif179:;
_t429 = (c == 91);
if (!_t429) goto endif181;
{
JsonValue _t430;
_t430 = JsonParser_ParseArray(p);
return _t430;
}
endif181:;
_t431 = (c == 116);
if (!_t431) goto endif183;
{
bool _t432;
_t432 = JsonParser_Match(p, "true");
if (!_t432) goto endif185;
{
JsonValue _t433;
_t433 = Json_Bool(1);
return _t433;
}
endif185:;
p->error = "Expected 'true'";
JsonValue _t434;
_t434 = Json_Null();
return _t434;
}
endif183:;
_t435 = (c == 102);
if (!_t435) goto endif187;
{
bool _t436;
_t436 = JsonParser_Match(p, "false");
if (!_t436) goto endif189;
{
JsonValue _t437;
_t437 = Json_Bool(0);
return _t437;
}
endif189:;
p->error = "Expected 'false'";
JsonValue _t438;
_t438 = Json_Null();
return _t438;
}
endif187:;
_t439 = (c == 110);
if (!_t439) goto endif191;
{
bool _t440;
_t440 = JsonParser_Match(p, "null");
if (!_t440) goto endif193;
{
JsonValue _t441;
_t441 = Json_Null();
return _t441;
}
endif193:;
p->error = "Expected 'null'";
JsonValue _t442;
_t442 = Json_Null();
return _t442;
}
endif191:;
bool __or_tmp_7;
bool __and_tmp_8;
_t443 = (c >= 48);
if (!_t443) goto else194;
_t444 = (c <= 57);
*(bool*)&__and_tmp_8 = _t444;
goto endif195;
else194:;
*(bool*)&__and_tmp_8 = 0;
endif195:;
bool _t445;
_t445 = *(bool*)&__and_tmp_8;
if (!_t445) goto else196;
*(bool*)&__or_tmp_7 = 1;
goto endif197;
else196:;
_t446 = (c == 45);
*(bool*)&__or_tmp_7 = _t446;
endif197:;
bool _t447;
_t447 = *(bool*)&__or_tmp_7;
if (!_t447) goto endif199;
{
JsonValue _t448;
_t448 = JsonParser_ParseNumber(p);
return _t448;
}
endif199:;
p->error = "Unexpected character";
JsonValue _t449;
_t449 = Json_Null();
return _t449;
}
JsonValue Json_Parse(const char* s) {
JsonParser _t451;
void* _t452;
void* _t454;
int _t456;
int _t459;
JsonParser p;
unsigned int _t450;
_t450 = String_Len(s);
_t451 = (JsonParser){.src = s, .pos = 0, .len = _t450, .error = ""};
p = _t451;
JsonValue result;
_t452 = &p;
JsonValue _t453;
_t453 = JsonParser_ParseValue(_t452);
result = _t453;
_t454 = &p;
JsonParser_SkipWhitespace(_t454);
bool __and_tmp_9;
const char* _t455;
_t455 = p.error;
_t456 = (_t455 == "");
if (!_t456) goto else200;
unsigned int _t457;
_t457 = p.pos;
unsigned int _t458;
_t458 = p.len;
_t459 = (_t457 != _t458);
*(bool*)&__and_tmp_9 = _t459;
goto endif201;
else200:;
*(bool*)&__and_tmp_9 = 0;
endif201:;
bool _t460;
_t460 = *(bool*)&__and_tmp_9;
if (!_t460) goto endif203;
{
p.error = "Trailing data after JSON value";
JsonValue _t461;
_t461 = Json_Null();
return _t461;
}
endif203:;
return result;
}
void Json_StringifyImpl(StringBuilder* sb, JsonValue v) {
int _t463;
int _t465;
int _t468;
int _t471;
char _t472;
char _t474;
int _t476;
char _t477;
int _t479;
int _t480;
char _t481;
int _t484;
char _t485;
int _t487;
char _t488;
int _t490;
int _t491;
char _t492;
char _t493;
char _t496;
char _t497;
int _t500;
char _t501;
int _t462;
_t462 = v.tag;
_t463 = (_t462 == JsonTagNull);
if (!_t463) goto endif205;
{
StringBuilder_Append(sb, "null");
return;
}
endif205:;
int _t464;
_t464 = v.tag;
_t465 = (_t464 == JsonTagBool);
if (!_t465) goto endif207;
{
bool _t466;
_t466 = v.boolVal;
if (!_t466) goto else208;
{
StringBuilder_Append(sb, "true");
}
goto endif209;
else208:;
{
StringBuilder_Append(sb, "false");
}
endif209:;
return;
}
endif207:;
int _t467;
_t467 = v.tag;
_t468 = (_t467 == JsonTagNumber);
if (!_t468) goto endif211;
{
double _t469;
_t469 = v.numVal;
StringBuilder_AppendFloat(sb, _t469);
return;
}
endif211:;
int _t470;
_t470 = v.tag;
_t471 = (_t470 == JsonTagString);
if (!_t471) goto endif213;
{
_t472 = (char)34;
StringBuilder_AppendChar(sb, _t472);
const char* _t473;
_t473 = v.strVal;
StringBuilder_Append(sb, _t473);
_t474 = (char)34;
StringBuilder_AppendChar(sb, _t474);
return;
}
endif213:;
int _t475;
_t475 = v.tag;
_t476 = (_t475 == JsonTagArray);
if (!_t476) goto endif215;
{
_t477 = (char)91;
StringBuilder_AppendChar(sb, _t477);
unsigned int i;
i = 0;
while216:;
unsigned int _t478;
_t478 = v.arrLen;
_t479 = (i < _t478);
if (!_t479) goto wend218;
{
_t480 = (i > 0);
if (!_t480) goto endif220;
{
_t481 = (char)44;
StringBuilder_AppendChar(sb, _t481);
}
endif220:;
JsonValue* _t482;
_t482 = v.arrData;
JsonValue _t483;
_t483 = _t482[i];
Json_StringifyImpl(sb, _t483);
_t484 = i + 1;
i = _t484;
}
goto while216;
wend218:;
_t485 = (char)93;
StringBuilder_AppendChar(sb, _t485);
return;
}
endif215:;
int _t486;
_t486 = v.tag;
_t487 = (_t486 == JsonTagObject);
if (!_t487) goto endif222;
{
_t488 = (char)123;
StringBuilder_AppendChar(sb, _t488);
unsigned int i;
i = 0;
while223:;
unsigned int _t489;
_t489 = v.objLen;
_t490 = (i < _t489);
if (!_t490) goto wend225;
{
_t491 = (i > 0);
if (!_t491) goto endif227;
{
_t492 = (char)44;
StringBuilder_AppendChar(sb, _t492);
}
endif227:;
_t493 = (char)34;
StringBuilder_AppendChar(sb, _t493);
const char** _t494;
_t494 = v.objKeys;
const char* _t495;
_t495 = _t494[i];
StringBuilder_Append(sb, _t495);
_t496 = (char)34;
StringBuilder_AppendChar(sb, _t496);
_t497 = (char)58;
StringBuilder_AppendChar(sb, _t497);
JsonValue* _t498;
_t498 = v.objValues;
JsonValue _t499;
_t499 = _t498[i];
Json_StringifyImpl(sb, _t499);
_t500 = i + 1;
i = _t500;
}
goto while223;
wend225:;
_t501 = (char)125;
StringBuilder_AppendChar(sb, _t501);
return;
}
endif222:;
}
const char* Json_Stringify(JsonValue v) {
void* _t503;
void* _t504;
StringBuilder sb;
StringBuilder _t502;
_t502 = StringBuilder_New();
sb = _t502;
_t503 = &sb;
Json_StringifyImpl(_t503, v);
_t504 = &sb;
const char* _t505;
_t505 = StringBuilder_Build(_t504);
return _t505;
}
unsigned int String_Len(const char* s) {
unsigned int _t506;
_t506 = bux_strlen(s);
return _t506;
}
bool String_IsNull(const char* s) {
int _t508;
int _t507;
_t507 = bux_str_is_null(s);
_t508 = (_t507 != 0);
return _t508;
}
bool String_Eq(const char* a, const char* b) {
int _t510;
int _t509;
_t509 = bux_strcmp(a, b);
_t510 = (_t509 == 0);
return _t510;
}
const char* String_Concat(const char* a, const char* b) {
int _t513;
int _t514;
char* _t516;
unsigned int len_a;
unsigned int _t511;
_t511 = bux_strlen(a);
len_a = _t511;
unsigned int len_b;
unsigned int _t512;
_t512 = bux_strlen(b);
len_b = _t512;
unsigned int total;
_t513 = len_a + len_b;
_t514 = _t513 + 1;
total = _t514;
char* buf;
void* _t515;
_t515 = bux_alloc(total);
_t516 = (char*)_t515;
buf = _t516;
bux_strcpy(buf, a);
bux_strcat(buf, b);
return buf;
}
const char* String_Copy(const char* s) {
int _t518;
char* _t520;
unsigned int len;
unsigned int _t517;
_t517 = bux_strlen(s);
len = _t517;
char* buf;
_t518 = len + 1;
void* _t519;
_t519 = bux_alloc(_t518);
_t520 = (char*)_t519;
buf = _t520;
bux_strcpy(buf, s);
return buf;
}
bool String_StartsWith(const char* s, const char* prefix) {
int _t523;
int _t525;
unsigned int s_len;
unsigned int _t521;
_t521 = bux_strlen(s);
s_len = _t521;
unsigned int p_len;
unsigned int _t522;
_t522 = bux_strlen(prefix);
p_len = _t522;
_t523 = (p_len > s_len);
if (!_t523) goto endif229;
{
return 0;
}
endif229:;
int r;
int _t524;
_t524 = bux_strncmp(s, prefix, p_len);
r = _t524;
_t525 = (r == 0);
return _t525;
}
bool String_EndsWith(const char* s, const char* suffix) {
int _t528;
int _t529;
int _t532;
unsigned int s_len;
unsigned int _t526;
_t526 = bux_strlen(s);
s_len = _t526;
unsigned int suf_len;
unsigned int _t527;
_t527 = bux_strlen(suffix);
suf_len = _t527;
_t528 = (suf_len > s_len);
if (!_t528) goto endif231;
{
return 0;
}
endif231:;
unsigned int start;
_t529 = s_len - suf_len;
start = _t529;
const char* tail;
const char* _t530;
_t530 = bux_str_slice(s, start, suf_len);
tail = _t530;
bool eq;
int _t531;
_t531 = bux_strcmp(tail, suffix);
_t532 = (_t531 == 0);
eq = _t532;
return eq;
}
bool String_Contains(const char* s, const char* substr) {
int _t534;
int r;
int _t533;
_t533 = bux_str_contains(s, substr);
r = _t533;
_t534 = (r != 0);
return _t534;
}
const char* String_Slice(const char* s, unsigned int start, unsigned int len) {
const char* _t535;
_t535 = bux_str_slice(s, start, len);
return _t535;
}
const char* String_Trim(const char* s) {
const char* _t536;
_t536 = bux_str_trim(s);
return _t536;
}
const char* String_TrimLeft(const char* s) {
const char* _t537;
_t537 = bux_str_trim_left(s);
return _t537;
}
const char* String_TrimRight(const char* s) {
const char* _t538;
_t538 = bux_str_trim_right(s);
return _t538;
}
const char* String_FromInt(int64_t n) {
const char* _t539;
_t539 = bux_int_to_str(n);
return _t539;
}
int64_t String_ToInt(const char* s) {
int64_t _t540;
_t540 = bux_str_to_int(s);
return _t540;
}
StringBuilder StringBuilder_New(void) {
StringBuilder _t542;
void* _t541;
_t541 = bux_sb_new(64);
_t542 = (StringBuilder){.handle = _t541};
return _t542;
}
StringBuilder StringBuilder_NewCap(unsigned int cap) {
StringBuilder _t544;
void* _t543;
_t543 = bux_sb_new(cap);
_t544 = (StringBuilder){.handle = _t543};
return _t544;
}
void StringBuilder_Append(StringBuilder* sb, const char* s) {
void* _t545;
_t545 = sb->handle;
bux_sb_append(_t545, s);
}
void StringBuilder_AppendInt(StringBuilder* sb, int64_t n) {
void* _t546;
_t546 = sb->handle;
bux_sb_append_int(_t546, n);
}
void StringBuilder_AppendFloat(StringBuilder* sb, double f) {
void* _t547;
_t547 = sb->handle;
bux_sb_append_float(_t547, f);
}
void StringBuilder_AppendChar(StringBuilder* sb, char c) {
void* _t548;
_t548 = sb->handle;
bux_sb_append_char(_t548, c);
}
const char* StringBuilder_Build(StringBuilder* sb) {
void* _t549;
_t549 = sb->handle;
const char* _t550;
_t550 = bux_sb_build(_t549);
return _t550;
}
void StringBuilder_Free(StringBuilder* sb) {
void* _t551;
_t551 = sb->handle;
bux_sb_free(_t551);
}
unsigned int String_SplitCount(const char* s, const char* delim) {
unsigned int _t552;
_t552 = bux_str_split_count(s, delim);
return _t552;
}
const char* String_SplitPart(const char* s, const char* delim, unsigned int index) {
const char* _t553;
_t553 = bux_str_split_part(s, delim, index);
return _t553;
}
const char* String_Join2(const char* a, const char* b, const char* sep) {
const char* _t554;
_t554 = bux_str_join2(a, b, sep);
return _t554;
}
const char* String_Chars(const char* s, unsigned int index) {
const char* _t555;
_t555 = bux_str_slice(s, index, 1);
return _t555;
}
const char* String_Find(const char* haystack, const char* needle) {
const char* _t556;
_t556 = bux_strstr(haystack, needle);
return _t556;
}
unsigned int String_Offset(const char* pos, const char* base) {
unsigned int _t557;
_t557 = bux_str_offset(pos, base);
return _t557;
}
const char* String_Replace(const char* s, const char* old, const char* new) {
int _t563;
int _t565;
int _t566;
const char* pos;
const char* _t558;
_t558 = bux_strstr(s, old);
pos = _t558;
bool _t559;
_t559 = String_IsNull(pos);
if (!_t559) goto endif233;
{
return s;
}
endif233:;
unsigned int oldLen;
unsigned int _t560;
_t560 = bux_strlen(old);
oldLen = _t560;
unsigned int prefixLen;
unsigned int _t561;
_t561 = String_Offset(pos, s);
prefixLen = _t561;
const char* prefix;
const char* _t562;
_t562 = bux_str_slice(s, 0, prefixLen);
prefix = _t562;
const char* suffix;
_t563 = prefixLen + oldLen;
unsigned int _t564;
_t564 = bux_strlen(s);
_t565 = _t564 - prefixLen;
_t566 = _t565 - oldLen;
const char* _t567;
_t567 = bux_str_slice(s, _t563, _t566);
suffix = _t567;
const char* temp;
const char* _t568;
_t568 = String_Concat(prefix, new);
temp = _t568;
const char* result;
const char* _t569;
_t569 = String_Concat(temp, suffix);
result = _t569;
return result;
}
double String_ToFloat(const char* s) {
double _t570;
_t570 = bux_str_to_float(s);
return _t570;
}
const char* String_FromBool(bool b) {
if (!b) goto endif235;
{
return "true";
}
endif235:;
return "false";
}
const char* String_FromFloat(double f) {
const char* _t571;
_t571 = bux_float_to_string(f);
return _t571;
}
const char* String_Format1(const char* pattern, const char* a0) {
const char* _t572;
_t572 = bux_str_format(pattern, a0, "", "", "", "", "", "", "");
return _t572;
}
const char* String_Format2(const char* pattern, const char* a0, const char* a1) {
const char* _t573;
_t573 = bux_str_format(pattern, a0, a1, "", "", "", "", "", "");
return _t573;
}
const char* String_Format3(const char* pattern, const char* a0, const char* a1, const char* a2) {
const char* _t574;
_t574 = bux_str_format(pattern, a0, a1, a2, "", "", "", "", "");
return _t574;
}
void Channel_SendInt(Channel_int* ch, int value) {
void* _t576;
void* _t577;
void* _t575;
_t575 = ch->handle;
_t576 = &value;
_t577 = (void*)_t576;
bux_channel_send(_t575, _t577);
}
int Channel_RecvInt(Channel_int* ch) {
void* _t579;
void* _t580;
int result;
result = 0;
void* _t578;
_t578 = ch->handle;
_t579 = &result;
_t580 = (void*)_t579;
bux_channel_recv(_t578, _t580);
return result;
}
void Channel_SendFloat64(Channel_float64* ch, double value) {
void* _t582;
void* _t583;
void* _t581;
_t581 = ch->handle;
_t582 = &value;
_t583 = (void*)_t582;
bux_channel_send(_t581, _t583);
}
double Channel_RecvFloat64(Channel_float64* ch) {
void* _t585;
void* _t586;
double result;
result = 0.0;
void* _t584;
_t584 = ch->handle;
_t585 = &result;
_t586 = (void*)_t585;
bux_channel_recv(_t584, _t586);
return result;
}
const char* Hash_Sha1(const char* data) {
int _t588;
int len;
unsigned int _t587;
_t587 = String_Len(data);
_t588 = (int)_t587;
len = _t588;
void* buf;
void* _t589;
_t589 = Alloc(20);
buf = _t589;
bux_sha1(data, len, buf);
const char* result;
const char* _t590;
_t590 = bux_bytes_to_hex(buf, 20);
result = _t590;
Free(buf);
return result;
}
const char* Hash_Sha256(const char* data) {
int _t592;
int len;
unsigned int _t591;
_t591 = String_Len(data);
_t592 = (int)_t591;
len = _t592;
void* buf;
void* _t593;
_t593 = Alloc(32);
buf = _t593;
bux_sha256(data, len, buf);
const char* result;
const char* _t594;
_t594 = bux_bytes_to_hex(buf, 32);
result = _t594;
Free(buf);
return result;
}
const char* Hash_Sha384(const char* data) {
int _t596;
int len;
unsigned int _t595;
_t595 = String_Len(data);
_t596 = (int)_t595;
len = _t596;
void* buf;
void* _t597;
_t597 = Alloc(48);
buf = _t597;
bux_sha384(data, len, buf);
const char* result;
const char* _t598;
_t598 = bux_bytes_to_hex(buf, 48);
result = _t598;
Free(buf);
return result;
}
const char* Hash_Sha512(const char* data) {
int _t600;
int len;
unsigned int _t599;
_t599 = String_Len(data);
_t600 = (int)_t599;
len = _t600;
void* buf;
void* _t601;
_t601 = Alloc(64);
buf = _t601;
bux_sha512(data, len, buf);
const char* result;
const char* _t602;
_t602 = bux_bytes_to_hex(buf, 64);
result = _t602;
Free(buf);
return result;
}
void Hash_Sha256Raw(const char* data, void* out) {
int _t604;
unsigned int _t603;
_t603 = String_Len(data);
_t604 = (int)_t603;
bux_sha256(data, _t604, out);
}
void Hash_Sha384Raw(const char* data, void* out) {
int _t606;
unsigned int _t605;
_t605 = String_Len(data);
_t606 = (int)_t605;
bux_sha384(data, _t606, out);
}
void Hash_Sha512Raw(const char* data, void* out) {
int _t608;
unsigned int _t607;
_t607 = String_Len(data);
_t608 = (int)_t607;
bux_sha512(data, _t608, out);
}
int Hash_Sha1Size(void) {
return 20;
}
int Hash_Sha256Size(void) {
return 32;
}
int Hash_Sha384Size(void) {
return 48;
}
int Hash_Sha512Size(void) {
return 64;
}
const char* Base64_Encode(const char* s) {
int _t610;
unsigned int _t609;
_t609 = String_Len(s);
_t610 = (int)_t609;
const char* _t611;
_t611 = bux_base64_encode(s, _t610);
return _t611;
}
const char* Base64_Decode(const char* s) {
int _t613;
void* _t614;
int outlen;
outlen = 0;
unsigned int _t612;
_t612 = String_Len(s);
_t613 = (int)_t612;
_t614 = &outlen;
const char* _t615;
_t615 = bux_base64_decode(s, _t613, _t614);
return _t615;
}
const char* Base64URL_Encode(const char* s) {
int _t617;
unsigned int _t616;
_t616 = String_Len(s);
_t617 = (int)_t616;
const char* _t618;
_t618 = bux_base64url_encode(s, _t617);
return _t618;
}
const char* Base64URL_Decode(const char* s) {
int _t620;
void* _t621;
int outlen;
outlen = 0;
unsigned int _t619;
_t619 = String_Len(s);
_t620 = (int)_t619;
_t621 = &outlen;
const char* _t622;
_t622 = bux_base64url_decode(s, _t620, _t621);
return _t622;
}
const char* Hmac_Sha256(const char* key, const char* message) {
int _t624;
int _t626;
int kl;
unsigned int _t623;
_t623 = String_Len(key);
_t624 = (int)_t623;
kl = _t624;
int ml;
unsigned int _t625;
_t625 = String_Len(message);
_t626 = (int)_t625;
ml = _t626;
void* buf;
void* _t627;
_t627 = Alloc(32);
buf = _t627;
bux_hmac_sha256(key, kl, message, ml, buf);
const char* result;
const char* _t628;
_t628 = bux_bytes_to_hex(buf, 32);
result = _t628;
Free(buf);
return result;
}
void Hmac_Sha256Raw(const char* key, const char* message, void* out) {
int _t630;
int _t632;
unsigned int _t629;
_t629 = String_Len(key);
_t630 = (int)_t629;
unsigned int _t631;
_t631 = String_Len(message);
_t632 = (int)_t631;
bux_hmac_sha256(key, _t630, message, _t632, out);
}
const char* Hmac_Sha256Base64(const char* key, const char* message) {
int _t634;
int _t636;
const char* _t638;
int kl;
unsigned int _t633;
_t633 = String_Len(key);
_t634 = (int)_t633;
kl = _t634;
int ml;
unsigned int _t635;
_t635 = String_Len(message);
_t636 = (int)_t635;
ml = _t636;
void* buf;
void* _t637;
_t637 = Alloc(32);
buf = _t637;
bux_hmac_sha256(key, kl, message, ml, buf);
const char* result;
_t638 = (const char*)buf;
const char* _t639;
_t639 = bux_base64_encode(_t638, 32);
result = _t639;
Free(buf);
return result;
}
const char* Hmac_Sha384(const char* key, const char* message) {
int _t641;
int _t643;
int kl;
unsigned int _t640;
_t640 = String_Len(key);
_t641 = (int)_t640;
kl = _t641;
int ml;
unsigned int _t642;
_t642 = String_Len(message);
_t643 = (int)_t642;
ml = _t643;
void* buf;
void* _t644;
_t644 = Alloc(48);
buf = _t644;
bux_hmac_sha384(key, kl, message, ml, buf);
const char* result;
const char* _t645;
_t645 = bux_bytes_to_hex(buf, 48);
result = _t645;
Free(buf);
return result;
}
void Hmac_Sha384Raw(const char* key, const char* message, void* out) {
int _t647;
int _t649;
unsigned int _t646;
_t646 = String_Len(key);
_t647 = (int)_t646;
unsigned int _t648;
_t648 = String_Len(message);
_t649 = (int)_t648;
bux_hmac_sha384(key, _t647, message, _t649, out);
}
const char* Hmac_Sha384Base64(const char* key, const char* message) {
int _t651;
int _t653;
const char* _t655;
int kl;
unsigned int _t650;
_t650 = String_Len(key);
_t651 = (int)_t650;
kl = _t651;
int ml;
unsigned int _t652;
_t652 = String_Len(message);
_t653 = (int)_t652;
ml = _t653;
void* buf;
void* _t654;
_t654 = Alloc(48);
buf = _t654;
bux_hmac_sha384(key, kl, message, ml, buf);
const char* result;
_t655 = (const char*)buf;
const char* _t656;
_t656 = bux_base64_encode(_t655, 48);
result = _t656;
Free(buf);
return result;
}
const char* Hmac_Sha512(const char* key, const char* message) {
int _t658;
int _t660;
int kl;
unsigned int _t657;
_t657 = String_Len(key);
_t658 = (int)_t657;
kl = _t658;
int ml;
unsigned int _t659;
_t659 = String_Len(message);
_t660 = (int)_t659;
ml = _t660;
void* buf;
void* _t661;
_t661 = Alloc(64);
buf = _t661;
bux_hmac_sha512(key, kl, message, ml, buf);
const char* result;
const char* _t662;
_t662 = bux_bytes_to_hex(buf, 64);
result = _t662;
Free(buf);
return result;
}
void Hmac_Sha512Raw(const char* key, const char* message, void* out) {
int _t664;
int _t666;
unsigned int _t663;
_t663 = String_Len(key);
_t664 = (int)_t663;
unsigned int _t665;
_t665 = String_Len(message);
_t666 = (int)_t665;
bux_hmac_sha512(key, _t664, message, _t666, out);
}
const char* Hmac_Sha512Base64(const char* key, const char* message) {
int _t668;
int _t670;
const char* _t672;
int kl;
unsigned int _t667;
_t667 = String_Len(key);
_t668 = (int)_t667;
kl = _t668;
int ml;
unsigned int _t669;
_t669 = String_Len(message);
_t670 = (int)_t669;
ml = _t670;
void* buf;
void* _t671;
_t671 = Alloc(64);
buf = _t671;
bux_hmac_sha512(key, kl, message, ml, buf);
const char* result;
_t672 = (const char*)buf;
const char* _t673;
_t673 = bux_base64_encode(_t672, 64);
result = _t673;
Free(buf);
return result;
}
const char* Random_Bytes(int n) {
int _t674;
unsigned int _t675;
int _t678;
const char* _t679;
_t674 = (n <= 0);
if (!_t674) goto endif237;
{
return "";
}
endif237:;
void* buf;
_t675 = (unsigned int)n;
void* _t676;
_t676 = Alloc(_t675);
buf = _t676;
int _t677;
_t677 = bux_random_bytes(buf, n);
_t678 = (_t677 != 1);
if (!_t678) goto endif239;
{
Free(buf);
return "";
}
endif239:;
_t679 = (const char*)buf;
return _t679;
}
const char* Random_Hex(int n) {
int _t680;
unsigned int _t681;
int _t684;
_t680 = (n <= 0);
if (!_t680) goto endif241;
{
return "";
}
endif241:;
void* buf;
_t681 = (unsigned int)n;
void* _t682;
_t682 = Alloc(_t681);
buf = _t682;
int _t683;
_t683 = bux_random_bytes(buf, n);
_t684 = (_t683 != 1);
if (!_t684) goto endif243;
{
Free(buf);
return "";
}
endif243:;
const char* result;
const char* _t685;
_t685 = bux_bytes_to_hex(buf, n);
result = _t685;
Free(buf);
return result;
}
const char* Random_Base64(int n) {
int _t686;
unsigned int _t687;
int _t690;
const char* _t691;
_t686 = (n <= 0);
if (!_t686) goto endif245;
{
return "";
}
endif245:;
void* buf;
_t687 = (unsigned int)n;
void* _t688;
_t688 = Alloc(_t687);
buf = _t688;
int _t689;
_t689 = bux_random_bytes(buf, n);
_t690 = (_t689 != 1);
if (!_t690) goto endif247;
{
Free(buf);
return "";
}
endif247:;
const char* result;
_t691 = (const char*)buf;
const char* _t692;
_t692 = bux_base64_encode(_t691, n);
result = _t692;
Free(buf);
return result;
}
unsigned int Random_Uint32(void) {
int _t695;
unsigned int* _t696;
unsigned int _t697;
void* buf;
void* _t693;
_t693 = Alloc(4);
buf = _t693;
int _t694;
_t694 = bux_random_bytes(buf, 4);
_t695 = (_t694 != 1);
if (!_t695) goto endif249;
{
Free(buf);
return 0;
}
endif249:;
unsigned int* ptr;
_t696 = (unsigned int*)buf;
ptr = _t696;
unsigned int val;
_t697 = *ptr;
val = _t697;
Free(buf);
return val;
}
const char* Aes_GenerateKey(void) {
unsigned int _t698;
int _t701;
const char* _t702;
void* buf;
_t698 = (unsigned int)AES_KEY_SIZE;
void* _t699;
_t699 = Alloc(_t698);
buf = _t699;
int _t700;
_t700 = bux_random_bytes(buf, AES_KEY_SIZE);
_t701 = (_t700 != 1);
if (!_t701) goto endif251;
{
Free(buf);
return "";
}
endif251:;
_t702 = (const char*)buf;
return _t702;
}
const char* Aes_GenerateIV(void) {
unsigned int _t703;
int _t706;
const char* _t707;
void* buf;
_t703 = (unsigned int)AES_IV_SIZE;
void* _t704;
_t704 = Alloc(_t703);
buf = _t704;
int _t705;
_t705 = bux_random_bytes(buf, AES_IV_SIZE);
_t706 = (_t705 != 1);
if (!_t706) goto endif253;
{
Free(buf);
return "";
}
endif253:;
_t707 = (const char*)buf;
return _t707;
}
const char* Aes_CbcEncrypt(const char* plain, const char* key, const char* iv) {
int _t709;
void* _t710;
int outlen;
outlen = 0;
unsigned int _t708;
_t708 = String_Len(plain);
_t709 = (int)_t708;
_t710 = &outlen;
const char* _t711;
_t711 = bux_aes_256_cbc_encrypt(plain, _t709, key, iv, _t710);
return _t711;
}
const char* Aes_CbcDecrypt(const char* cipher, const char* key, const char* iv) {
int _t713;
void* _t714;
int outlen;
outlen = 0;
unsigned int _t712;
_t712 = String_Len(cipher);
_t713 = (int)_t712;
_t714 = &outlen;
const char* _t715;
_t715 = bux_aes_256_cbc_decrypt(cipher, _t713, key, iv, _t714);
return _t715;
}
const char* Aes_GcmEncrypt(const char* plain, const char* key, const char* iv, void* tag) {
int _t717;
void* _t718;
int outlen;
outlen = 0;
unsigned int _t716;
_t716 = String_Len(plain);
_t717 = (int)_t716;
_t718 = &outlen;
const char* _t719;
_t719 = bux_aes_256_gcm_encrypt(plain, _t717, key, iv, tag, _t718);
return _t719;
}
const char* Aes_GcmDecrypt(const char* cipher, const char* key, const char* iv, const char* tag) {
int _t721;
void* _t722;
int outlen;
outlen = 0;
unsigned int _t720;
_t720 = String_Len(cipher);
_t721 = (int)_t720;
_t722 = &outlen;
const char* _t723;
_t723 = bux_aes_256_gcm_decrypt(cipher, _t721, key, iv, tag, _t722);
return _t723;
}
const char* Jwt_MakeHeader(JwtAlg alg) {
int _t724;
int _t725;
int _t726;
int _t727;
int _t728;
int _t729;
int _t730;
int _t731;
int _t732;
_t724 = (alg == JwtAlg_HS256);
if (!_t724) goto endif255;
{
return "{\"alg\":\"HS256\",\"typ\":\"JWT\"}";
}
endif255:;
_t725 = (alg == JwtAlg_HS384);
if (!_t725) goto endif257;
{
return "{\"alg\":\"HS384\",\"typ\":\"JWT\"}";
}
endif257:;
_t726 = (alg == JwtAlg_HS512);
if (!_t726) goto endif259;
{
return "{\"alg\":\"HS512\",\"typ\":\"JWT\"}";
}
endif259:;
_t727 = (alg == JwtAlg_RS256);
if (!_t727) goto endif261;
{
return "{\"alg\":\"RS256\",\"typ\":\"JWT\"}";
}
endif261:;
_t728 = (alg == JwtAlg_RS384);
if (!_t728) goto endif263;
{
return "{\"alg\":\"RS384\",\"typ\":\"JWT\"}";
}
endif263:;
_t729 = (alg == JwtAlg_RS512);
if (!_t729) goto endif265;
{
return "{\"alg\":\"RS512\",\"typ\":\"JWT\"}";
}
endif265:;
_t730 = (alg == JwtAlg_ES256);
if (!_t730) goto endif267;
{
return "{\"alg\":\"ES256\",\"typ\":\"JWT\"}";
}
endif267:;
_t731 = (alg == JwtAlg_ES384);
if (!_t731) goto endif269;
{
return "{\"alg\":\"ES384\",\"typ\":\"JWT\"}";
}
endif269:;
_t732 = (alg == JwtAlg_EdDSA);
if (!_t732) goto endif271;
{
return "{\"alg\":\"EdDSA\",\"typ\":\"JWT\"}";
}
endif271:;
return "{\"alg\":\"none\",\"typ\":\"JWT\"}";
}
const char* Jwt_Sign(JwtAlg alg, const char* signingInput, const char* key) {
int _t733;
const char* _t735;
int _t737;
const char* _t739;
int _t741;
const char* _t743;
int _t745;
int _t748;
int _t750;
int _t753;
int _t755;
int _t758;
int _t760;
int _t763;
int _t765;
int _t768;
int _t770;
_t733 = (alg == JwtAlg_HS256);
if (!_t733) goto endif273;
{
void* buf;
void* _t734;
_t734 = Alloc(32);
buf = _t734;
Hmac_Sha256Raw(key, signingInput, buf);
const char* result;
_t735 = (const char*)buf;
const char* _t736;
_t736 = bux_base64_encode(_t735, 32);
result = _t736;
Free(buf);
return result;
}
endif273:;
_t737 = (alg == JwtAlg_HS384);
if (!_t737) goto endif275;
{
void* buf;
void* _t738;
_t738 = Alloc(48);
buf = _t738;
Hmac_Sha384Raw(key, signingInput, buf);
const char* result;
_t739 = (const char*)buf;
const char* _t740;
_t740 = bux_base64_encode(_t739, 48);
result = _t740;
Free(buf);
return result;
}
endif275:;
_t741 = (alg == JwtAlg_HS512);
if (!_t741) goto endif277;
{
void* buf;
void* _t742;
_t742 = Alloc(64);
buf = _t742;
Hmac_Sha512Raw(key, signingInput, buf);
const char* result;
_t743 = (const char*)buf;
const char* _t744;
_t744 = bux_base64_encode(_t743, 64);
result = _t744;
Free(buf);
return result;
}
endif277:;
_t745 = (alg == JwtAlg_RS256);
if (!_t745) goto endif279;
{
const char* raw;
const char* _t746;
_t746 = Rsa_SignSha256(key, signingInput);
raw = _t746;
unsigned int _t747;
_t747 = String_Len(raw);
_t748 = (int)_t747;
const char* _t749;
_t749 = bux_base64_encode(raw, _t748);
return _t749;
}
endif279:;
_t750 = (alg == JwtAlg_RS384);
if (!_t750) goto endif281;
{
const char* raw;
const char* _t751;
_t751 = Rsa_SignSha384(key, signingInput);
raw = _t751;
unsigned int _t752;
_t752 = String_Len(raw);
_t753 = (int)_t752;
const char* _t754;
_t754 = bux_base64_encode(raw, _t753);
return _t754;
}
endif281:;
_t755 = (alg == JwtAlg_RS512);
if (!_t755) goto endif283;
{
const char* raw;
const char* _t756;
_t756 = Rsa_SignSha512(key, signingInput);
raw = _t756;
unsigned int _t757;
_t757 = String_Len(raw);
_t758 = (int)_t757;
const char* _t759;
_t759 = bux_base64_encode(raw, _t758);
return _t759;
}
endif283:;
_t760 = (alg == JwtAlg_ES256);
if (!_t760) goto endif285;
{
const char* raw;
const char* _t761;
_t761 = Ecdsa_SignP256(key, signingInput);
raw = _t761;
unsigned int _t762;
_t762 = String_Len(raw);
_t763 = (int)_t762;
const char* _t764;
_t764 = bux_base64_encode(raw, _t763);
return _t764;
}
endif285:;
_t765 = (alg == JwtAlg_ES384);
if (!_t765) goto endif287;
{
const char* raw;
const char* _t766;
_t766 = Ecdsa_SignP384(key, signingInput);
raw = _t766;
unsigned int _t767;
_t767 = String_Len(raw);
_t768 = (int)_t767;
const char* _t769;
_t769 = bux_base64_encode(raw, _t768);
return _t769;
}
endif287:;
_t770 = (alg == JwtAlg_EdDSA);
if (!_t770) goto endif289;
{
const char* _t771;
_t771 = Ed25519_Sign(key, signingInput);
return _t771;
}
endif289:;
return "";
}
bool Jwt_Verify(JwtAlg alg, const char* signingInput, const char* signatureB64, const char* key) {
int _t772;
const char* _t774;
int _t777;
const char* _t779;
int _t782;
const char* _t784;
int _t787;
int _t789;
int _t791;
int _t793;
int _t795;
int _t797;
_t772 = (alg == JwtAlg_HS256);
if (!_t772) goto endif291;
{
void* expectBuf;
void* _t773;
_t773 = Alloc(32);
expectBuf = _t773;
Hmac_Sha256Raw(key, signingInput, expectBuf);
const char* expectB64;
_t774 = (const char*)expectBuf;
const char* _t775;
_t775 = bux_base64_encode(_t774, 32);
expectB64 = _t775;
Free(expectBuf);
bool _t776;
_t776 = String_Eq(expectB64, signatureB64);
return _t776;
}
endif291:;
_t777 = (alg == JwtAlg_HS384);
if (!_t777) goto endif293;
{
void* expectBuf;
void* _t778;
_t778 = Alloc(48);
expectBuf = _t778;
Hmac_Sha384Raw(key, signingInput, expectBuf);
const char* expectB64;
_t779 = (const char*)expectBuf;
const char* _t780;
_t780 = bux_base64_encode(_t779, 48);
expectB64 = _t780;
Free(expectBuf);
bool _t781;
_t781 = String_Eq(expectB64, signatureB64);
return _t781;
}
endif293:;
_t782 = (alg == JwtAlg_HS512);
if (!_t782) goto endif295;
{
void* expectBuf;
void* _t783;
_t783 = Alloc(64);
expectBuf = _t783;
Hmac_Sha512Raw(key, signingInput, expectBuf);
const char* expectB64;
_t784 = (const char*)expectBuf;
const char* _t785;
_t785 = bux_base64_encode(_t784, 64);
expectB64 = _t785;
Free(expectBuf);
bool _t786;
_t786 = String_Eq(expectB64, signatureB64);
return _t786;
}
endif295:;
_t787 = (alg == JwtAlg_RS256);
if (!_t787) goto endif297;
{
bool _t788;
_t788 = Rsa_VerifySha256(key, signingInput, signatureB64);
return _t788;
}
endif297:;
_t789 = (alg == JwtAlg_RS384);
if (!_t789) goto endif299;
{
bool _t790;
_t790 = Rsa_VerifySha384(key, signingInput, signatureB64);
return _t790;
}
endif299:;
_t791 = (alg == JwtAlg_RS512);
if (!_t791) goto endif301;
{
bool _t792;
_t792 = Rsa_VerifySha512(key, signingInput, signatureB64);
return _t792;
}
endif301:;
_t793 = (alg == JwtAlg_ES256);
if (!_t793) goto endif303;
{
bool _t794;
_t794 = Ecdsa_VerifyP256(key, signingInput, signatureB64);
return _t794;
}
endif303:;
_t795 = (alg == JwtAlg_ES384);
if (!_t795) goto endif305;
{
bool _t796;
_t796 = Ecdsa_VerifyP384(key, signingInput, signatureB64);
return _t796;
}
endif305:;
_t797 = (alg == JwtAlg_EdDSA);
if (!_t797) goto endif307;
{
bool _t798;
_t798 = Ed25519_Verify(key, signatureB64, signingInput);
return _t798;
}
endif307:;
return 0;
}
const char* Jwt_Encode(const char* headerJson, const char* payloadJson, JwtAlg alg, const char* key) {
const char* headerB64;
const char* _t799;
_t799 = Base64URL_Encode(headerJson);
headerB64 = _t799;
const char* payloadB64;
const char* _t800;
_t800 = Base64URL_Encode(payloadJson);
payloadB64 = _t800;
const char* signingInput;
const char* _t801;
_t801 = String_Concat(headerB64, ".");
signingInput = _t801;
const char* signingInputFull;
const char* _t802;
_t802 = String_Concat(signingInput, payloadB64);
signingInputFull = _t802;
const char* sigB64;
const char* _t803;
_t803 = Jwt_Sign(alg, signingInputFull, key);
sigB64 = _t803;
const char* part1;
const char* _t804;
_t804 = String_Concat(signingInputFull, ".");
part1 = _t804;
const char* _t805;
_t805 = String_Concat(part1, sigB64);
return _t805;
}
bool Jwt_Decode(const char* token, JwtAlg alg, const char* key, const char** headerOut, const char** payloadOut) {
int _t807;
int _t814;
unsigned int partCount;
unsigned int _t806;
_t806 = bux_str_split_count(token, ".");
partCount = _t806;
_t807 = (partCount != 3);
if (!_t807) goto endif309;
{
return 0;
}
endif309:;
const char* headerB64;
const char* _t808;
_t808 = bux_str_split_part(token, ".", 0);
headerB64 = _t808;
const char* payloadB64;
const char* _t809;
_t809 = bux_str_split_part(token, ".", 1);
payloadB64 = _t809;
const char* sigB64;
const char* _t810;
_t810 = bux_str_split_part(token, ".", 2);
sigB64 = _t810;
const char* input;
const char* _t811;
_t811 = String_Concat(headerB64, ".");
input = _t811;
const char* signingInput;
const char* _t812;
_t812 = String_Concat(input, payloadB64);
signingInput = _t812;
bool _t813;
_t813 = Jwt_Verify(alg, signingInput, sigB64, key);
_t814 = !_t813;
if (!_t814) goto endif311;
{
return 0;
}
endif311:;
const char* _t815;
_t815 = Base64URL_Decode(headerB64);
headerOut[0] = _t815;
const char* _t816;
_t816 = Base64URL_Decode(payloadB64);
payloadOut[0] = _t816;
return 1;
}
const char* Jwt_EncodeHS256(const char* payloadJson, const char* secret) {
const char* header;
const char* _t817;
_t817 = Jwt_MakeHeader(JwtAlg_HS256);
header = _t817;
const char* _t818;
_t818 = Jwt_Encode(header, payloadJson, JwtAlg_HS256, secret);
return _t818;
}
const char* Jwt_EncodeHS384(const char* payloadJson, const char* secret) {
const char* header;
const char* _t819;
_t819 = Jwt_MakeHeader(JwtAlg_HS384);
header = _t819;
const char* _t820;
_t820 = Jwt_Encode(header, payloadJson, JwtAlg_HS384, secret);
return _t820;
}
const char* Jwt_EncodeHS512(const char* payloadJson, const char* secret) {
const char* header;
const char* _t821;
_t821 = Jwt_MakeHeader(JwtAlg_HS512);
header = _t821;
const char* _t822;
_t822 = Jwt_Encode(header, payloadJson, JwtAlg_HS512, secret);
return _t822;
}
const char* Jwt_EncodeRS256(const char* payloadJson, const char* pemPrivateKey) {
const char* header;
const char* _t823;
_t823 = Jwt_MakeHeader(JwtAlg_RS256);
header = _t823;
const char* _t824;
_t824 = Jwt_Encode(header, payloadJson, JwtAlg_RS256, pemPrivateKey);
return _t824;
}
const char* Jwt_EncodeES256(const char* payloadJson, const char* pemPrivateKey) {
const char* header;
const char* _t825;
_t825 = Jwt_MakeHeader(JwtAlg_ES256);
header = _t825;
const char* _t826;
_t826 = Jwt_Encode(header, payloadJson, JwtAlg_ES256, pemPrivateKey);
return _t826;
}
const char* Jwt_EncodeEdDSA(const char* payloadJson, const char* rawPrivKey) {
const char* header;
const char* _t827;
_t827 = Jwt_MakeHeader(JwtAlg_EdDSA);
header = _t827;
const char* _t828;
_t828 = Jwt_Encode(header, payloadJson, JwtAlg_EdDSA, rawPrivKey);
return _t828;
}
const char* Ecdsa_SignP256(const char* pemPrivateKey, const char* data) {
int _t830;
int _t832;
void* _t833;
int siglen;
siglen = 0;
unsigned int _t829;
_t829 = String_Len(pemPrivateKey);
_t830 = (int)_t829;
unsigned int _t831;
_t831 = String_Len(data);
_t832 = (int)_t831;
_t833 = &siglen;
const char* _t834;
_t834 = bux_ecdsa_sign_p256(pemPrivateKey, _t830, data, _t832, _t833);
return _t834;
}
const char* Ecdsa_SignP256Base64(const char* pemPrivateKey, const char* data) {
int _t837;
const char* raw;
const char* _t835;
_t835 = Ecdsa_SignP256(pemPrivateKey, data);
raw = _t835;
unsigned int _t836;
_t836 = String_Len(raw);
_t837 = (int)_t836;
const char* _t838;
_t838 = bux_base64_encode(raw, _t837);
return _t838;
}
bool Ecdsa_VerifyP256(const char* pemPublicKey, const char* data, const char* signature) {
int _t840;
int _t842;
int _t844;
int _t846;
int r;
unsigned int _t839;
_t839 = String_Len(pemPublicKey);
_t840 = (int)_t839;
unsigned int _t841;
_t841 = String_Len(data);
_t842 = (int)_t841;
unsigned int _t843;
_t843 = String_Len(signature);
_t844 = (int)_t843;
int _t845;
_t845 = bux_ecdsa_verify_p256(pemPublicKey, _t840, data, _t842, signature, _t844);
r = _t845;
_t846 = (r == 1);
return _t846;
}
bool Ecdsa_VerifyP256Base64(const char* pemPublicKey, const char* data, const char* signatureB64) {
int _t848;
void* _t849;
int outlen;
outlen = 0;
const char* sig;
unsigned int _t847;
_t847 = String_Len(signatureB64);
_t848 = (int)_t847;
_t849 = &outlen;
const char* _t850;
_t850 = bux_base64_decode(signatureB64, _t848, _t849);
sig = _t850;
bool _t851;
_t851 = Ecdsa_VerifyP256(pemPublicKey, data, sig);
return _t851;
}
const char* Ecdsa_SignP384(const char* pemPrivateKey, const char* data) {
int _t853;
int _t855;
void* _t856;
int siglen;
siglen = 0;
unsigned int _t852;
_t852 = String_Len(pemPrivateKey);
_t853 = (int)_t852;
unsigned int _t854;
_t854 = String_Len(data);
_t855 = (int)_t854;
_t856 = &siglen;
const char* _t857;
_t857 = bux_ecdsa_sign_p384(pemPrivateKey, _t853, data, _t855, _t856);
return _t857;
}
const char* Ecdsa_SignP384Base64(const char* pemPrivateKey, const char* data) {
int _t860;
const char* raw;
const char* _t858;
_t858 = Ecdsa_SignP384(pemPrivateKey, data);
raw = _t858;
unsigned int _t859;
_t859 = String_Len(raw);
_t860 = (int)_t859;
const char* _t861;
_t861 = bux_base64_encode(raw, _t860);
return _t861;
}
bool Ecdsa_VerifyP384(const char* pemPublicKey, const char* data, const char* signature) {
int _t863;
int _t865;
int _t867;
int _t869;
int r;
unsigned int _t862;
_t862 = String_Len(pemPublicKey);
_t863 = (int)_t862;
unsigned int _t864;
_t864 = String_Len(data);
_t865 = (int)_t864;
unsigned int _t866;
_t866 = String_Len(signature);
_t867 = (int)_t866;
int _t868;
_t868 = bux_ecdsa_verify_p384(pemPublicKey, _t863, data, _t865, signature, _t867);
r = _t868;
_t869 = (r == 1);
return _t869;
}
bool Ecdsa_VerifyP384Base64(const char* pemPublicKey, const char* data, const char* signatureB64) {
int _t871;
void* _t872;
int outlen;
outlen = 0;
const char* sig;
unsigned int _t870;
_t870 = String_Len(signatureB64);
_t871 = (int)_t870;
_t872 = &outlen;
const char* _t873;
_t873 = bux_base64_decode(signatureB64, _t871, _t872);
sig = _t873;
bool _t874;
_t874 = Ecdsa_VerifyP384(pemPublicKey, data, sig);
return _t874;
}
bool Ed25519_Keypair(void* pubKey, void* privKey) {
int _t876;
int r;
int _t875;
_t875 = bux_ed25519_keypair(pubKey, privKey);
r = _t875;
_t876 = (r == 1);
return _t876;
}
const char* Ed25519_KeypairBase64(void) {
unsigned int _t877;
unsigned int _t879;
int _t882;
const char* _t883;
const char* _t885;
void* pubBuf;
_t877 = (unsigned int)ED25519_PUBKEY_SIZE;
void* _t878;
_t878 = Alloc(_t877);
pubBuf = _t878;
void* priv;
_t879 = (unsigned int)ED25519_PRIVKEY_SIZE;
void* _t880;
_t880 = Alloc(_t879);
priv = _t880;
int _t881;
_t881 = bux_ed25519_keypair(pubBuf, priv);
_t882 = (_t881 != 1);
if (!_t882) goto endif313;
{
Free(pubBuf);
Free(priv);
return "";
}
endif313:;
const char* pubB64;
_t883 = (const char*)pubBuf;
const char* _t884;
_t884 = bux_base64_encode(_t883, ED25519_PUBKEY_SIZE);
pubB64 = _t884;
const char* privB64;
_t885 = (const char*)priv;
const char* _t886;
_t886 = bux_base64_encode(_t885, ED25519_PRIVKEY_SIZE);
privB64 = _t886;
Free(pubBuf);
Free(priv);
const char* pair;
const char* _t887;
_t887 = String_Concat(pubB64, ":");
pair = _t887;
const char* _t888;
_t888 = String_Concat(pair, privB64);
return _t888;
}
const char* Ed25519_Sign(const char* privKey, const char* data) {
unsigned int _t889;
int _t892;
int _t894;
const char* _t895;
void* sig;
_t889 = (unsigned int)ED25519_SIG_SIZE;
void* _t890;
_t890 = Alloc(_t889);
sig = _t890;
unsigned int _t891;
_t891 = String_Len(data);
_t892 = (int)_t891;
int _t893;
_t893 = bux_ed25519_sign(privKey, data, _t892, sig);
_t894 = (_t893 != 1);
if (!_t894) goto endif315;
{
Free(sig);
return "";
}
endif315:;
_t895 = (const char*)sig;
return _t895;
}
const char* Ed25519_SignBase64(const char* privKey, const char* data) {
int _t898;
const char* sig;
const char* _t896;
_t896 = Ed25519_Sign(privKey, data);
sig = _t896;
unsigned int _t897;
_t897 = String_Len(sig);
_t898 = (_t897 == 0);
if (!_t898) goto endif317;
{
return "";
}
endif317:;
const char* _t899;
_t899 = bux_base64_encode(sig, ED25519_SIG_SIZE);
return _t899;
}
bool Ed25519_Verify(const char* pubKey, const char* signature, const char* data) {
int _t901;
int _t903;
int r;
unsigned int _t900;
_t900 = String_Len(data);
_t901 = (int)_t900;
int _t902;
_t902 = bux_ed25519_verify(pubKey, signature, data, _t901);
r = _t902;
_t903 = (r == 1);
return _t903;
}
bool Ed25519_VerifyBase64(const char* pubKey, const char* signatureB64, const char* data) {
int _t905;
void* _t906;
int _t908;
int outlen;
outlen = 0;
const char* sig;
unsigned int _t904;
_t904 = String_Len(signatureB64);
_t905 = (int)_t904;
_t906 = &outlen;
const char* _t907;
_t907 = bux_base64_decode(signatureB64, _t905, _t906);
sig = _t907;
_t908 = (outlen != ED25519_SIG_SIZE);
if (!_t908) goto endif319;
{
return 0;
}
endif319:;
bool _t909;
_t909 = Ed25519_Verify(pubKey, sig, data);
return _t909;
}
const char* Rsa_SignSha256(const char* pemPrivateKey, const char* data) {
int _t911;
int _t913;
void* _t914;
int siglen;
siglen = 0;
unsigned int _t910;
_t910 = String_Len(pemPrivateKey);
_t911 = (int)_t910;
unsigned int _t912;
_t912 = String_Len(data);
_t913 = (int)_t912;
_t914 = &siglen;
const char* _t915;
_t915 = bux_rsa_sign_sha256(pemPrivateKey, _t911, data, _t913, _t914);
return _t915;
}
const char* Rsa_SignSha384(const char* pemPrivateKey, const char* data) {
int _t917;
int _t919;
void* _t920;
int siglen;
siglen = 0;
unsigned int _t916;
_t916 = String_Len(pemPrivateKey);
_t917 = (int)_t916;
unsigned int _t918;
_t918 = String_Len(data);
_t919 = (int)_t918;
_t920 = &siglen;
const char* _t921;
_t921 = bux_rsa_sign_sha384(pemPrivateKey, _t917, data, _t919, _t920);
return _t921;
}
const char* Rsa_SignSha512(const char* pemPrivateKey, const char* data) {
int _t923;
int _t925;
void* _t926;
int siglen;
siglen = 0;
unsigned int _t922;
_t922 = String_Len(pemPrivateKey);
_t923 = (int)_t922;
unsigned int _t924;
_t924 = String_Len(data);
_t925 = (int)_t924;
_t926 = &siglen;
const char* _t927;
_t927 = bux_rsa_sign_sha512(pemPrivateKey, _t923, data, _t925, _t926);
return _t927;
}
const char* Rsa_SignSha256Base64(const char* pemPrivateKey, const char* data) {
int _t930;
const char* raw;
const char* _t928;
_t928 = Rsa_SignSha256(pemPrivateKey, data);
raw = _t928;
unsigned int _t929;
_t929 = String_Len(raw);
_t930 = (int)_t929;
const char* _t931;
_t931 = bux_base64_encode(raw, _t930);
return _t931;
}
const char* Rsa_SignSha384Base64(const char* pemPrivateKey, const char* data) {
int _t934;
const char* raw;
const char* _t932;
_t932 = Rsa_SignSha384(pemPrivateKey, data);
raw = _t932;
unsigned int _t933;
_t933 = String_Len(raw);
_t934 = (int)_t933;
const char* _t935;
_t935 = bux_base64_encode(raw, _t934);
return _t935;
}
const char* Rsa_SignSha512Base64(const char* pemPrivateKey, const char* data) {
int _t938;
const char* raw;
const char* _t936;
_t936 = Rsa_SignSha512(pemPrivateKey, data);
raw = _t936;
unsigned int _t937;
_t937 = String_Len(raw);
_t938 = (int)_t937;
const char* _t939;
_t939 = bux_base64_encode(raw, _t938);
return _t939;
}
bool Rsa_VerifySha256(const char* pemPublicKey, const char* data, const char* signature) {
int _t941;
int _t943;
int _t945;
int _t947;
int r;
unsigned int _t940;
_t940 = String_Len(pemPublicKey);
_t941 = (int)_t940;
unsigned int _t942;
_t942 = String_Len(data);
_t943 = (int)_t942;
unsigned int _t944;
_t944 = String_Len(signature);
_t945 = (int)_t944;
int _t946;
_t946 = bux_rsa_verify_sha256(pemPublicKey, _t941, data, _t943, signature, _t945);
r = _t946;
_t947 = (r == 1);
return _t947;
}
bool Rsa_VerifySha384(const char* pemPublicKey, const char* data, const char* signature) {
int _t949;
int _t951;
int _t953;
int _t955;
int r;
unsigned int _t948;
_t948 = String_Len(pemPublicKey);
_t949 = (int)_t948;
unsigned int _t950;
_t950 = String_Len(data);
_t951 = (int)_t950;
unsigned int _t952;
_t952 = String_Len(signature);
_t953 = (int)_t952;
int _t954;
_t954 = bux_rsa_verify_sha384(pemPublicKey, _t949, data, _t951, signature, _t953);
r = _t954;
_t955 = (r == 1);
return _t955;
}
bool Rsa_VerifySha512(const char* pemPublicKey, const char* data, const char* signature) {
int _t957;
int _t959;
int _t961;
int _t963;
int r;
unsigned int _t956;
_t956 = String_Len(pemPublicKey);
_t957 = (int)_t956;
unsigned int _t958;
_t958 = String_Len(data);
_t959 = (int)_t958;
unsigned int _t960;
_t960 = String_Len(signature);
_t961 = (int)_t960;
int _t962;
_t962 = bux_rsa_verify_sha512(pemPublicKey, _t957, data, _t959, signature, _t961);
r = _t962;
_t963 = (r == 1);
return _t963;
}
bool Rsa_VerifySha256Base64(const char* pemPublicKey, const char* data, const char* signatureB64) {
int _t965;
void* _t966;
int outlen;
outlen = 0;
const char* sig;
unsigned int _t964;
_t964 = String_Len(signatureB64);
_t965 = (int)_t964;
_t966 = &outlen;
const char* _t967;
_t967 = bux_base64_decode(signatureB64, _t965, _t966);
sig = _t967;
bool _t968;
_t968 = Rsa_VerifySha256(pemPublicKey, data, sig);
return _t968;
}
bool Rsa_VerifySha384Base64(const char* pemPublicKey, const char* data, const char* signatureB64) {
int _t970;
void* _t971;
int outlen;
outlen = 0;
const char* sig;
unsigned int _t969;
_t969 = String_Len(signatureB64);
_t970 = (int)_t969;
_t971 = &outlen;
const char* _t972;
_t972 = bux_base64_decode(signatureB64, _t970, _t971);
sig = _t972;
bool _t973;
_t973 = Rsa_VerifySha384(pemPublicKey, data, sig);
return _t973;
}
bool Rsa_VerifySha512Base64(const char* pemPublicKey, const char* data, const char* signatureB64) {
int _t975;
void* _t976;
int outlen;
outlen = 0;
const char* sig;
unsigned int _t974;
_t974 = String_Len(signatureB64);
_t975 = (int)_t974;
_t976 = &outlen;
const char* _t977;
_t977 = bux_base64_decode(signatureB64, _t975, _t976);
sig = _t977;
bool _t978;
_t978 = Rsa_VerifySha512(pemPublicKey, data, sig);
return _t978;
}
int Main(void) {
int m1;
int _t979;
_t979 = Max_int(10, 20);
m1 = _t979;
int m2;
int _t980;
_t980 = Max_int(5, 3);
m2 = _t980;
PrintLine("Max(10, 20) = ");
PrintInt(m1);
PrintLine("");
PrintLine("Max(5, 3) = ");
PrintInt(m2);
PrintLine("");
return 0;
}
int Max_int(int a, int b) {
int _t981;
_t981 = (a > b);
if (!_t981) goto else320;
{
return a;
}
goto endif321;
else320:;
{
return b;
}
endif321:;
}
/* C entry point wrapper */
extern int g_argc;
extern char** g_argv;
int main(int argc, char** argv) {
g_argc = argc;
g_argv = argv;
return Main();
}