/* 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 struct Channel_float64 {
    void* handle;
} Channel_float64;

typedef struct TaskHandle {
    void* handle;
} TaskHandle;

typedef struct RwLock {
    void* handle;
} RwLock;

typedef struct Channel_int {
    void* handle;
} Channel_int;

typedef enum {
    JwtAlg_HS256,
    JwtAlg_HS384,
    JwtAlg_HS512,
    JwtAlg_RS256,
    JwtAlg_RS384,
    JwtAlg_RS512,
    JwtAlg_ES256,
    JwtAlg_ES384,
    JwtAlg_EdDSA
} JwtAlg;

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 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 Mutex {
    void* handle;
} Mutex;

typedef struct StringBuilder {
    void* handle;
} StringBuilder;

typedef struct JsonParser {
    const char* src;
    unsigned int pos;
    unsigned int len;
    const char* error;
} JsonParser;

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 wend2;
    {
    const char* ch;
    const char* _t61;
    _t61 = String_Chars(tmpl, i);
    ch = _t61;
    bool _t62;
    _t62 = String_Eq(ch, "{");
    if (!_t62) goto endif4;
    {
    unsigned int digitIdx;
    _t63 = i + 1;
    digitIdx = _t63;
    _t64 = (digitIdx < tmplLen);
    if (!_t64) goto endif6;
    {
    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 else7;
    _t68 = (int64_t)argCount;
    _t69 = (d < _t68);
    *(bool*)&__and_tmp_0 = _t69;
    goto endif8;
    else7:;
    *(bool*)&__and_tmp_0 = 0;
    endif8:;
    bool _t70;
    _t70 = *(bool*)&__and_tmp_0;
    if (!_t70) goto endif10;
    {
    _t71 = i + 2;
    i = _t71;
    _t72 = (i < tmplLen);
    if (!_t72) goto endif12;
    {
    const char* closeCh;
    const char* _t73;
    _t73 = String_Chars(tmpl, i);
    closeCh = _t73;
    bool _t74;
    _t74 = String_Eq(closeCh, "}");
    if (!_t74) goto endif14;
    {
    _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;
    }
    endif14:;
    }
    endif12:;
    }
    endif10:;
    }
    endif6:;
    }
    endif4:;
    _t79 = &sb;
    StringBuilder_Append(_t79, ch);
    _t80 = i + 1;
    i = _t80;
    }
    goto while1;
    wend2:;
    _t81 = &sb;
    const char* _t82;
    _t82 = StringBuilder_Build(_t81);
    return _t82;
}

const char* Fmt_Fmt1(const char* tmpl, const char* a1) {
    const char** _t84;
    const char** args;
    /* sizeof(const char*) */
    void* _t83;
    _t83 = bux_alloc(sizeof(const char*));
    _t84 = (const char**)_t83;
    args = _t84;
    args[0] = a1;
    const char* _t85;
    _t85 = Fmt_Format(tmpl, args, 1);
    return _t85;
}

const char* Fmt_FmtInt(const char* tmpl, int64_t val) {
    const char* s;
    const char* _t86;
    _t86 = String_FromInt(val);
    s = _t86;
    const char* _t87;
    _t87 = Fmt_Fmt1(tmpl, s);
    return _t87;
}

const char* Fmt_FmtBool(const char* tmpl, bool val) {
    const char* s;
    const char* _t88;
    _t88 = String_FromBool(val);
    s = _t88;
    const char* _t89;
    _t89 = Fmt_Fmt1(tmpl, s);
    return _t89;
}

const char* Fmt_FmtFloat(const char* tmpl, double val) {
    const char* s;
    const char* _t90;
    _t90 = String_FromFloat(val);
    s = _t90;
    const char* _t91;
    _t91 = Fmt_Fmt1(tmpl, s);
    return _t91;
}

const char* Fmt_Fmt2(const char* tmpl, const char* a1, const char* a2) {
    int _t92;
    const char** _t94;
    const char** args;
    /* sizeof(const char*) */
    _t92 = 2 * sizeof(const char*);
    void* _t93;
    _t93 = bux_alloc(_t92);
    _t94 = (const char**)_t93;
    args = _t94;
    args[0] = a1;
    args[1] = a2;
    const char* _t95;
    _t95 = Fmt_Format(tmpl, args, 2);
    return _t95;
}

const char* Fmt_Fmt3(const char* tmpl, const char* a1, const char* a2, const char* a3) {
    int _t96;
    const char** _t98;
    const char** args;
    /* sizeof(const char*) */
    _t96 = 3 * sizeof(const char*);
    void* _t97;
    _t97 = bux_alloc(_t96);
    _t98 = (const char**)_t97;
    args = _t98;
    args[0] = a1;
    args[1] = a2;
    args[2] = a3;
    const char* _t99;
    _t99 = Fmt_Format(tmpl, args, 3);
    return _t99;
}

const char* Crypto_Sha256(const char* data) {
    int _t101;
    void* _t103;
    int len;
    unsigned int _t100;
    _t100 = String_Len(data);
    _t101 = (int)_t100;
    len = _t101;
    void* hashBuf;
    void* _t102;
    _t102 = Alloc(32);
    hashBuf = _t102;
    bux_sha256(data, len, hashBuf);
    const char* result;
    _t103 = (void*)hashBuf;
    const char* _t104;
    _t104 = bux_bytes_to_hex(_t103, 32);
    result = _t104;
    Free(hashBuf);
    return result;
}

const char* Crypto_HmacSha256(const char* key, const char* message) {
    int _t106;
    int _t108;
    void* _t110;
    int keylen;
    unsigned int _t105;
    _t105 = String_Len(key);
    _t106 = (int)_t105;
    keylen = _t106;
    int msglen;
    unsigned int _t107;
    _t107 = String_Len(message);
    _t108 = (int)_t107;
    msglen = _t108;
    void* hmacBuf;
    void* _t109;
    _t109 = Alloc(32);
    hmacBuf = _t109;
    bux_hmac_sha256(key, keylen, message, msglen, hmacBuf);
    const char* result;
    _t110 = (void*)hmacBuf;
    const char* _t111;
    _t111 = bux_bytes_to_hex(_t110, 32);
    result = _t111;
    Free(hmacBuf);
    return result;
}

const char* Crypto_RandomBytes(int n) {
    int _t112;
    unsigned int _t113;
    int _t116;
    const char* _t117;
    _t112 = (n <= 0);
    if (!_t112) goto endif16;
    {
    return "";
    }
    endif16:;
    void* buf;
    _t113 = (unsigned int)n;
    void* _t114;
    _t114 = Alloc(_t113);
    buf = _t114;
    int _t115;
    _t115 = bux_random_bytes(buf, n);
    _t116 = (_t115 != 1);
    if (!_t116) goto endif18;
    {
    Free(buf);
    return "";
    }
    endif18:;
    const char* result;
    _t117 = (const char*)buf;
    const char* _t118;
    _t118 = bux_base64_encode(_t117, n);
    result = _t118;
    Free(buf);
    return result;
}

const char* Crypto_Base64Encode(const char* s) {
    int _t120;
    unsigned int _t119;
    _t119 = String_Len(s);
    _t120 = (int)_t119;
    const char* _t121;
    _t121 = bux_base64_encode(s, _t120);
    return _t121;
}

const char* Crypto_HmacSha256Raw(const char* key, const char* message) {
    int _t123;
    int _t125;
    const char* _t127;
    int keylen;
    unsigned int _t122;
    _t122 = String_Len(key);
    _t123 = (int)_t122;
    keylen = _t123;
    int msglen;
    unsigned int _t124;
    _t124 = String_Len(message);
    _t125 = (int)_t124;
    msglen = _t125;
    void* hmacBuf;
    void* _t126;
    _t126 = Alloc(32);
    hmacBuf = _t126;
    bux_hmac_sha256(key, keylen, message, msglen, hmacBuf);
    const char* result;
    _t127 = (const char*)hmacBuf;
    const char* _t128;
    _t128 = bux_base64_encode(_t127, 32);
    result = _t128;
    Free(hmacBuf);
    return result;
}

const char* Crypto_Base64Decode(const char* s) {
    int _t130;
    void* _t131;
    int outlen;
    outlen = 0;
    unsigned int _t129;
    _t129 = String_Len(s);
    _t130 = (int)_t129;
    _t131 = &outlen;
    const char* _t132;
    _t132 = bux_base64_decode(s, _t130, _t131);
    return _t132;
}

Mutex Mutex_New(void) {
    Mutex _t134;
    void* _t133;
    _t133 = bux_mutex_new();
    _t134 = (Mutex){.handle = _t133};
    return _t134;
}

void Mutex_Lock(Mutex* m) {
    void* _t135;
    _t135 = m->handle;
    bux_mutex_lock(_t135);
}

void Mutex_Unlock(Mutex* m) {
    void* _t136;
    _t136 = m->handle;
    bux_mutex_unlock(_t136);
}

void Mutex_Free(Mutex* m) {
    void* _t137;
    _t137 = m->handle;
    bux_mutex_free(_t137);
}

RwLock RwLock_New(void) {
    RwLock _t139;
    void* _t138;
    _t138 = bux_rwlock_new();
    _t139 = (RwLock){.handle = _t138};
    return _t139;
}

void RwLock_ReadLock(RwLock* rw) {
    void* _t140;
    _t140 = rw->handle;
    bux_rwlock_rdlock(_t140);
}

void RwLock_WriteLock(RwLock* rw) {
    void* _t141;
    _t141 = rw->handle;
    bux_rwlock_wrlock(_t141);
}

void RwLock_Unlock(RwLock* rw) {
    void* _t142;
    _t142 = rw->handle;
    bux_rwlock_unlock(_t142);
}

void RwLock_Free(RwLock* rw) {
    void* _t143;
    _t143 = rw->handle;
    bux_rwlock_free(_t143);
}

void Test_Exit(int code) {
    bux_exit(code);
}

void Test_Assert(bool cond) {
    int _t144;
    _t144 = (int)cond;
    bux_assert(_t144, "", 0, "");
}

void Test_AssertEqInt(int a, int b) {
    int _t145;
    _t145 = (a != b);
    if (!_t145) goto endif20;
    {
    PrintLine("ASSERT_EQ FAILED:");
    PrintInt(a);
    PrintLine(" != ");
    PrintInt(b);
    bux_exit(1);
    }
    endif20:;
}

void Test_AssertTrue(bool cond) {
    int _t146;
    _t146 = !cond;
    if (!_t146) goto endif22;
    {
    PrintLine("ASSERT_TRUE FAILED");
    bux_exit(1);
    }
    endif22:;
}

void Test_AssertFalse(bool cond) {
    if (!cond) goto endif24;
    {
    PrintLine("ASSERT_FALSE FAILED");
    bux_exit(1);
    }
    endif24:;
}

void Test_Fail(const char* msg) {
    PrintLine("FAIL:");
    PrintLine(msg);
    bux_exit(1);
}

Result Result_NewOk(int value) {
    Result _t147;
    Result r;
    _t147 = (Result){.tag = Result_Ok};
    r = _t147;
    r.data.Ok_0 = value;
    return r;
}

Result Result_NewErr(const char* msg) {
    Result _t148;
    Result r;
    _t148 = (Result){.tag = Result_Err};
    r = _t148;
    r.data.Err_0 = msg;
    return r;
}

bool Result_IsOk(Result r) {
    int _t150;
    Result_Tag _t149;
    _t149 = r.tag;
    _t150 = (_t149 == Result_Ok);
    return _t150;
}

bool Result_IsErr(Result r) {
    int _t152;
    Result_Tag _t151;
    _t151 = r.tag;
    _t152 = (_t151 == Result_Err);
    return _t152;
}

int Result_Unwrap(Result r) {
    int _t154;
    Result_Tag _t153;
    _t153 = r.tag;
    _t154 = (_t153 != Result_Ok);
    if (!_t154) goto endif26;
    {
    PrintLine("panic: unwrap on Err");
    return 0;
    }
    endif26:;
    Result_Data _t155;
    _t155 = r.data;
    int _t156;
    _t156 = _t155.Ok_0;
    return _t156;
}

int Result_UnwrapOr(Result r, int fallback) {
    int _t158;
    Result_Tag _t157;
    _t157 = r.tag;
    _t158 = (_t157 == Result_Ok);
    if (!_t158) goto endif28;
    {
    Result_Data _t159;
    _t159 = r.data;
    int _t160;
    _t160 = _t159.Ok_0;
    return _t160;
    }
    endif28:;
    return fallback;
}

Option Option_NewSome(int value) {
    Option _t161;
    Option o;
    _t161 = (Option){.tag = Option_Some};
    o = _t161;
    o.data.Some_0 = value;
    return o;
}

Option Option_NewNone(void) {
    Option _t162;
    _t162 = (Option){.tag = Option_None};
    return _t162;
}

bool Option_IsSome(Option o) {
    int _t164;
    Option_Tag _t163;
    _t163 = o.tag;
    _t164 = (_t163 == Option_Some);
    return _t164;
}

bool Option_IsNone(Option o) {
    int _t166;
    Option_Tag _t165;
    _t165 = o.tag;
    _t166 = (_t165 == Option_None);
    return _t166;
}

int Option_Unwrap(Option o) {
    int _t168;
    Option_Tag _t167;
    _t167 = o.tag;
    _t168 = (_t167 != Option_Some);
    if (!_t168) goto endif30;
    {
    PrintLine("panic: unwrap on None");
    return 0;
    }
    endif30:;
    Option_Data _t169;
    _t169 = o.data;
    int _t170;
    _t170 = _t169.Some_0;
    return _t170;
}

int Option_UnwrapOr(Option o, int fallback) {
    int _t172;
    Option_Tag _t171;
    _t171 = o.tag;
    _t172 = (_t171 == Option_Some);
    if (!_t172) goto endif32;
    {
    Option_Data _t173;
    _t173 = o.data;
    int _t174;
    _t174 = _t173.Some_0;
    return _t174;
    }
    endif32:;
    return fallback;
}

JsonValue Json_Null(void) {
    JsonValue _t175;
    _t175 = (JsonValue){.tag = JsonTagNull, .boolVal = 0, .numVal = 0.0, .strVal = "", .arrData = 0, .arrLen = 0, .arrCap = 0, .objKeys = 0, .objValues = 0, .objLen = 0, .objCap = 0};
    return _t175;
}

JsonValue Json_Bool(bool b) {
    JsonValue _t176;
    _t176 = (JsonValue){.tag = JsonTagBool, .boolVal = b, .numVal = 0.0, .strVal = "", .arrData = 0, .arrLen = 0, .arrCap = 0, .objKeys = 0, .objValues = 0, .objLen = 0, .objCap = 0};
    return _t176;
}

JsonValue Json_Number(double n) {
    JsonValue _t177;
    _t177 = (JsonValue){.tag = JsonTagNumber, .boolVal = 0, .numVal = n, .strVal = "", .arrData = 0, .arrLen = 0, .arrCap = 0, .objKeys = 0, .objValues = 0, .objLen = 0, .objCap = 0};
    return _t177;
}

JsonValue Json_String(const char* s) {
    JsonValue _t178;
    _t178 = (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 _t178;
}

JsonValue Json_Array(void) {
    JsonValue _t179;
    _t179 = (JsonValue){.tag = JsonTagArray, .boolVal = 0, .numVal = 0.0, .strVal = "", .arrData = 0, .arrLen = 0, .arrCap = 0, .objKeys = 0, .objValues = 0, .objLen = 0, .objCap = 0};
    return _t179;
}

JsonValue Json_Object(void) {
    JsonValue _t180;
    _t180 = (JsonValue){.tag = JsonTagObject, .boolVal = 0, .numVal = 0.0, .strVal = "", .arrData = 0, .arrLen = 0, .arrCap = 0, .objKeys = 0, .objValues = 0, .objLen = 0, .objCap = 0};
    return _t180;
}

unsigned int Json_ArrayLen(JsonValue v) {
    int _t182;
    int _t181;
    _t181 = v.tag;
    _t182 = (_t181 != JsonTagArray);
    if (!_t182) goto endif34;
    {
    return 0;
    }
    endif34:;
    unsigned int _t183;
    _t183 = v.arrLen;
    return _t183;
}

JsonValue Json_ArrayGet(JsonValue v, unsigned int index) {
    int _t185;
    int _t188;
    int _t184;
    _t184 = v.tag;
    _t185 = (_t184 != JsonTagArray);
    if (!_t185) goto endif36;
    {
    JsonValue _t186;
    _t186 = Json_Null();
    return _t186;
    }
    endif36:;
    unsigned int _t187;
    _t187 = v.arrLen;
    _t188 = (index >= _t187);
    if (!_t188) goto endif38;
    {
    JsonValue _t189;
    _t189 = Json_Null();
    return _t189;
    }
    endif38:;
    JsonValue* _t190;
    _t190 = v.arrData;
    JsonValue _t191;
    _t191 = _t190[index];
    return _t191;
}

void Json_ArrayPush(JsonValue* self, JsonValue val) {
    int _t193;
    int _t196;
    int _t198;
    int _t199;
    JsonValue* _t201;
    int _t202;
    void* _t204;
    int _t205;
    JsonValue* _t207;
    int _t211;
    int _t192;
    _t192 = self->tag;
    _t193 = (_t192 != JsonTagArray);
    if (!_t193) goto endif40;
    {
    return;
    }
    endif40:;
    unsigned int _t194;
    _t194 = self->arrLen;
    unsigned int _t195;
    _t195 = self->arrCap;
    _t196 = (_t194 >= _t195);
    if (!_t196) goto endif42;
    {
    unsigned int arrNewCap;
    unsigned int _t197;
    _t197 = self->arrCap;
    arrNewCap = _t197;
    _t198 = (arrNewCap == 0);
    if (!_t198) goto else43;
    {
    self->arrCap = 4;
    /* sizeof(JsonValue) */
    _t199 = 4 * sizeof(JsonValue);
    void* _t200;
    _t200 = Alloc(_t199);
    _t201 = (JsonValue*)_t200;
    self->arrData = _t201;
    }
    goto endif44;
    else43:;
    {
    unsigned int doubleCap;
    _t202 = arrNewCap * 2;
    doubleCap = _t202;
    self->arrCap = doubleCap;
    JsonValue* _t203;
    _t203 = self->arrData;
    _t204 = (void*)_t203;
    /* sizeof(JsonValue) */
    _t205 = doubleCap * sizeof(JsonValue);
    void* _t206;
    _t206 = Realloc(_t204, _t205);
    _t207 = (JsonValue*)_t206;
    self->arrData = _t207;
    }
    endif44:;
    }
    endif42:;
    JsonValue* _t208;
    _t208 = self->arrData;
    unsigned int _t209;
    _t209 = self->arrLen;
    _t208[_t209] = val;
    unsigned int _t210;
    _t210 = self->arrLen;
    _t211 = _t210 + 1;
    self->arrLen = _t211;
}

unsigned int Json_ObjectLen(JsonValue v) {
    int _t213;
    int _t212;
    _t212 = v.tag;
    _t213 = (_t212 != JsonTagObject);
    if (!_t213) goto endif46;
    {
    return 0;
    }
    endif46:;
    unsigned int _t214;
    _t214 = v.objLen;
    return _t214;
}

JsonValue Json_ObjectGet(JsonValue v, const char* key) {
    int _t216;
    int _t219;
    int _t225;
    int _t215;
    _t215 = v.tag;
    _t216 = (_t215 != JsonTagObject);
    if (!_t216) goto endif48;
    {
    JsonValue _t217;
    _t217 = Json_Null();
    return _t217;
    }
    endif48:;
    unsigned int i;
    i = 0;
    while49:;
    unsigned int _t218;
    _t218 = v.objLen;
    _t219 = (i < _t218);
    if (!_t219) goto wend50;
    {
    const char** _t220;
    _t220 = v.objKeys;
    const char* _t221;
    _t221 = _t220[i];
    bool _t222;
    _t222 = String_Eq(_t221, key);
    if (!_t222) goto endif52;
    {
    JsonValue* _t223;
    _t223 = v.objValues;
    JsonValue _t224;
    _t224 = _t223[i];
    return _t224;
    }
    endif52:;
    _t225 = i + 1;
    i = _t225;
    }
    goto while49;
    wend50:;
    JsonValue _t226;
    _t226 = Json_Null();
    return _t226;
}

bool Json_ObjectHas(JsonValue v, const char* key) {
    int _t228;
    int _t230;
    int _t234;
    int _t227;
    _t227 = v.tag;
    _t228 = (_t227 != JsonTagObject);
    if (!_t228) goto endif54;
    {
    return 0;
    }
    endif54:;
    unsigned int i;
    i = 0;
    while55:;
    unsigned int _t229;
    _t229 = v.objLen;
    _t230 = (i < _t229);
    if (!_t230) goto wend56;
    {
    const char** _t231;
    _t231 = v.objKeys;
    const char* _t232;
    _t232 = _t231[i];
    bool _t233;
    _t233 = String_Eq(_t232, key);
    if (!_t233) goto endif58;
    {
    return 1;
    }
    endif58:;
    _t234 = i + 1;
    i = _t234;
    }
    goto while55;
    wend56:;
    return 0;
}

void Json_ObjectSet(JsonValue* self, const char* key, JsonValue val) {
    int _t236;
    int _t238;
    int _t243;
    int _t246;
    int _t248;
    int _t249;
    const char** _t251;
    int _t252;
    JsonValue* _t254;
    int _t255;
    void* _t257;
    int _t258;
    const char** _t260;
    void* _t262;
    int _t263;
    JsonValue* _t265;
    int _t271;
    int _t235;
    _t235 = self->tag;
    _t236 = (_t235 != JsonTagObject);
    if (!_t236) goto endif60;
    {
    return;
    }
    endif60:;
    unsigned int i;
    i = 0;
    while61:;
    unsigned int _t237;
    _t237 = self->objLen;
    _t238 = (i < _t237);
    if (!_t238) goto wend62;
    {
    const char** _t239;
    _t239 = self->objKeys;
    const char* _t240;
    _t240 = _t239[i];
    bool _t241;
    _t241 = String_Eq(_t240, key);
    if (!_t241) goto endif64;
    {
    JsonValue* _t242;
    _t242 = self->objValues;
    _t242[i] = val;
    return;
    }
    endif64:;
    _t243 = i + 1;
    i = _t243;
    }
    goto while61;
    wend62:;
    unsigned int _t244;
    _t244 = self->objLen;
    unsigned int _t245;
    _t245 = self->objCap;
    _t246 = (_t244 >= _t245);
    if (!_t246) goto endif66;
    {
    unsigned int objNewCap;
    unsigned int _t247;
    _t247 = self->objCap;
    objNewCap = _t247;
    _t248 = (objNewCap == 0);
    if (!_t248) goto else67;
    {
    self->objCap = 4;
    /* sizeof(const char*) */
    _t249 = 4 * sizeof(const char*);
    void* _t250;
    _t250 = Alloc(_t249);
    _t251 = (const char**)_t250;
    self->objKeys = _t251;
    /* sizeof(JsonValue) */
    _t252 = 4 * sizeof(JsonValue);
    void* _t253;
    _t253 = Alloc(_t252);
    _t254 = (JsonValue*)_t253;
    self->objValues = _t254;
    }
    goto endif68;
    else67:;
    {
    unsigned int doubleCap;
    _t255 = objNewCap * 2;
    doubleCap = _t255;
    self->objCap = doubleCap;
    const char** _t256;
    _t256 = self->objKeys;
    _t257 = (void*)_t256;
    /* sizeof(const char*) */
    _t258 = doubleCap * sizeof(const char*);
    void* _t259;
    _t259 = Realloc(_t257, _t258);
    _t260 = (const char**)_t259;
    self->objKeys = _t260;
    JsonValue* _t261;
    _t261 = self->objValues;
    _t262 = (void*)_t261;
    /* sizeof(JsonValue) */
    _t263 = doubleCap * sizeof(JsonValue);
    void* _t264;
    _t264 = Realloc(_t262, _t263);
    _t265 = (JsonValue*)_t264;
    self->objValues = _t265;
    }
    endif68:;
    }
    endif66:;
    const char** _t266;
    _t266 = self->objKeys;
    unsigned int _t267;
    _t267 = self->objLen;
    _t266[_t267] = key;
    JsonValue* _t268;
    _t268 = self->objValues;
    unsigned int _t269;
    _t269 = self->objLen;
    _t268[_t269] = val;
    unsigned int _t270;
    _t270 = self->objLen;
    _t271 = _t270 + 1;
    self->objLen = _t271;
}

bool Json_IsNull(JsonValue v) {
    int _t273;
    int _t272;
    _t272 = v.tag;
    _t273 = (_t272 == JsonTagNull);
    return _t273;
}

bool Json_AsBool(JsonValue v) {
    int _t275;
    int _t274;
    _t274 = v.tag;
    _t275 = (_t274 == JsonTagBool);
    if (!_t275) goto endif70;
    {
    bool _t276;
    _t276 = v.boolVal;
    return _t276;
    }
    endif70:;
    return 0;
}

double Json_AsNumber(JsonValue v) {
    int _t278;
    int _t277;
    _t277 = v.tag;
    _t278 = (_t277 == JsonTagNumber);
    if (!_t278) goto endif72;
    {
    double _t279;
    _t279 = v.numVal;
    return _t279;
    }
    endif72:;
    return 0.0;
}

const char* Json_AsString(JsonValue v) {
    int _t281;
    int _t280;
    _t280 = v.tag;
    _t281 = (_t280 == JsonTagString);
    if (!_t281) goto endif74;
    {
    const char* _t282;
    _t282 = v.strVal;
    return _t282;
    }
    endif74:;
    return "";
}

int JsonParser_Peek(JsonParser* p) {
    int _t285;
    int _t289;
    unsigned int _t283;
    _t283 = p->pos;
    unsigned int _t284;
    _t284 = p->len;
    _t285 = (_t283 >= _t284);
    if (!_t285) goto endif76;
    {
    return 0;
    }
    endif76:;
    const char* _t286;
    _t286 = p->src;
    unsigned int _t287;
    _t287 = p->pos;
    int _t288;
    _t288 = _t286[_t287];
    _t289 = (int)_t288;
    return _t289;
}

void JsonParser_Advance(JsonParser* p) {
    int _t292;
    int _t294;
    unsigned int _t290;
    _t290 = p->pos;
    unsigned int _t291;
    _t291 = p->len;
    _t292 = (_t290 < _t291);
    if (!_t292) goto endif78;
    {
    unsigned int _t293;
    _t293 = p->pos;
    _t294 = _t293 + 1;
    p->pos = _t294;
    }
    endif78:;
}

void JsonParser_SkipWhitespace(JsonParser* p) {
    int _t296;
    int _t297;
    int _t299;
    int _t301;
    while79:;
    if (!1) goto wend80;
    {
    int c;
    int _t295;
    _t295 = JsonParser_Peek(p);
    c = _t295;
    bool __or_tmp_1;
    bool __or_tmp_2;
    bool __or_tmp_3;
    _t296 = (c == 32);
    if (!_t296) goto else81;
    *(bool*)&__or_tmp_3 = 1;
    goto endif82;
    else81:;
    _t297 = (c == 9);
    *(bool*)&__or_tmp_3 = _t297;
    endif82:;
    bool _t298;
    _t298 = *(bool*)&__or_tmp_3;
    if (!_t298) goto else83;
    *(bool*)&__or_tmp_2 = 1;
    goto endif84;
    else83:;
    _t299 = (c == 10);
    *(bool*)&__or_tmp_2 = _t299;
    endif84:;
    bool _t300;
    _t300 = *(bool*)&__or_tmp_2;
    if (!_t300) goto else85;
    *(bool*)&__or_tmp_1 = 1;
    goto endif86;
    else85:;
    _t301 = (c == 13);
    *(bool*)&__or_tmp_1 = _t301;
    endif86:;
    bool _t302;
    _t302 = *(bool*)&__or_tmp_1;
    if (!_t302) goto else87;
    {
    JsonParser_Advance(p);
    }
    goto endif88;
    else87:;
    {
    return;
    }
    endif88:;
    }
    goto while79;
    wend80:;
}

bool JsonParser_Match(JsonParser* p, const char* expected) {
    int _t305;
    int _t307;
    int _t308;
    int _t311;
    int _t314;
    int _t315;
    int _t317;
    unsigned int elen;
    unsigned int _t303;
    _t303 = String_Len(expected);
    elen = _t303;
    unsigned int _t304;
    _t304 = p->pos;
    _t305 = _t304 + elen;
    unsigned int _t306;
    _t306 = p->len;
    _t307 = (_t305 > _t306);
    if (!_t307) goto endif90;
    {
    return 0;
    }
    endif90:;
    unsigned int i;
    i = 0;
    while91:;
    _t308 = (i < elen);
    if (!_t308) goto wend92;
    {
    const char* _t309;
    _t309 = p->src;
    unsigned int _t310;
    _t310 = p->pos;
    _t311 = _t310 + i;
    int _t312;
    _t312 = _t309[_t311];
    int _t313;
    _t313 = expected[i];
    _t314 = (_t312 != _t313);
    if (!_t314) goto endif94;
    {
    return 0;
    }
    endif94:;
    _t315 = i + 1;
    i = _t315;
    }
    goto while91;
    wend92:;
    unsigned int _t316;
    _t316 = p->pos;
    _t317 = _t316 + elen;
    p->pos = _t317;
    return 1;
}

const char* JsonParser_ParseString(JsonParser* p) {
    int _t319;
    int _t322;
    int _t323;
    int _t325;
    int _t327;
    void* _t328;
    int _t329;
    void* _t330;
    char _t331;
    int _t332;
    void* _t333;
    char _t334;
    int _t335;
    void* _t336;
    char _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;
    void* _t350;
    char _t351;
    void* _t352;
    char _t353;
    void* _t354;
    char _t355;
    int _t357;
    void* _t358;
    void* _t359;
    void* _t361;
    int _t318;
    _t318 = JsonParser_Peek(p);
    _t319 = (_t318 != 34);
    if (!_t319) goto endif96;
    {
    p->error = "Expected string";
    return "";
    }
    endif96:;
    JsonParser_Advance(p);
    StringBuilder sb;
    StringBuilder _t320;
    _t320 = StringBuilder_New();
    sb = _t320;
    while97:;
    if (!1) goto wend98;
    {
    int c;
    int _t321;
    _t321 = JsonParser_Peek(p);
    c = _t321;
    bool __or_tmp_4;
    _t322 = (c == 0);
    if (!_t322) goto else99;
    *(bool*)&__or_tmp_4 = 1;
    goto endif100;
    else99:;
    _t323 = (c == 34);
    *(bool*)&__or_tmp_4 = _t323;
    endif100:;
    bool _t324;
    _t324 = *(bool*)&__or_tmp_4;
    if (!_t324) goto endif102;
    {
    goto wend98;
    }
    endif102:;
    _t325 = (c == 92);
    if (!_t325) goto else103;
    {
    JsonParser_Advance(p);
    int esc;
    int _t326;
    _t326 = JsonParser_Peek(p);
    esc = _t326;
    _t327 = (esc == 0);
    if (!_t327) goto endif106;
    {
    p->error = "Unterminated string escape";
    _t328 = &sb;
    StringBuilder_Free(_t328);
    return "";
    }
    endif106:;
    _t329 = (esc == 110);
    if (!_t329) goto else107;
    {
    _t330 = &sb;
    _t331 = (char)10;
    StringBuilder_AppendChar(_t330, _t331);
    }
    goto endif108;
    else107:;
    _t332 = (esc == 116);
    if (!_t332) goto else109;
    {
    _t333 = &sb;
    _t334 = (char)9;
    StringBuilder_AppendChar(_t333, _t334);
    }
    goto endif110;
    else109:;
    _t335 = (esc == 114);
    if (!_t335) goto else111;
    {
    _t336 = &sb;
    _t337 = (char)13;
    StringBuilder_AppendChar(_t336, _t337);
    }
    goto endif112;
    else111:;
    _t338 = (esc == 98);
    if (!_t338) goto else113;
    {
    _t339 = &sb;
    _t340 = (char)8;
    StringBuilder_AppendChar(_t339, _t340);
    }
    goto endif114;
    else113:;
    _t341 = (esc == 102);
    if (!_t341) goto else115;
    {
    _t342 = &sb;
    _t343 = (char)12;
    StringBuilder_AppendChar(_t342, _t343);
    }
    goto endif116;
    else115:;
    _t344 = (esc == 34);
    if (!_t344) goto else117;
    {
    _t345 = &sb;
    _t346 = (char)34;
    StringBuilder_AppendChar(_t345, _t346);
    }
    goto endif118;
    else117:;
    _t347 = (esc == 92);
    if (!_t347) goto else119;
    {
    _t348 = &sb;
    _t349 = (char)92;
    StringBuilder_AppendChar(_t348, _t349);
    }
    goto endif120;
    else119:;
    {
    _t350 = &sb;
    _t351 = (char)92;
    StringBuilder_AppendChar(_t350, _t351);
    _t352 = &sb;
    _t353 = (char)esc;
    StringBuilder_AppendChar(_t352, _t353);
    }
    endif120:;
    endif118:;
    endif116:;
    endif114:;
    endif112:;
    endif110:;
    endif108:;
    JsonParser_Advance(p);
    }
    goto endif104;
    else103:;
    {
    _t354 = &sb;
    _t355 = (char)c;
    StringBuilder_AppendChar(_t354, _t355);
    JsonParser_Advance(p);
    }
    endif104:;
    }
    goto while97;
    wend98:;
    int _t356;
    _t356 = JsonParser_Peek(p);
    _t357 = (_t356 != 34);
    if (!_t357) goto endif122;
    {
    p->error = "Unterminated string";
    _t358 = &sb;
    StringBuilder_Free(_t358);
    return "";
    }
    endif122:;
    JsonParser_Advance(p);
    const char* result;
    _t359 = &sb;
    const char* _t360;
    _t360 = StringBuilder_Build(_t359);
    result = _t360;
    _t361 = &sb;
    StringBuilder_Free(_t361);
    return result;
}

JsonValue JsonParser_ParseNumber(JsonParser* p) {
    int _t364;
    int _t366;
    int _t367;
    int _t370;
    int _t372;
    int _t373;
    int _t377;
    unsigned int start;
    unsigned int _t362;
    _t362 = p->pos;
    start = _t362;
    int c0;
    int _t363;
    _t363 = JsonParser_Peek(p);
    c0 = _t363;
    _t364 = (c0 == 45);
    if (!_t364) goto endif124;
    {
    JsonParser_Advance(p);
    }
    endif124:;
    while125:;
    if (!1) goto wend126;
    {
    int c;
    int _t365;
    _t365 = JsonParser_Peek(p);
    c = _t365;
    bool __and_tmp_5;
    _t366 = (c >= 48);
    if (!_t366) goto else127;
    _t367 = (c <= 57);
    *(bool*)&__and_tmp_5 = _t367;
    goto endif128;
    else127:;
    *(bool*)&__and_tmp_5 = 0;
    endif128:;
    bool _t368;
    _t368 = *(bool*)&__and_tmp_5;
    if (!_t368) goto else129;
    {
    JsonParser_Advance(p);
    }
    goto endif130;
    else129:;
    {
    goto wend126;
    }
    endif130:;
    }
    goto while125;
    wend126:;
    int _t369;
    _t369 = JsonParser_Peek(p);
    _t370 = (_t369 == 46);
    if (!_t370) goto endif132;
    {
    JsonParser_Advance(p);
    while133:;
    if (!1) goto wend134;
    {
    int c;
    int _t371;
    _t371 = JsonParser_Peek(p);
    c = _t371;
    bool __and_tmp_6;
    _t372 = (c >= 48);
    if (!_t372) goto else135;
    _t373 = (c <= 57);
    *(bool*)&__and_tmp_6 = _t373;
    goto endif136;
    else135:;
    *(bool*)&__and_tmp_6 = 0;
    endif136:;
    bool _t374;
    _t374 = *(bool*)&__and_tmp_6;
    if (!_t374) goto else137;
    {
    JsonParser_Advance(p);
    }
    goto endif138;
    else137:;
    {
    goto wend134;
    }
    endif138:;
    }
    goto while133;
    wend134:;
    }
    endif132:;
    const char* numStr;
    const char* _t375;
    _t375 = p->src;
    unsigned int _t376;
    _t376 = p->pos;
    _t377 = _t376 - start;
    const char* _t378;
    _t378 = String_Slice(_t375, start, _t377);
    numStr = _t378;
    double n;
    double _t379;
    _t379 = String_ToFloat(numStr);
    n = _t379;
    JsonValue _t380;
    _t380 = Json_Number(n);
    return _t380;
}

JsonValue JsonParser_ParseArray(JsonParser* p) {
    int _t383;
    int _t386;
    void* _t388;
    int _t390;
    int _t391;
    JsonParser_Advance(p);
    JsonValue arr;
    JsonValue _t381;
    _t381 = Json_Array();
    arr = _t381;
    JsonParser_SkipWhitespace(p);
    int _t382;
    _t382 = JsonParser_Peek(p);
    _t383 = (_t382 == 93);
    if (!_t383) goto endif140;
    {
    JsonParser_Advance(p);
    return arr;
    }
    endif140:;
    while141:;
    if (!1) goto wend142;
    {
    JsonParser_SkipWhitespace(p);
    JsonValue val;
    JsonValue _t384;
    _t384 = JsonParser_ParseValue(p);
    val = _t384;
    const char* _t385;
    _t385 = p->error;
    _t386 = (_t385 != "");
    if (!_t386) goto endif144;
    {
    JsonValue _t387;
    _t387 = Json_Null();
    return _t387;
    }
    endif144:;
    _t388 = &arr;
    Json_ArrayPush(_t388, val);
    JsonParser_SkipWhitespace(p);
    int c;
    int _t389;
    _t389 = JsonParser_Peek(p);
    c = _t389;
    _t390 = (c == 93);
    if (!_t390) goto endif146;
    {
    JsonParser_Advance(p);
    return arr;
    }
    endif146:;
    _t391 = (c == 44);
    if (!_t391) goto else147;
    {
    JsonParser_Advance(p);
    }
    goto endif148;
    else147:;
    {
    p->error = "Expected ',' or ']' in array";
    JsonValue _t392;
    _t392 = Json_Null();
    return _t392;
    }
    endif148:;
    }
    goto while141;
    wend142:;
}

JsonValue JsonParser_ParseObject(JsonParser* p) {
    int _t395;
    int _t398;
    int _t401;
    int _t405;
    void* _t407;
    int _t409;
    int _t410;
    JsonParser_Advance(p);
    JsonValue obj;
    JsonValue _t393;
    _t393 = Json_Object();
    obj = _t393;
    JsonParser_SkipWhitespace(p);
    int _t394;
    _t394 = JsonParser_Peek(p);
    _t395 = (_t394 == 125);
    if (!_t395) goto endif150;
    {
    JsonParser_Advance(p);
    return obj;
    }
    endif150:;
    while151:;
    if (!1) goto wend152;
    {
    JsonParser_SkipWhitespace(p);
    const char* key;
    const char* _t396;
    _t396 = JsonParser_ParseString(p);
    key = _t396;
    const char* _t397;
    _t397 = p->error;
    _t398 = (_t397 != "");
    if (!_t398) goto endif154;
    {
    JsonValue _t399;
    _t399 = Json_Null();
    return _t399;
    }
    endif154:;
    JsonParser_SkipWhitespace(p);
    int _t400;
    _t400 = JsonParser_Peek(p);
    _t401 = (_t400 != 58);
    if (!_t401) goto endif156;
    {
    p->error = "Expected ':' after object key";
    JsonValue _t402;
    _t402 = Json_Null();
    return _t402;
    }
    endif156:;
    JsonParser_Advance(p);
    JsonParser_SkipWhitespace(p);
    JsonValue val;
    JsonValue _t403;
    _t403 = JsonParser_ParseValue(p);
    val = _t403;
    const char* _t404;
    _t404 = p->error;
    _t405 = (_t404 != "");
    if (!_t405) goto endif158;
    {
    JsonValue _t406;
    _t406 = Json_Null();
    return _t406;
    }
    endif158:;
    _t407 = &obj;
    Json_ObjectSet(_t407, key, val);
    JsonParser_SkipWhitespace(p);
    int c;
    int _t408;
    _t408 = JsonParser_Peek(p);
    c = _t408;
    _t409 = (c == 125);
    if (!_t409) goto endif160;
    {
    JsonParser_Advance(p);
    return obj;
    }
    endif160:;
    _t410 = (c == 44);
    if (!_t410) goto else161;
    {
    JsonParser_Advance(p);
    }
    goto endif162;
    else161:;
    {
    p->error = "Expected ',' or '}' in object";
    JsonValue _t411;
    _t411 = Json_Null();
    return _t411;
    }
    endif162:;
    }
    goto while151;
    wend152:;
}

JsonValue JsonParser_ParseValue(JsonParser* p) {
    int _t413;
    int _t415;
    int _t418;
    int _t420;
    int _t422;
    int _t426;
    int _t430;
    int _t434;
    int _t435;
    int _t437;
    JsonParser_SkipWhitespace(p);
    int c;
    int _t412;
    _t412 = JsonParser_Peek(p);
    c = _t412;
    _t413 = (c == 0);
    if (!_t413) goto endif164;
    {
    p->error = "Unexpected end of input";
    JsonValue _t414;
    _t414 = Json_Null();
    return _t414;
    }
    endif164:;
    _t415 = (c == 34);
    if (!_t415) goto endif166;
    {
    const char* _t416;
    _t416 = JsonParser_ParseString(p);
    JsonValue _t417;
    _t417 = Json_String(_t416);
    return _t417;
    }
    endif166:;
    _t418 = (c == 123);
    if (!_t418) goto endif168;
    {
    JsonValue _t419;
    _t419 = JsonParser_ParseObject(p);
    return _t419;
    }
    endif168:;
    _t420 = (c == 91);
    if (!_t420) goto endif170;
    {
    JsonValue _t421;
    _t421 = JsonParser_ParseArray(p);
    return _t421;
    }
    endif170:;
    _t422 = (c == 116);
    if (!_t422) goto endif172;
    {
    bool _t423;
    _t423 = JsonParser_Match(p, "true");
    if (!_t423) goto endif174;
    {
    JsonValue _t424;
    _t424 = Json_Bool(1);
    return _t424;
    }
    endif174:;
    p->error = "Expected 'true'";
    JsonValue _t425;
    _t425 = Json_Null();
    return _t425;
    }
    endif172:;
    _t426 = (c == 102);
    if (!_t426) goto endif176;
    {
    bool _t427;
    _t427 = JsonParser_Match(p, "false");
    if (!_t427) goto endif178;
    {
    JsonValue _t428;
    _t428 = Json_Bool(0);
    return _t428;
    }
    endif178:;
    p->error = "Expected 'false'";
    JsonValue _t429;
    _t429 = Json_Null();
    return _t429;
    }
    endif176:;
    _t430 = (c == 110);
    if (!_t430) goto endif180;
    {
    bool _t431;
    _t431 = JsonParser_Match(p, "null");
    if (!_t431) goto endif182;
    {
    JsonValue _t432;
    _t432 = Json_Null();
    return _t432;
    }
    endif182:;
    p->error = "Expected 'null'";
    JsonValue _t433;
    _t433 = Json_Null();
    return _t433;
    }
    endif180:;
    bool __or_tmp_7;
    bool __and_tmp_8;
    _t434 = (c >= 48);
    if (!_t434) goto else183;
    _t435 = (c <= 57);
    *(bool*)&__and_tmp_8 = _t435;
    goto endif184;
    else183:;
    *(bool*)&__and_tmp_8 = 0;
    endif184:;
    bool _t436;
    _t436 = *(bool*)&__and_tmp_8;
    if (!_t436) goto else185;
    *(bool*)&__or_tmp_7 = 1;
    goto endif186;
    else185:;
    _t437 = (c == 45);
    *(bool*)&__or_tmp_7 = _t437;
    endif186:;
    bool _t438;
    _t438 = *(bool*)&__or_tmp_7;
    if (!_t438) goto endif188;
    {
    JsonValue _t439;
    _t439 = JsonParser_ParseNumber(p);
    return _t439;
    }
    endif188:;
    p->error = "Unexpected character";
    JsonValue _t440;
    _t440 = Json_Null();
    return _t440;
}

JsonValue Json_Parse(const char* s) {
    JsonParser _t442;
    void* _t443;
    void* _t445;
    int _t447;
    int _t450;
    JsonParser p;
    unsigned int _t441;
    _t441 = String_Len(s);
    _t442 = (JsonParser){.src = s, .pos = 0, .len = _t441, .error = ""};
    p = _t442;
    JsonValue result;
    _t443 = &p;
    JsonValue _t444;
    _t444 = JsonParser_ParseValue(_t443);
    result = _t444;
    _t445 = &p;
    JsonParser_SkipWhitespace(_t445);
    bool __and_tmp_9;
    const char* _t446;
    _t446 = p.error;
    _t447 = (_t446 == "");
    if (!_t447) goto else189;
    unsigned int _t448;
    _t448 = p.pos;
    unsigned int _t449;
    _t449 = p.len;
    _t450 = (_t448 != _t449);
    *(bool*)&__and_tmp_9 = _t450;
    goto endif190;
    else189:;
    *(bool*)&__and_tmp_9 = 0;
    endif190:;
    bool _t451;
    _t451 = *(bool*)&__and_tmp_9;
    if (!_t451) goto endif192;
    {
    p.error = "Trailing data after JSON value";
    JsonValue _t452;
    _t452 = Json_Null();
    return _t452;
    }
    endif192:;
    return result;
}

void Json_StringifyImpl(StringBuilder* sb, JsonValue v) {
    int _t454;
    int _t456;
    int _t459;
    int _t462;
    char _t463;
    char _t465;
    int _t467;
    char _t468;
    int _t470;
    int _t471;
    char _t472;
    int _t475;
    char _t476;
    int _t478;
    char _t479;
    int _t481;
    int _t482;
    char _t483;
    char _t484;
    char _t487;
    char _t488;
    int _t491;
    char _t492;
    int _t453;
    _t453 = v.tag;
    _t454 = (_t453 == JsonTagNull);
    if (!_t454) goto endif194;
    {
    StringBuilder_Append(sb, "null");
    return;
    }
    endif194:;
    int _t455;
    _t455 = v.tag;
    _t456 = (_t455 == JsonTagBool);
    if (!_t456) goto endif196;
    {
    bool _t457;
    _t457 = v.boolVal;
    if (!_t457) goto else197;
    {
    StringBuilder_Append(sb, "true");
    }
    goto endif198;
    else197:;
    {
    StringBuilder_Append(sb, "false");
    }
    endif198:;
    return;
    }
    endif196:;
    int _t458;
    _t458 = v.tag;
    _t459 = (_t458 == JsonTagNumber);
    if (!_t459) goto endif200;
    {
    double _t460;
    _t460 = v.numVal;
    StringBuilder_AppendFloat(sb, _t460);
    return;
    }
    endif200:;
    int _t461;
    _t461 = v.tag;
    _t462 = (_t461 == JsonTagString);
    if (!_t462) goto endif202;
    {
    _t463 = (char)34;
    StringBuilder_AppendChar(sb, _t463);
    const char* _t464;
    _t464 = v.strVal;
    StringBuilder_Append(sb, _t464);
    _t465 = (char)34;
    StringBuilder_AppendChar(sb, _t465);
    return;
    }
    endif202:;
    int _t466;
    _t466 = v.tag;
    _t467 = (_t466 == JsonTagArray);
    if (!_t467) goto endif204;
    {
    _t468 = (char)91;
    StringBuilder_AppendChar(sb, _t468);
    unsigned int i;
    i = 0;
    while205:;
    unsigned int _t469;
    _t469 = v.arrLen;
    _t470 = (i < _t469);
    if (!_t470) goto wend206;
    {
    _t471 = (i > 0);
    if (!_t471) goto endif208;
    {
    _t472 = (char)44;
    StringBuilder_AppendChar(sb, _t472);
    }
    endif208:;
    JsonValue* _t473;
    _t473 = v.arrData;
    JsonValue _t474;
    _t474 = _t473[i];
    Json_StringifyImpl(sb, _t474);
    _t475 = i + 1;
    i = _t475;
    }
    goto while205;
    wend206:;
    _t476 = (char)93;
    StringBuilder_AppendChar(sb, _t476);
    return;
    }
    endif204:;
    int _t477;
    _t477 = v.tag;
    _t478 = (_t477 == JsonTagObject);
    if (!_t478) goto endif210;
    {
    _t479 = (char)123;
    StringBuilder_AppendChar(sb, _t479);
    unsigned int i;
    i = 0;
    while211:;
    unsigned int _t480;
    _t480 = v.objLen;
    _t481 = (i < _t480);
    if (!_t481) goto wend212;
    {
    _t482 = (i > 0);
    if (!_t482) goto endif214;
    {
    _t483 = (char)44;
    StringBuilder_AppendChar(sb, _t483);
    }
    endif214:;
    _t484 = (char)34;
    StringBuilder_AppendChar(sb, _t484);
    const char** _t485;
    _t485 = v.objKeys;
    const char* _t486;
    _t486 = _t485[i];
    StringBuilder_Append(sb, _t486);
    _t487 = (char)34;
    StringBuilder_AppendChar(sb, _t487);
    _t488 = (char)58;
    StringBuilder_AppendChar(sb, _t488);
    JsonValue* _t489;
    _t489 = v.objValues;
    JsonValue _t490;
    _t490 = _t489[i];
    Json_StringifyImpl(sb, _t490);
    _t491 = i + 1;
    i = _t491;
    }
    goto while211;
    wend212:;
    _t492 = (char)125;
    StringBuilder_AppendChar(sb, _t492);
    return;
    }
    endif210:;
}

const char* Json_Stringify(JsonValue v) {
    void* _t494;
    void* _t495;
    StringBuilder sb;
    StringBuilder _t493;
    _t493 = StringBuilder_New();
    sb = _t493;
    _t494 = &sb;
    Json_StringifyImpl(_t494, v);
    _t495 = &sb;
    const char* _t496;
    _t496 = StringBuilder_Build(_t495);
    return _t496;
}

unsigned int String_Len(const char* s) {
    unsigned int _t497;
    _t497 = bux_strlen(s);
    return _t497;
}

bool String_IsNull(const char* s) {
    int _t499;
    int _t498;
    _t498 = bux_str_is_null(s);
    _t499 = (_t498 != 0);
    return _t499;
}

bool String_Eq(const char* a, const char* b) {
    int _t501;
    int _t500;
    _t500 = bux_strcmp(a, b);
    _t501 = (_t500 == 0);
    return _t501;
}

const char* String_Concat(const char* a, const char* b) {
    int _t504;
    int _t505;
    char* _t507;
    unsigned int len_a;
    unsigned int _t502;
    _t502 = bux_strlen(a);
    len_a = _t502;
    unsigned int len_b;
    unsigned int _t503;
    _t503 = bux_strlen(b);
    len_b = _t503;
    unsigned int total;
    _t504 = len_a + len_b;
    _t505 = _t504 + 1;
    total = _t505;
    char* buf;
    void* _t506;
    _t506 = bux_alloc(total);
    _t507 = (char*)_t506;
    buf = _t507;
    bux_strcpy(buf, a);
    bux_strcat(buf, b);
    return buf;
}

const char* String_Copy(const char* s) {
    int _t509;
    char* _t511;
    unsigned int len;
    unsigned int _t508;
    _t508 = bux_strlen(s);
    len = _t508;
    char* buf;
    _t509 = len + 1;
    void* _t510;
    _t510 = bux_alloc(_t509);
    _t511 = (char*)_t510;
    buf = _t511;
    bux_strcpy(buf, s);
    return buf;
}

bool String_StartsWith(const char* s, const char* prefix) {
    int _t514;
    int _t516;
    unsigned int s_len;
    unsigned int _t512;
    _t512 = bux_strlen(s);
    s_len = _t512;
    unsigned int p_len;
    unsigned int _t513;
    _t513 = bux_strlen(prefix);
    p_len = _t513;
    _t514 = (p_len > s_len);
    if (!_t514) goto endif216;
    {
    return 0;
    }
    endif216:;
    int r;
    int _t515;
    _t515 = bux_strncmp(s, prefix, p_len);
    r = _t515;
    _t516 = (r == 0);
    return _t516;
}

bool String_EndsWith(const char* s, const char* suffix) {
    int _t519;
    int _t520;
    int _t523;
    unsigned int s_len;
    unsigned int _t517;
    _t517 = bux_strlen(s);
    s_len = _t517;
    unsigned int suf_len;
    unsigned int _t518;
    _t518 = bux_strlen(suffix);
    suf_len = _t518;
    _t519 = (suf_len > s_len);
    if (!_t519) goto endif218;
    {
    return 0;
    }
    endif218:;
    unsigned int start;
    _t520 = s_len - suf_len;
    start = _t520;
    const char* tail;
    const char* _t521;
    _t521 = bux_str_slice(s, start, suf_len);
    tail = _t521;
    bool eq;
    int _t522;
    _t522 = bux_strcmp(tail, suffix);
    _t523 = (_t522 == 0);
    eq = _t523;
    return eq;
}

bool String_Contains(const char* s, const char* substr) {
    int _t525;
    int r;
    int _t524;
    _t524 = bux_str_contains(s, substr);
    r = _t524;
    _t525 = (r != 0);
    return _t525;
}

const char* String_Slice(const char* s, unsigned int start, unsigned int len) {
    const char* _t526;
    _t526 = bux_str_slice(s, start, len);
    return _t526;
}

const char* String_Trim(const char* s) {
    const char* _t527;
    _t527 = bux_str_trim(s);
    return _t527;
}

const char* String_TrimLeft(const char* s) {
    const char* _t528;
    _t528 = bux_str_trim_left(s);
    return _t528;
}

const char* String_TrimRight(const char* s) {
    const char* _t529;
    _t529 = bux_str_trim_right(s);
    return _t529;
}

const char* String_FromInt(int64_t n) {
    const char* _t530;
    _t530 = bux_int_to_str(n);
    return _t530;
}

int64_t String_ToInt(const char* s) {
    int64_t _t531;
    _t531 = bux_str_to_int(s);
    return _t531;
}

StringBuilder StringBuilder_New(void) {
    StringBuilder _t533;
    void* _t532;
    _t532 = bux_sb_new(64);
    _t533 = (StringBuilder){.handle = _t532};
    return _t533;
}

StringBuilder StringBuilder_NewCap(unsigned int cap) {
    StringBuilder _t535;
    void* _t534;
    _t534 = bux_sb_new(cap);
    _t535 = (StringBuilder){.handle = _t534};
    return _t535;
}

void StringBuilder_Append(StringBuilder* sb, const char* s) {
    void* _t536;
    _t536 = sb->handle;
    bux_sb_append(_t536, s);
}

void StringBuilder_AppendInt(StringBuilder* sb, int64_t n) {
    void* _t537;
    _t537 = sb->handle;
    bux_sb_append_int(_t537, n);
}

void StringBuilder_AppendFloat(StringBuilder* sb, double f) {
    void* _t538;
    _t538 = sb->handle;
    bux_sb_append_float(_t538, f);
}

void StringBuilder_AppendChar(StringBuilder* sb, char c) {
    void* _t539;
    _t539 = sb->handle;
    bux_sb_append_char(_t539, c);
}

const char* StringBuilder_Build(StringBuilder* sb) {
    void* _t540;
    _t540 = sb->handle;
    const char* _t541;
    _t541 = bux_sb_build(_t540);
    return _t541;
}

void StringBuilder_Free(StringBuilder* sb) {
    void* _t542;
    _t542 = sb->handle;
    bux_sb_free(_t542);
}

unsigned int String_SplitCount(const char* s, const char* delim) {
    unsigned int _t543;
    _t543 = bux_str_split_count(s, delim);
    return _t543;
}

const char* String_SplitPart(const char* s, const char* delim, unsigned int index) {
    const char* _t544;
    _t544 = bux_str_split_part(s, delim, index);
    return _t544;
}

const char* String_Join2(const char* a, const char* b, const char* sep) {
    const char* _t545;
    _t545 = bux_str_join2(a, b, sep);
    return _t545;
}

const char* String_Chars(const char* s, unsigned int index) {
    const char* _t546;
    _t546 = bux_str_slice(s, index, 1);
    return _t546;
}

const char* String_Find(const char* haystack, const char* needle) {
    const char* _t547;
    _t547 = bux_strstr(haystack, needle);
    return _t547;
}

unsigned int String_Offset(const char* pos, const char* base) {
    unsigned int _t548;
    _t548 = bux_str_offset(pos, base);
    return _t548;
}

const char* String_Replace(const char* s, const char* old, const char* new) {
    int _t554;
    int _t556;
    int _t557;
    const char* pos;
    const char* _t549;
    _t549 = bux_strstr(s, old);
    pos = _t549;
    bool _t550;
    _t550 = String_IsNull(pos);
    if (!_t550) goto endif220;
    {
    return s;
    }
    endif220:;
    unsigned int oldLen;
    unsigned int _t551;
    _t551 = bux_strlen(old);
    oldLen = _t551;
    unsigned int prefixLen;
    unsigned int _t552;
    _t552 = String_Offset(pos, s);
    prefixLen = _t552;
    const char* prefix;
    const char* _t553;
    _t553 = bux_str_slice(s, 0, prefixLen);
    prefix = _t553;
    const char* suffix;
    _t554 = prefixLen + oldLen;
    unsigned int _t555;
    _t555 = bux_strlen(s);
    _t556 = _t555 - prefixLen;
    _t557 = _t556 - oldLen;
    const char* _t558;
    _t558 = bux_str_slice(s, _t554, _t557);
    suffix = _t558;
    const char* temp;
    const char* _t559;
    _t559 = String_Concat(prefix, new);
    temp = _t559;
    const char* result;
    const char* _t560;
    _t560 = String_Concat(temp, suffix);
    result = _t560;
    return result;
}

double String_ToFloat(const char* s) {
    double _t561;
    _t561 = bux_str_to_float(s);
    return _t561;
}

const char* String_FromBool(bool b) {
    if (!b) goto endif222;
    {
    return "true";
    }
    endif222:;
    return "false";
}

const char* String_FromFloat(double f) {
    const char* _t562;
    _t562 = bux_float_to_string(f);
    return _t562;
}

const char* String_Format1(const char* pattern, const char* a0) {
    const char* _t563;
    _t563 = bux_str_format(pattern, a0, "", "", "", "", "", "", "");
    return _t563;
}

const char* String_Format2(const char* pattern, const char* a0, const char* a1) {
    const char* _t564;
    _t564 = bux_str_format(pattern, a0, a1, "", "", "", "", "", "");
    return _t564;
}

const char* String_Format3(const char* pattern, const char* a0, const char* a1, const char* a2) {
    const char* _t565;
    _t565 = bux_str_format(pattern, a0, a1, a2, "", "", "", "", "");
    return _t565;
}

void Channel_SendInt(Channel_int* ch, int value) {
    void* _t567;
    void* _t568;
    void* _t566;
    _t566 = ch->handle;
    _t567 = &value;
    _t568 = (void*)_t567;
    bux_channel_send(_t566, _t568);
}

int Channel_RecvInt(Channel_int* ch) {
    void* _t570;
    void* _t571;
    int result;
    result = 0;
    void* _t569;
    _t569 = ch->handle;
    _t570 = &result;
    _t571 = (void*)_t570;
    bux_channel_recv(_t569, _t571);
    return result;
}

void Channel_SendFloat64(Channel_float64* ch, double value) {
    void* _t573;
    void* _t574;
    void* _t572;
    _t572 = ch->handle;
    _t573 = &value;
    _t574 = (void*)_t573;
    bux_channel_send(_t572, _t574);
}

double Channel_RecvFloat64(Channel_float64* ch) {
    void* _t576;
    void* _t577;
    double result;
    result = 0.0;
    void* _t575;
    _t575 = ch->handle;
    _t576 = &result;
    _t577 = (void*)_t576;
    bux_channel_recv(_t575, _t577);
    return result;
}

const char* Hash_Sha1(const char* data) {
    int _t579;
    int len;
    unsigned int _t578;
    _t578 = String_Len(data);
    _t579 = (int)_t578;
    len = _t579;
    void* buf;
    void* _t580;
    _t580 = Alloc(20);
    buf = _t580;
    bux_sha1(data, len, buf);
    const char* result;
    const char* _t581;
    _t581 = bux_bytes_to_hex(buf, 20);
    result = _t581;
    Free(buf);
    return result;
}

const char* Hash_Sha256(const char* data) {
    int _t583;
    int len;
    unsigned int _t582;
    _t582 = String_Len(data);
    _t583 = (int)_t582;
    len = _t583;
    void* buf;
    void* _t584;
    _t584 = Alloc(32);
    buf = _t584;
    bux_sha256(data, len, buf);
    const char* result;
    const char* _t585;
    _t585 = bux_bytes_to_hex(buf, 32);
    result = _t585;
    Free(buf);
    return result;
}

const char* Hash_Sha384(const char* data) {
    int _t587;
    int len;
    unsigned int _t586;
    _t586 = String_Len(data);
    _t587 = (int)_t586;
    len = _t587;
    void* buf;
    void* _t588;
    _t588 = Alloc(48);
    buf = _t588;
    bux_sha384(data, len, buf);
    const char* result;
    const char* _t589;
    _t589 = bux_bytes_to_hex(buf, 48);
    result = _t589;
    Free(buf);
    return result;
}

const char* Hash_Sha512(const char* data) {
    int _t591;
    int len;
    unsigned int _t590;
    _t590 = String_Len(data);
    _t591 = (int)_t590;
    len = _t591;
    void* buf;
    void* _t592;
    _t592 = Alloc(64);
    buf = _t592;
    bux_sha512(data, len, buf);
    const char* result;
    const char* _t593;
    _t593 = bux_bytes_to_hex(buf, 64);
    result = _t593;
    Free(buf);
    return result;
}

void Hash_Sha256Raw(const char* data, void* out) {
    int _t595;
    unsigned int _t594;
    _t594 = String_Len(data);
    _t595 = (int)_t594;
    bux_sha256(data, _t595, out);
}

void Hash_Sha384Raw(const char* data, void* out) {
    int _t597;
    unsigned int _t596;
    _t596 = String_Len(data);
    _t597 = (int)_t596;
    bux_sha384(data, _t597, out);
}

void Hash_Sha512Raw(const char* data, void* out) {
    int _t599;
    unsigned int _t598;
    _t598 = String_Len(data);
    _t599 = (int)_t598;
    bux_sha512(data, _t599, 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 _t601;
    unsigned int _t600;
    _t600 = String_Len(s);
    _t601 = (int)_t600;
    const char* _t602;
    _t602 = bux_base64_encode(s, _t601);
    return _t602;
}

const char* Base64_Decode(const char* s) {
    int _t604;
    void* _t605;
    int outlen;
    outlen = 0;
    unsigned int _t603;
    _t603 = String_Len(s);
    _t604 = (int)_t603;
    _t605 = &outlen;
    const char* _t606;
    _t606 = bux_base64_decode(s, _t604, _t605);
    return _t606;
}

const char* Base64URL_Encode(const char* s) {
    int _t608;
    unsigned int _t607;
    _t607 = String_Len(s);
    _t608 = (int)_t607;
    const char* _t609;
    _t609 = bux_base64url_encode(s, _t608);
    return _t609;
}

const char* Base64URL_Decode(const char* s) {
    int _t611;
    void* _t612;
    int outlen;
    outlen = 0;
    unsigned int _t610;
    _t610 = String_Len(s);
    _t611 = (int)_t610;
    _t612 = &outlen;
    const char* _t613;
    _t613 = bux_base64url_decode(s, _t611, _t612);
    return _t613;
}

const char* Hmac_Sha256(const char* key, const char* message) {
    int _t615;
    int _t617;
    int kl;
    unsigned int _t614;
    _t614 = String_Len(key);
    _t615 = (int)_t614;
    kl = _t615;
    int ml;
    unsigned int _t616;
    _t616 = String_Len(message);
    _t617 = (int)_t616;
    ml = _t617;
    void* buf;
    void* _t618;
    _t618 = Alloc(32);
    buf = _t618;
    bux_hmac_sha256(key, kl, message, ml, buf);
    const char* result;
    const char* _t619;
    _t619 = bux_bytes_to_hex(buf, 32);
    result = _t619;
    Free(buf);
    return result;
}

void Hmac_Sha256Raw(const char* key, const char* message, void* out) {
    int _t621;
    int _t623;
    unsigned int _t620;
    _t620 = String_Len(key);
    _t621 = (int)_t620;
    unsigned int _t622;
    _t622 = String_Len(message);
    _t623 = (int)_t622;
    bux_hmac_sha256(key, _t621, message, _t623, out);
}

const char* Hmac_Sha256Base64(const char* key, const char* message) {
    int _t625;
    int _t627;
    const char* _t629;
    int kl;
    unsigned int _t624;
    _t624 = String_Len(key);
    _t625 = (int)_t624;
    kl = _t625;
    int ml;
    unsigned int _t626;
    _t626 = String_Len(message);
    _t627 = (int)_t626;
    ml = _t627;
    void* buf;
    void* _t628;
    _t628 = Alloc(32);
    buf = _t628;
    bux_hmac_sha256(key, kl, message, ml, buf);
    const char* result;
    _t629 = (const char*)buf;
    const char* _t630;
    _t630 = bux_base64_encode(_t629, 32);
    result = _t630;
    Free(buf);
    return result;
}

const char* Hmac_Sha384(const char* key, const char* message) {
    int _t632;
    int _t634;
    int kl;
    unsigned int _t631;
    _t631 = String_Len(key);
    _t632 = (int)_t631;
    kl = _t632;
    int ml;
    unsigned int _t633;
    _t633 = String_Len(message);
    _t634 = (int)_t633;
    ml = _t634;
    void* buf;
    void* _t635;
    _t635 = Alloc(48);
    buf = _t635;
    bux_hmac_sha384(key, kl, message, ml, buf);
    const char* result;
    const char* _t636;
    _t636 = bux_bytes_to_hex(buf, 48);
    result = _t636;
    Free(buf);
    return result;
}

void Hmac_Sha384Raw(const char* key, const char* message, void* out) {
    int _t638;
    int _t640;
    unsigned int _t637;
    _t637 = String_Len(key);
    _t638 = (int)_t637;
    unsigned int _t639;
    _t639 = String_Len(message);
    _t640 = (int)_t639;
    bux_hmac_sha384(key, _t638, message, _t640, out);
}

const char* Hmac_Sha384Base64(const char* key, const char* message) {
    int _t642;
    int _t644;
    const char* _t646;
    int kl;
    unsigned int _t641;
    _t641 = String_Len(key);
    _t642 = (int)_t641;
    kl = _t642;
    int ml;
    unsigned int _t643;
    _t643 = String_Len(message);
    _t644 = (int)_t643;
    ml = _t644;
    void* buf;
    void* _t645;
    _t645 = Alloc(48);
    buf = _t645;
    bux_hmac_sha384(key, kl, message, ml, buf);
    const char* result;
    _t646 = (const char*)buf;
    const char* _t647;
    _t647 = bux_base64_encode(_t646, 48);
    result = _t647;
    Free(buf);
    return result;
}

const char* Hmac_Sha512(const char* key, const char* message) {
    int _t649;
    int _t651;
    int kl;
    unsigned int _t648;
    _t648 = String_Len(key);
    _t649 = (int)_t648;
    kl = _t649;
    int ml;
    unsigned int _t650;
    _t650 = String_Len(message);
    _t651 = (int)_t650;
    ml = _t651;
    void* buf;
    void* _t652;
    _t652 = Alloc(64);
    buf = _t652;
    bux_hmac_sha512(key, kl, message, ml, buf);
    const char* result;
    const char* _t653;
    _t653 = bux_bytes_to_hex(buf, 64);
    result = _t653;
    Free(buf);
    return result;
}

void Hmac_Sha512Raw(const char* key, const char* message, void* out) {
    int _t655;
    int _t657;
    unsigned int _t654;
    _t654 = String_Len(key);
    _t655 = (int)_t654;
    unsigned int _t656;
    _t656 = String_Len(message);
    _t657 = (int)_t656;
    bux_hmac_sha512(key, _t655, message, _t657, out);
}

const char* Hmac_Sha512Base64(const char* key, const char* message) {
    int _t659;
    int _t661;
    const char* _t663;
    int kl;
    unsigned int _t658;
    _t658 = String_Len(key);
    _t659 = (int)_t658;
    kl = _t659;
    int ml;
    unsigned int _t660;
    _t660 = String_Len(message);
    _t661 = (int)_t660;
    ml = _t661;
    void* buf;
    void* _t662;
    _t662 = Alloc(64);
    buf = _t662;
    bux_hmac_sha512(key, kl, message, ml, buf);
    const char* result;
    _t663 = (const char*)buf;
    const char* _t664;
    _t664 = bux_base64_encode(_t663, 64);
    result = _t664;
    Free(buf);
    return result;
}

const char* Random_Bytes(int n) {
    int _t665;
    unsigned int _t666;
    int _t669;
    const char* _t670;
    _t665 = (n <= 0);
    if (!_t665) goto endif224;
    {
    return "";
    }
    endif224:;
    void* buf;
    _t666 = (unsigned int)n;
    void* _t667;
    _t667 = Alloc(_t666);
    buf = _t667;
    int _t668;
    _t668 = bux_random_bytes(buf, n);
    _t669 = (_t668 != 1);
    if (!_t669) goto endif226;
    {
    Free(buf);
    return "";
    }
    endif226:;
    _t670 = (const char*)buf;
    return _t670;
}

const char* Random_Hex(int n) {
    int _t671;
    unsigned int _t672;
    int _t675;
    _t671 = (n <= 0);
    if (!_t671) goto endif228;
    {
    return "";
    }
    endif228:;
    void* buf;
    _t672 = (unsigned int)n;
    void* _t673;
    _t673 = Alloc(_t672);
    buf = _t673;
    int _t674;
    _t674 = bux_random_bytes(buf, n);
    _t675 = (_t674 != 1);
    if (!_t675) goto endif230;
    {
    Free(buf);
    return "";
    }
    endif230:;
    const char* result;
    const char* _t676;
    _t676 = bux_bytes_to_hex(buf, n);
    result = _t676;
    Free(buf);
    return result;
}

const char* Random_Base64(int n) {
    int _t677;
    unsigned int _t678;
    int _t681;
    const char* _t682;
    _t677 = (n <= 0);
    if (!_t677) goto endif232;
    {
    return "";
    }
    endif232:;
    void* buf;
    _t678 = (unsigned int)n;
    void* _t679;
    _t679 = Alloc(_t678);
    buf = _t679;
    int _t680;
    _t680 = bux_random_bytes(buf, n);
    _t681 = (_t680 != 1);
    if (!_t681) goto endif234;
    {
    Free(buf);
    return "";
    }
    endif234:;
    const char* result;
    _t682 = (const char*)buf;
    const char* _t683;
    _t683 = bux_base64_encode(_t682, n);
    result = _t683;
    Free(buf);
    return result;
}

unsigned int Random_Uint32(void) {
    int _t686;
    unsigned int* _t687;
    unsigned int _t688;
    void* buf;
    void* _t684;
    _t684 = Alloc(4);
    buf = _t684;
    int _t685;
    _t685 = bux_random_bytes(buf, 4);
    _t686 = (_t685 != 1);
    if (!_t686) goto endif236;
    {
    Free(buf);
    return 0;
    }
    endif236:;
    unsigned int* ptr;
    _t687 = (unsigned int*)buf;
    ptr = _t687;
    unsigned int val;
    _t688 = *ptr;
    val = _t688;
    Free(buf);
    return val;
}

const char* Aes_GenerateKey(void) {
    unsigned int _t689;
    int _t692;
    const char* _t693;
    void* buf;
    _t689 = (unsigned int)AES_KEY_SIZE;
    void* _t690;
    _t690 = Alloc(_t689);
    buf = _t690;
    int _t691;
    _t691 = bux_random_bytes(buf, AES_KEY_SIZE);
    _t692 = (_t691 != 1);
    if (!_t692) goto endif238;
    {
    Free(buf);
    return "";
    }
    endif238:;
    _t693 = (const char*)buf;
    return _t693;
}

const char* Aes_GenerateIV(void) {
    unsigned int _t694;
    int _t697;
    const char* _t698;
    void* buf;
    _t694 = (unsigned int)AES_IV_SIZE;
    void* _t695;
    _t695 = Alloc(_t694);
    buf = _t695;
    int _t696;
    _t696 = bux_random_bytes(buf, AES_IV_SIZE);
    _t697 = (_t696 != 1);
    if (!_t697) goto endif240;
    {
    Free(buf);
    return "";
    }
    endif240:;
    _t698 = (const char*)buf;
    return _t698;
}

const char* Aes_CbcEncrypt(const char* plain, const char* key, const char* iv) {
    int _t700;
    void* _t701;
    int outlen;
    outlen = 0;
    unsigned int _t699;
    _t699 = String_Len(plain);
    _t700 = (int)_t699;
    _t701 = &outlen;
    const char* _t702;
    _t702 = bux_aes_256_cbc_encrypt(plain, _t700, key, iv, _t701);
    return _t702;
}

const char* Aes_CbcDecrypt(const char* cipher, const char* key, const char* iv) {
    int _t704;
    void* _t705;
    int outlen;
    outlen = 0;
    unsigned int _t703;
    _t703 = String_Len(cipher);
    _t704 = (int)_t703;
    _t705 = &outlen;
    const char* _t706;
    _t706 = bux_aes_256_cbc_decrypt(cipher, _t704, key, iv, _t705);
    return _t706;
}

const char* Aes_GcmEncrypt(const char* plain, const char* key, const char* iv, void* tag) {
    int _t708;
    void* _t709;
    int outlen;
    outlen = 0;
    unsigned int _t707;
    _t707 = String_Len(plain);
    _t708 = (int)_t707;
    _t709 = &outlen;
    const char* _t710;
    _t710 = bux_aes_256_gcm_encrypt(plain, _t708, key, iv, tag, _t709);
    return _t710;
}

const char* Aes_GcmDecrypt(const char* cipher, const char* key, const char* iv, const char* tag) {
    int _t712;
    void* _t713;
    int outlen;
    outlen = 0;
    unsigned int _t711;
    _t711 = String_Len(cipher);
    _t712 = (int)_t711;
    _t713 = &outlen;
    const char* _t714;
    _t714 = bux_aes_256_gcm_decrypt(cipher, _t712, key, iv, tag, _t713);
    return _t714;
}

const char* Jwt_MakeHeader(JwtAlg alg) {
    int _t715;
    int _t716;
    int _t717;
    int _t718;
    int _t719;
    int _t720;
    int _t721;
    int _t722;
    int _t723;
    _t715 = (alg == JwtAlg_HS256);
    if (!_t715) goto endif242;
    {
    return "{\"alg\":\"HS256\",\"typ\":\"JWT\"}";
    }
    endif242:;
    _t716 = (alg == JwtAlg_HS384);
    if (!_t716) goto endif244;
    {
    return "{\"alg\":\"HS384\",\"typ\":\"JWT\"}";
    }
    endif244:;
    _t717 = (alg == JwtAlg_HS512);
    if (!_t717) goto endif246;
    {
    return "{\"alg\":\"HS512\",\"typ\":\"JWT\"}";
    }
    endif246:;
    _t718 = (alg == JwtAlg_RS256);
    if (!_t718) goto endif248;
    {
    return "{\"alg\":\"RS256\",\"typ\":\"JWT\"}";
    }
    endif248:;
    _t719 = (alg == JwtAlg_RS384);
    if (!_t719) goto endif250;
    {
    return "{\"alg\":\"RS384\",\"typ\":\"JWT\"}";
    }
    endif250:;
    _t720 = (alg == JwtAlg_RS512);
    if (!_t720) goto endif252;
    {
    return "{\"alg\":\"RS512\",\"typ\":\"JWT\"}";
    }
    endif252:;
    _t721 = (alg == JwtAlg_ES256);
    if (!_t721) goto endif254;
    {
    return "{\"alg\":\"ES256\",\"typ\":\"JWT\"}";
    }
    endif254:;
    _t722 = (alg == JwtAlg_ES384);
    if (!_t722) goto endif256;
    {
    return "{\"alg\":\"ES384\",\"typ\":\"JWT\"}";
    }
    endif256:;
    _t723 = (alg == JwtAlg_EdDSA);
    if (!_t723) goto endif258;
    {
    return "{\"alg\":\"EdDSA\",\"typ\":\"JWT\"}";
    }
    endif258:;
    return "{\"alg\":\"none\",\"typ\":\"JWT\"}";
}

const char* Jwt_Sign(JwtAlg alg, const char* signingInput, const char* key) {
    int _t724;
    const char* _t726;
    int _t728;
    const char* _t730;
    int _t732;
    const char* _t734;
    int _t736;
    int _t739;
    int _t741;
    int _t744;
    int _t746;
    int _t749;
    int _t751;
    int _t754;
    int _t756;
    int _t759;
    int _t761;
    _t724 = (alg == JwtAlg_HS256);
    if (!_t724) goto endif260;
    {
    void* buf;
    void* _t725;
    _t725 = Alloc(32);
    buf = _t725;
    Hmac_Sha256Raw(key, signingInput, buf);
    const char* result;
    _t726 = (const char*)buf;
    const char* _t727;
    _t727 = bux_base64_encode(_t726, 32);
    result = _t727;
    Free(buf);
    return result;
    }
    endif260:;
    _t728 = (alg == JwtAlg_HS384);
    if (!_t728) goto endif262;
    {
    void* buf;
    void* _t729;
    _t729 = Alloc(48);
    buf = _t729;
    Hmac_Sha384Raw(key, signingInput, buf);
    const char* result;
    _t730 = (const char*)buf;
    const char* _t731;
    _t731 = bux_base64_encode(_t730, 48);
    result = _t731;
    Free(buf);
    return result;
    }
    endif262:;
    _t732 = (alg == JwtAlg_HS512);
    if (!_t732) goto endif264;
    {
    void* buf;
    void* _t733;
    _t733 = Alloc(64);
    buf = _t733;
    Hmac_Sha512Raw(key, signingInput, buf);
    const char* result;
    _t734 = (const char*)buf;
    const char* _t735;
    _t735 = bux_base64_encode(_t734, 64);
    result = _t735;
    Free(buf);
    return result;
    }
    endif264:;
    _t736 = (alg == JwtAlg_RS256);
    if (!_t736) goto endif266;
    {
    const char* raw;
    const char* _t737;
    _t737 = Rsa_SignSha256(key, signingInput);
    raw = _t737;
    unsigned int _t738;
    _t738 = String_Len(raw);
    _t739 = (int)_t738;
    const char* _t740;
    _t740 = bux_base64_encode(raw, _t739);
    return _t740;
    }
    endif266:;
    _t741 = (alg == JwtAlg_RS384);
    if (!_t741) goto endif268;
    {
    const char* raw;
    const char* _t742;
    _t742 = Rsa_SignSha384(key, signingInput);
    raw = _t742;
    unsigned int _t743;
    _t743 = String_Len(raw);
    _t744 = (int)_t743;
    const char* _t745;
    _t745 = bux_base64_encode(raw, _t744);
    return _t745;
    }
    endif268:;
    _t746 = (alg == JwtAlg_RS512);
    if (!_t746) goto endif270;
    {
    const char* raw;
    const char* _t747;
    _t747 = Rsa_SignSha512(key, signingInput);
    raw = _t747;
    unsigned int _t748;
    _t748 = String_Len(raw);
    _t749 = (int)_t748;
    const char* _t750;
    _t750 = bux_base64_encode(raw, _t749);
    return _t750;
    }
    endif270:;
    _t751 = (alg == JwtAlg_ES256);
    if (!_t751) goto endif272;
    {
    const char* raw;
    const char* _t752;
    _t752 = Ecdsa_SignP256(key, signingInput);
    raw = _t752;
    unsigned int _t753;
    _t753 = String_Len(raw);
    _t754 = (int)_t753;
    const char* _t755;
    _t755 = bux_base64_encode(raw, _t754);
    return _t755;
    }
    endif272:;
    _t756 = (alg == JwtAlg_ES384);
    if (!_t756) goto endif274;
    {
    const char* raw;
    const char* _t757;
    _t757 = Ecdsa_SignP384(key, signingInput);
    raw = _t757;
    unsigned int _t758;
    _t758 = String_Len(raw);
    _t759 = (int)_t758;
    const char* _t760;
    _t760 = bux_base64_encode(raw, _t759);
    return _t760;
    }
    endif274:;
    _t761 = (alg == JwtAlg_EdDSA);
    if (!_t761) goto endif276;
    {
    const char* _t762;
    _t762 = Ed25519_Sign(key, signingInput);
    return _t762;
    }
    endif276:;
    return "";
}

bool Jwt_Verify(JwtAlg alg, const char* signingInput, const char* signatureB64, const char* key) {
    int _t763;
    const char* _t765;
    int _t768;
    const char* _t770;
    int _t773;
    const char* _t775;
    int _t778;
    int _t780;
    int _t782;
    int _t784;
    int _t786;
    int _t788;
    _t763 = (alg == JwtAlg_HS256);
    if (!_t763) goto endif278;
    {
    void* expectBuf;
    void* _t764;
    _t764 = Alloc(32);
    expectBuf = _t764;
    Hmac_Sha256Raw(key, signingInput, expectBuf);
    const char* expectB64;
    _t765 = (const char*)expectBuf;
    const char* _t766;
    _t766 = bux_base64_encode(_t765, 32);
    expectB64 = _t766;
    Free(expectBuf);
    bool _t767;
    _t767 = String_Eq(expectB64, signatureB64);
    return _t767;
    }
    endif278:;
    _t768 = (alg == JwtAlg_HS384);
    if (!_t768) goto endif280;
    {
    void* expectBuf;
    void* _t769;
    _t769 = Alloc(48);
    expectBuf = _t769;
    Hmac_Sha384Raw(key, signingInput, expectBuf);
    const char* expectB64;
    _t770 = (const char*)expectBuf;
    const char* _t771;
    _t771 = bux_base64_encode(_t770, 48);
    expectB64 = _t771;
    Free(expectBuf);
    bool _t772;
    _t772 = String_Eq(expectB64, signatureB64);
    return _t772;
    }
    endif280:;
    _t773 = (alg == JwtAlg_HS512);
    if (!_t773) goto endif282;
    {
    void* expectBuf;
    void* _t774;
    _t774 = Alloc(64);
    expectBuf = _t774;
    Hmac_Sha512Raw(key, signingInput, expectBuf);
    const char* expectB64;
    _t775 = (const char*)expectBuf;
    const char* _t776;
    _t776 = bux_base64_encode(_t775, 64);
    expectB64 = _t776;
    Free(expectBuf);
    bool _t777;
    _t777 = String_Eq(expectB64, signatureB64);
    return _t777;
    }
    endif282:;
    _t778 = (alg == JwtAlg_RS256);
    if (!_t778) goto endif284;
    {
    bool _t779;
    _t779 = Rsa_VerifySha256(key, signingInput, signatureB64);
    return _t779;
    }
    endif284:;
    _t780 = (alg == JwtAlg_RS384);
    if (!_t780) goto endif286;
    {
    bool _t781;
    _t781 = Rsa_VerifySha384(key, signingInput, signatureB64);
    return _t781;
    }
    endif286:;
    _t782 = (alg == JwtAlg_RS512);
    if (!_t782) goto endif288;
    {
    bool _t783;
    _t783 = Rsa_VerifySha512(key, signingInput, signatureB64);
    return _t783;
    }
    endif288:;
    _t784 = (alg == JwtAlg_ES256);
    if (!_t784) goto endif290;
    {
    bool _t785;
    _t785 = Ecdsa_VerifyP256(key, signingInput, signatureB64);
    return _t785;
    }
    endif290:;
    _t786 = (alg == JwtAlg_ES384);
    if (!_t786) goto endif292;
    {
    bool _t787;
    _t787 = Ecdsa_VerifyP384(key, signingInput, signatureB64);
    return _t787;
    }
    endif292:;
    _t788 = (alg == JwtAlg_EdDSA);
    if (!_t788) goto endif294;
    {
    bool _t789;
    _t789 = Ed25519_Verify(key, signatureB64, signingInput);
    return _t789;
    }
    endif294:;
    return 0;
}

const char* Jwt_Encode(const char* headerJson, const char* payloadJson, JwtAlg alg, const char* key) {
    const char* headerB64;
    const char* _t790;
    _t790 = Base64URL_Encode(headerJson);
    headerB64 = _t790;
    const char* payloadB64;
    const char* _t791;
    _t791 = Base64URL_Encode(payloadJson);
    payloadB64 = _t791;
    const char* signingInput;
    const char* _t792;
    _t792 = String_Concat(headerB64, ".");
    signingInput = _t792;
    const char* signingInputFull;
    const char* _t793;
    _t793 = String_Concat(signingInput, payloadB64);
    signingInputFull = _t793;
    const char* sigB64;
    const char* _t794;
    _t794 = Jwt_Sign(alg, signingInputFull, key);
    sigB64 = _t794;
    const char* part1;
    const char* _t795;
    _t795 = String_Concat(signingInputFull, ".");
    part1 = _t795;
    const char* _t796;
    _t796 = String_Concat(part1, sigB64);
    return _t796;
}

bool Jwt_Decode(const char* token, JwtAlg alg, const char* key, const char** headerOut, const char** payloadOut) {
    int _t798;
    int _t805;
    unsigned int partCount;
    unsigned int _t797;
    _t797 = bux_str_split_count(token, ".");
    partCount = _t797;
    _t798 = (partCount != 3);
    if (!_t798) goto endif296;
    {
    return 0;
    }
    endif296:;
    const char* headerB64;
    const char* _t799;
    _t799 = bux_str_split_part(token, ".", 0);
    headerB64 = _t799;
    const char* payloadB64;
    const char* _t800;
    _t800 = bux_str_split_part(token, ".", 1);
    payloadB64 = _t800;
    const char* sigB64;
    const char* _t801;
    _t801 = bux_str_split_part(token, ".", 2);
    sigB64 = _t801;
    const char* input;
    const char* _t802;
    _t802 = String_Concat(headerB64, ".");
    input = _t802;
    const char* signingInput;
    const char* _t803;
    _t803 = String_Concat(input, payloadB64);
    signingInput = _t803;
    bool _t804;
    _t804 = Jwt_Verify(alg, signingInput, sigB64, key);
    _t805 = !_t804;
    if (!_t805) goto endif298;
    {
    return 0;
    }
    endif298:;
    const char* _t806;
    _t806 = Base64URL_Decode(headerB64);
    headerOut[0] = _t806;
    const char* _t807;
    _t807 = Base64URL_Decode(payloadB64);
    payloadOut[0] = _t807;
    return 1;
}

const char* Jwt_EncodeHS256(const char* payloadJson, const char* secret) {
    const char* header;
    const char* _t808;
    _t808 = Jwt_MakeHeader(JwtAlg_HS256);
    header = _t808;
    const char* _t809;
    _t809 = Jwt_Encode(header, payloadJson, JwtAlg_HS256, secret);
    return _t809;
}

const char* Jwt_EncodeHS384(const char* payloadJson, const char* secret) {
    const char* header;
    const char* _t810;
    _t810 = Jwt_MakeHeader(JwtAlg_HS384);
    header = _t810;
    const char* _t811;
    _t811 = Jwt_Encode(header, payloadJson, JwtAlg_HS384, secret);
    return _t811;
}

const char* Jwt_EncodeHS512(const char* payloadJson, const char* secret) {
    const char* header;
    const char* _t812;
    _t812 = Jwt_MakeHeader(JwtAlg_HS512);
    header = _t812;
    const char* _t813;
    _t813 = Jwt_Encode(header, payloadJson, JwtAlg_HS512, secret);
    return _t813;
}

const char* Jwt_EncodeRS256(const char* payloadJson, const char* pemPrivateKey) {
    const char* header;
    const char* _t814;
    _t814 = Jwt_MakeHeader(JwtAlg_RS256);
    header = _t814;
    const char* _t815;
    _t815 = Jwt_Encode(header, payloadJson, JwtAlg_RS256, pemPrivateKey);
    return _t815;
}

const char* Jwt_EncodeES256(const char* payloadJson, const char* pemPrivateKey) {
    const char* header;
    const char* _t816;
    _t816 = Jwt_MakeHeader(JwtAlg_ES256);
    header = _t816;
    const char* _t817;
    _t817 = Jwt_Encode(header, payloadJson, JwtAlg_ES256, pemPrivateKey);
    return _t817;
}

const char* Jwt_EncodeEdDSA(const char* payloadJson, const char* rawPrivKey) {
    const char* header;
    const char* _t818;
    _t818 = Jwt_MakeHeader(JwtAlg_EdDSA);
    header = _t818;
    const char* _t819;
    _t819 = Jwt_Encode(header, payloadJson, JwtAlg_EdDSA, rawPrivKey);
    return _t819;
}

const char* Ecdsa_SignP256(const char* pemPrivateKey, const char* data) {
    int _t821;
    int _t823;
    void* _t824;
    int siglen;
    siglen = 0;
    unsigned int _t820;
    _t820 = String_Len(pemPrivateKey);
    _t821 = (int)_t820;
    unsigned int _t822;
    _t822 = String_Len(data);
    _t823 = (int)_t822;
    _t824 = &siglen;
    const char* _t825;
    _t825 = bux_ecdsa_sign_p256(pemPrivateKey, _t821, data, _t823, _t824);
    return _t825;
}

const char* Ecdsa_SignP256Base64(const char* pemPrivateKey, const char* data) {
    int _t828;
    const char* raw;
    const char* _t826;
    _t826 = Ecdsa_SignP256(pemPrivateKey, data);
    raw = _t826;
    unsigned int _t827;
    _t827 = String_Len(raw);
    _t828 = (int)_t827;
    const char* _t829;
    _t829 = bux_base64_encode(raw, _t828);
    return _t829;
}

bool Ecdsa_VerifyP256(const char* pemPublicKey, const char* data, const char* signature) {
    int _t831;
    int _t833;
    int _t835;
    int _t837;
    int r;
    unsigned int _t830;
    _t830 = String_Len(pemPublicKey);
    _t831 = (int)_t830;
    unsigned int _t832;
    _t832 = String_Len(data);
    _t833 = (int)_t832;
    unsigned int _t834;
    _t834 = String_Len(signature);
    _t835 = (int)_t834;
    int _t836;
    _t836 = bux_ecdsa_verify_p256(pemPublicKey, _t831, data, _t833, signature, _t835);
    r = _t836;
    _t837 = (r == 1);
    return _t837;
}

bool Ecdsa_VerifyP256Base64(const char* pemPublicKey, const char* data, const char* signatureB64) {
    int _t839;
    void* _t840;
    int outlen;
    outlen = 0;
    const char* sig;
    unsigned int _t838;
    _t838 = String_Len(signatureB64);
    _t839 = (int)_t838;
    _t840 = &outlen;
    const char* _t841;
    _t841 = bux_base64_decode(signatureB64, _t839, _t840);
    sig = _t841;
    bool _t842;
    _t842 = Ecdsa_VerifyP256(pemPublicKey, data, sig);
    return _t842;
}

const char* Ecdsa_SignP384(const char* pemPrivateKey, const char* data) {
    int _t844;
    int _t846;
    void* _t847;
    int siglen;
    siglen = 0;
    unsigned int _t843;
    _t843 = String_Len(pemPrivateKey);
    _t844 = (int)_t843;
    unsigned int _t845;
    _t845 = String_Len(data);
    _t846 = (int)_t845;
    _t847 = &siglen;
    const char* _t848;
    _t848 = bux_ecdsa_sign_p384(pemPrivateKey, _t844, data, _t846, _t847);
    return _t848;
}

const char* Ecdsa_SignP384Base64(const char* pemPrivateKey, const char* data) {
    int _t851;
    const char* raw;
    const char* _t849;
    _t849 = Ecdsa_SignP384(pemPrivateKey, data);
    raw = _t849;
    unsigned int _t850;
    _t850 = String_Len(raw);
    _t851 = (int)_t850;
    const char* _t852;
    _t852 = bux_base64_encode(raw, _t851);
    return _t852;
}

bool Ecdsa_VerifyP384(const char* pemPublicKey, const char* data, const char* signature) {
    int _t854;
    int _t856;
    int _t858;
    int _t860;
    int r;
    unsigned int _t853;
    _t853 = String_Len(pemPublicKey);
    _t854 = (int)_t853;
    unsigned int _t855;
    _t855 = String_Len(data);
    _t856 = (int)_t855;
    unsigned int _t857;
    _t857 = String_Len(signature);
    _t858 = (int)_t857;
    int _t859;
    _t859 = bux_ecdsa_verify_p384(pemPublicKey, _t854, data, _t856, signature, _t858);
    r = _t859;
    _t860 = (r == 1);
    return _t860;
}

bool Ecdsa_VerifyP384Base64(const char* pemPublicKey, const char* data, const char* signatureB64) {
    int _t862;
    void* _t863;
    int outlen;
    outlen = 0;
    const char* sig;
    unsigned int _t861;
    _t861 = String_Len(signatureB64);
    _t862 = (int)_t861;
    _t863 = &outlen;
    const char* _t864;
    _t864 = bux_base64_decode(signatureB64, _t862, _t863);
    sig = _t864;
    bool _t865;
    _t865 = Ecdsa_VerifyP384(pemPublicKey, data, sig);
    return _t865;
}

bool Ed25519_Keypair(void* pubKey, void* privKey) {
    int _t867;
    int r;
    int _t866;
    _t866 = bux_ed25519_keypair(pubKey, privKey);
    r = _t866;
    _t867 = (r == 1);
    return _t867;
}

const char* Ed25519_KeypairBase64(void) {
    unsigned int _t868;
    unsigned int _t870;
    int _t873;
    const char* _t874;
    const char* _t876;
    void* pubBuf;
    _t868 = (unsigned int)ED25519_PUBKEY_SIZE;
    void* _t869;
    _t869 = Alloc(_t868);
    pubBuf = _t869;
    void* priv;
    _t870 = (unsigned int)ED25519_PRIVKEY_SIZE;
    void* _t871;
    _t871 = Alloc(_t870);
    priv = _t871;
    int _t872;
    _t872 = bux_ed25519_keypair(pubBuf, priv);
    _t873 = (_t872 != 1);
    if (!_t873) goto endif300;
    {
    Free(pubBuf);
    Free(priv);
    return "";
    }
    endif300:;
    const char* pubB64;
    _t874 = (const char*)pubBuf;
    const char* _t875;
    _t875 = bux_base64_encode(_t874, ED25519_PUBKEY_SIZE);
    pubB64 = _t875;
    const char* privB64;
    _t876 = (const char*)priv;
    const char* _t877;
    _t877 = bux_base64_encode(_t876, ED25519_PRIVKEY_SIZE);
    privB64 = _t877;
    Free(pubBuf);
    Free(priv);
    const char* pair;
    const char* _t878;
    _t878 = String_Concat(pubB64, ":");
    pair = _t878;
    const char* _t879;
    _t879 = String_Concat(pair, privB64);
    return _t879;
}

const char* Ed25519_Sign(const char* privKey, const char* data) {
    unsigned int _t880;
    int _t883;
    int _t885;
    const char* _t886;
    void* sig;
    _t880 = (unsigned int)ED25519_SIG_SIZE;
    void* _t881;
    _t881 = Alloc(_t880);
    sig = _t881;
    unsigned int _t882;
    _t882 = String_Len(data);
    _t883 = (int)_t882;
    int _t884;
    _t884 = bux_ed25519_sign(privKey, data, _t883, sig);
    _t885 = (_t884 != 1);
    if (!_t885) goto endif302;
    {
    Free(sig);
    return "";
    }
    endif302:;
    _t886 = (const char*)sig;
    return _t886;
}

const char* Ed25519_SignBase64(const char* privKey, const char* data) {
    int _t889;
    const char* sig;
    const char* _t887;
    _t887 = Ed25519_Sign(privKey, data);
    sig = _t887;
    unsigned int _t888;
    _t888 = String_Len(sig);
    _t889 = (_t888 == 0);
    if (!_t889) goto endif304;
    {
    return "";
    }
    endif304:;
    const char* _t890;
    _t890 = bux_base64_encode(sig, ED25519_SIG_SIZE);
    return _t890;
}

bool Ed25519_Verify(const char* pubKey, const char* signature, const char* data) {
    int _t892;
    int _t894;
    int r;
    unsigned int _t891;
    _t891 = String_Len(data);
    _t892 = (int)_t891;
    int _t893;
    _t893 = bux_ed25519_verify(pubKey, signature, data, _t892);
    r = _t893;
    _t894 = (r == 1);
    return _t894;
}

bool Ed25519_VerifyBase64(const char* pubKey, const char* signatureB64, const char* data) {
    int _t896;
    void* _t897;
    int _t899;
    int outlen;
    outlen = 0;
    const char* sig;
    unsigned int _t895;
    _t895 = String_Len(signatureB64);
    _t896 = (int)_t895;
    _t897 = &outlen;
    const char* _t898;
    _t898 = bux_base64_decode(signatureB64, _t896, _t897);
    sig = _t898;
    _t899 = (outlen != ED25519_SIG_SIZE);
    if (!_t899) goto endif306;
    {
    return 0;
    }
    endif306:;
    bool _t900;
    _t900 = Ed25519_Verify(pubKey, sig, data);
    return _t900;
}

const char* Rsa_SignSha256(const char* pemPrivateKey, const char* data) {
    int _t902;
    int _t904;
    void* _t905;
    int siglen;
    siglen = 0;
    unsigned int _t901;
    _t901 = String_Len(pemPrivateKey);
    _t902 = (int)_t901;
    unsigned int _t903;
    _t903 = String_Len(data);
    _t904 = (int)_t903;
    _t905 = &siglen;
    const char* _t906;
    _t906 = bux_rsa_sign_sha256(pemPrivateKey, _t902, data, _t904, _t905);
    return _t906;
}

const char* Rsa_SignSha384(const char* pemPrivateKey, const char* data) {
    int _t908;
    int _t910;
    void* _t911;
    int siglen;
    siglen = 0;
    unsigned int _t907;
    _t907 = String_Len(pemPrivateKey);
    _t908 = (int)_t907;
    unsigned int _t909;
    _t909 = String_Len(data);
    _t910 = (int)_t909;
    _t911 = &siglen;
    const char* _t912;
    _t912 = bux_rsa_sign_sha384(pemPrivateKey, _t908, data, _t910, _t911);
    return _t912;
}

const char* Rsa_SignSha512(const char* pemPrivateKey, const char* data) {
    int _t914;
    int _t916;
    void* _t917;
    int siglen;
    siglen = 0;
    unsigned int _t913;
    _t913 = String_Len(pemPrivateKey);
    _t914 = (int)_t913;
    unsigned int _t915;
    _t915 = String_Len(data);
    _t916 = (int)_t915;
    _t917 = &siglen;
    const char* _t918;
    _t918 = bux_rsa_sign_sha512(pemPrivateKey, _t914, data, _t916, _t917);
    return _t918;
}

const char* Rsa_SignSha256Base64(const char* pemPrivateKey, const char* data) {
    int _t921;
    const char* raw;
    const char* _t919;
    _t919 = Rsa_SignSha256(pemPrivateKey, data);
    raw = _t919;
    unsigned int _t920;
    _t920 = String_Len(raw);
    _t921 = (int)_t920;
    const char* _t922;
    _t922 = bux_base64_encode(raw, _t921);
    return _t922;
}

const char* Rsa_SignSha384Base64(const char* pemPrivateKey, const char* data) {
    int _t925;
    const char* raw;
    const char* _t923;
    _t923 = Rsa_SignSha384(pemPrivateKey, data);
    raw = _t923;
    unsigned int _t924;
    _t924 = String_Len(raw);
    _t925 = (int)_t924;
    const char* _t926;
    _t926 = bux_base64_encode(raw, _t925);
    return _t926;
}

const char* Rsa_SignSha512Base64(const char* pemPrivateKey, const char* data) {
    int _t929;
    const char* raw;
    const char* _t927;
    _t927 = Rsa_SignSha512(pemPrivateKey, data);
    raw = _t927;
    unsigned int _t928;
    _t928 = String_Len(raw);
    _t929 = (int)_t928;
    const char* _t930;
    _t930 = bux_base64_encode(raw, _t929);
    return _t930;
}

bool Rsa_VerifySha256(const char* pemPublicKey, const char* data, const char* signature) {
    int _t932;
    int _t934;
    int _t936;
    int _t938;
    int r;
    unsigned int _t931;
    _t931 = String_Len(pemPublicKey);
    _t932 = (int)_t931;
    unsigned int _t933;
    _t933 = String_Len(data);
    _t934 = (int)_t933;
    unsigned int _t935;
    _t935 = String_Len(signature);
    _t936 = (int)_t935;
    int _t937;
    _t937 = bux_rsa_verify_sha256(pemPublicKey, _t932, data, _t934, signature, _t936);
    r = _t937;
    _t938 = (r == 1);
    return _t938;
}

bool Rsa_VerifySha384(const char* pemPublicKey, const char* data, const char* signature) {
    int _t940;
    int _t942;
    int _t944;
    int _t946;
    int r;
    unsigned int _t939;
    _t939 = String_Len(pemPublicKey);
    _t940 = (int)_t939;
    unsigned int _t941;
    _t941 = String_Len(data);
    _t942 = (int)_t941;
    unsigned int _t943;
    _t943 = String_Len(signature);
    _t944 = (int)_t943;
    int _t945;
    _t945 = bux_rsa_verify_sha384(pemPublicKey, _t940, data, _t942, signature, _t944);
    r = _t945;
    _t946 = (r == 1);
    return _t946;
}

bool Rsa_VerifySha512(const char* pemPublicKey, const char* data, const char* signature) {
    int _t948;
    int _t950;
    int _t952;
    int _t954;
    int r;
    unsigned int _t947;
    _t947 = String_Len(pemPublicKey);
    _t948 = (int)_t947;
    unsigned int _t949;
    _t949 = String_Len(data);
    _t950 = (int)_t949;
    unsigned int _t951;
    _t951 = String_Len(signature);
    _t952 = (int)_t951;
    int _t953;
    _t953 = bux_rsa_verify_sha512(pemPublicKey, _t948, data, _t950, signature, _t952);
    r = _t953;
    _t954 = (r == 1);
    return _t954;
}

bool Rsa_VerifySha256Base64(const char* pemPublicKey, const char* data, const char* signatureB64) {
    int _t956;
    void* _t957;
    int outlen;
    outlen = 0;
    const char* sig;
    unsigned int _t955;
    _t955 = String_Len(signatureB64);
    _t956 = (int)_t955;
    _t957 = &outlen;
    const char* _t958;
    _t958 = bux_base64_decode(signatureB64, _t956, _t957);
    sig = _t958;
    bool _t959;
    _t959 = Rsa_VerifySha256(pemPublicKey, data, sig);
    return _t959;
}

bool Rsa_VerifySha384Base64(const char* pemPublicKey, const char* data, const char* signatureB64) {
    int _t961;
    void* _t962;
    int outlen;
    outlen = 0;
    const char* sig;
    unsigned int _t960;
    _t960 = String_Len(signatureB64);
    _t961 = (int)_t960;
    _t962 = &outlen;
    const char* _t963;
    _t963 = bux_base64_decode(signatureB64, _t961, _t962);
    sig = _t963;
    bool _t964;
    _t964 = Rsa_VerifySha384(pemPublicKey, data, sig);
    return _t964;
}

bool Rsa_VerifySha512Base64(const char* pemPublicKey, const char* data, const char* signatureB64) {
    int _t966;
    void* _t967;
    int outlen;
    outlen = 0;
    const char* sig;
    unsigned int _t965;
    _t965 = String_Len(signatureB64);
    _t966 = (int)_t965;
    _t967 = &outlen;
    const char* _t968;
    _t968 = bux_base64_decode(signatureB64, _t966, _t967);
    sig = _t968;
    bool _t969;
    _t969 = Rsa_VerifySha512(pemPublicKey, data, sig);
    return _t969;
}

int Main(void) {
    int m1;
    int _t970;
    _t970 = Max_int(10, 20);
    m1 = _t970;
    int m2;
    int _t971;
    _t971 = Max_int(5, 3);
    m2 = _t971;
    PrintLine("Max(10, 20) = ");
    PrintInt(m1);
    PrintLine("");
    PrintLine("Max(5, 3) = ");
    PrintInt(m2);
    PrintLine("");
    return 0;
}

int Max_int(int a, int b) {
    int _t972;
    _t972 = (a > b);
    if (!_t972) goto else307;
    {
    return a;
    }
    goto endif308;
    else307:;
    {
    return b;
    }
    endif308:;
}

/* 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();
}
