---
source: framec/tests/c_snapshots.rs
expression: "compile_fixture(\"13_lifecycle_args\", \"c\")"
---
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>

// ============================================================================
// LifecycleArgs_FrameDict - String-keyed dictionary
// ============================================================================

typedef struct LifecycleArgs_FrameDictEntry {
    char* key;
    void* value;
    struct LifecycleArgs_FrameDictEntry* next;
} LifecycleArgs_FrameDictEntry;

typedef struct {
    LifecycleArgs_FrameDictEntry** buckets;
    int bucket_count;
    int size;
} LifecycleArgs_FrameDict;

static unsigned int LifecycleArgs_hash_string(const char* str) {
    unsigned int hash = 5381;
    int c;
    while ((c = *str++)) {
        hash = ((hash << 5) + hash) + c;
    }
    return hash;
}

static LifecycleArgs_FrameDict* LifecycleArgs_FrameDict_new(void) {
    LifecycleArgs_FrameDict* d = malloc(sizeof(LifecycleArgs_FrameDict));
    d->bucket_count = 16;
    d->buckets = calloc(d->bucket_count, sizeof(LifecycleArgs_FrameDictEntry*));
    d->size = 0;
    return d;
}

static void LifecycleArgs_FrameDict_set(LifecycleArgs_FrameDict* d, const char* key, void* value) {
    unsigned int idx = LifecycleArgs_hash_string(key) % d->bucket_count;
    LifecycleArgs_FrameDictEntry* entry = d->buckets[idx];
    while (entry) {
        if (strcmp(entry->key, key) == 0) {
            entry->value = value;
            return;
        }
        entry = entry->next;
    }
    LifecycleArgs_FrameDictEntry* new_entry = malloc(sizeof(LifecycleArgs_FrameDictEntry));
    new_entry->key = strdup(key);
    new_entry->value = value;
    new_entry->next = d->buckets[idx];
    d->buckets[idx] = new_entry;
    d->size++;
}

static void* LifecycleArgs_FrameDict_get(LifecycleArgs_FrameDict* d, const char* key) {
    unsigned int idx = LifecycleArgs_hash_string(key) % d->bucket_count;
    LifecycleArgs_FrameDictEntry* entry = d->buckets[idx];
    while (entry) {
        if (strcmp(entry->key, key) == 0) {
            return entry->value;
        }
        entry = entry->next;
    }
    return NULL;
}

static int LifecycleArgs_FrameDict_has(LifecycleArgs_FrameDict* d, const char* key) {
    unsigned int idx = LifecycleArgs_hash_string(key) % d->bucket_count;
    LifecycleArgs_FrameDictEntry* entry = d->buckets[idx];
    while (entry) {
        if (strcmp(entry->key, key) == 0) {
            return 1;
        }
        entry = entry->next;
    }
    return 0;
}

static LifecycleArgs_FrameDict* LifecycleArgs_FrameDict_copy(LifecycleArgs_FrameDict* src) {
    LifecycleArgs_FrameDict* dst = LifecycleArgs_FrameDict_new();
    for (int i = 0; i < src->bucket_count; i++) {
        LifecycleArgs_FrameDictEntry* entry = src->buckets[i];
        while (entry) {
            LifecycleArgs_FrameDict_set(dst, entry->key, entry->value);
            entry = entry->next;
        }
    }
    return dst;
}

static void LifecycleArgs_FrameDict_destroy(LifecycleArgs_FrameDict* d) {
    for (int i = 0; i < d->bucket_count; i++) {
        LifecycleArgs_FrameDictEntry* entry = d->buckets[i];
        while (entry) {
            LifecycleArgs_FrameDictEntry* next = entry->next;
            free(entry->key);
            free(entry);
            entry = next;
        }
    }
    free(d->buckets);
    free(d);
}

// ============================================================================
// LifecycleArgs_FrameVec - Dynamic array
// ============================================================================

typedef struct {
    void** items;
    int size;
    int capacity;
} LifecycleArgs_FrameVec;

static LifecycleArgs_FrameVec* LifecycleArgs_FrameVec_new(void) {
    LifecycleArgs_FrameVec* v = malloc(sizeof(LifecycleArgs_FrameVec));
    v->capacity = 8;
    v->size = 0;
    v->items = malloc(sizeof(void*) * v->capacity);
    return v;
}

static void LifecycleArgs_FrameVec_push(LifecycleArgs_FrameVec* v, void* item) {
    if (v->size >= v->capacity) {
        v->capacity *= 2;
        v->items = realloc(v->items, sizeof(void*) * v->capacity);
    }
    v->items[v->size++] = item;
}

static void* LifecycleArgs_FrameVec_pop(LifecycleArgs_FrameVec* v) {
    if (v->size == 0) return NULL;
    return v->items[--v->size];
}

static void* LifecycleArgs_FrameVec_last(LifecycleArgs_FrameVec* v) {
    if (v->size == 0) return NULL;
    return v->items[v->size - 1];
}

static void* LifecycleArgs_FrameVec_get(LifecycleArgs_FrameVec* v, int index) {
    if (index < 0 || index >= v->size) return NULL;
    return v->items[index];
}

static int LifecycleArgs_FrameVec_size(LifecycleArgs_FrameVec* v) {
    return v->size;
}

static void LifecycleArgs_FrameVec_destroy(LifecycleArgs_FrameVec* v) {
    if (!v) return;
    free(v->items);
    free(v);
}

static LifecycleArgs_FrameVec* LifecycleArgs_FrameVec_copy(LifecycleArgs_FrameVec* src) {
    if (!src) return NULL;
    LifecycleArgs_FrameVec* v = LifecycleArgs_FrameVec_new();
    for (int i = 0; i < src->size; i++) {
        LifecycleArgs_FrameVec_push(v, src->items[i]);
    }
    return v;
}

// ============================================================================
// LifecycleArgs_pack_double / LifecycleArgs_unpack_double — bit-pun doubles through void*
// ============================================================================

static inline void* LifecycleArgs_pack_double(double v) {
    void* p = 0;
    memcpy(&p, &v, sizeof(double));
    return p;
}

static inline double LifecycleArgs_unpack_double(void* p) {
    double d;
    memcpy(&d, &p, sizeof(double));
    return d;
}

// ============================================================================
// LifecycleArgs_FrameEvent - Event routing object
// ============================================================================

typedef struct {
    const char* _message;
    LifecycleArgs_FrameVec* _parameters;
    int _owns_parameters;
} LifecycleArgs_FrameEvent;

static LifecycleArgs_FrameEvent* LifecycleArgs_FrameEvent_new(const char* message, LifecycleArgs_FrameVec* parameters, int owns_parameters) {
    LifecycleArgs_FrameEvent* e = malloc(sizeof(LifecycleArgs_FrameEvent));
    e->_message = message;
    e->_parameters = parameters;
    e->_owns_parameters = owns_parameters;
    return e;
}

static void LifecycleArgs_FrameEvent_destroy(LifecycleArgs_FrameEvent* e) {
    if (e->_owns_parameters && e->_parameters) LifecycleArgs_FrameVec_destroy(e->_parameters);
    free(e);
}

// ============================================================================
// LifecycleArgs_FrameContext - Interface call context
// ============================================================================

typedef struct {
    LifecycleArgs_FrameEvent* event;
    void* _return;
    LifecycleArgs_FrameDict* _data;
    int _transitioned;
} LifecycleArgs_FrameContext;

static LifecycleArgs_FrameContext* LifecycleArgs_FrameContext_new(LifecycleArgs_FrameEvent* event, void* default_return) {
    LifecycleArgs_FrameContext* ctx = malloc(sizeof(LifecycleArgs_FrameContext));
    ctx->event = event;
    ctx->_return = default_return;
    ctx->_data = LifecycleArgs_FrameDict_new();
    ctx->_transitioned = 0;
    return ctx;
}

static void LifecycleArgs_FrameContext_destroy(LifecycleArgs_FrameContext* ctx) {
    LifecycleArgs_FrameDict_destroy(ctx->_data);
    free(ctx);
}

// ============================================================================
// LifecycleArgs_Compartment - State closure
// ============================================================================

typedef struct LifecycleArgs_Compartment {
    const char* state;
    LifecycleArgs_FrameVec* state_args;
    LifecycleArgs_FrameDict* state_vars;
    LifecycleArgs_FrameVec* enter_args;
    LifecycleArgs_FrameVec* exit_args;
    LifecycleArgs_FrameEvent* forward_event;
    struct LifecycleArgs_Compartment* parent_compartment;
    int _ref_count;
} LifecycleArgs_Compartment;

static LifecycleArgs_Compartment* LifecycleArgs_Compartment_new(const char* state) {
    LifecycleArgs_Compartment* c = malloc(sizeof(LifecycleArgs_Compartment));
    c->state = state;
    c->state_args = LifecycleArgs_FrameVec_new();
    c->state_vars = LifecycleArgs_FrameDict_new();
    c->enter_args = LifecycleArgs_FrameVec_new();
    c->exit_args = LifecycleArgs_FrameVec_new();
    c->forward_event = NULL;
    c->parent_compartment = NULL;
    c->_ref_count = 1;
    return c;
}

static LifecycleArgs_Compartment* LifecycleArgs_Compartment_ref(LifecycleArgs_Compartment* c) {
    if (c) c->_ref_count++;
    return c;
}

static void LifecycleArgs_Compartment_unref(LifecycleArgs_Compartment* c);
static void LifecycleArgs_Compartment_unref(LifecycleArgs_Compartment* c) {
    if (c == NULL) return;
    c->_ref_count--;
    if (c->_ref_count <= 0) {
        LifecycleArgs_Compartment_unref(c->parent_compartment);
        LifecycleArgs_FrameVec_destroy(c->state_args);
        LifecycleArgs_FrameDict_destroy(c->state_vars);
        LifecycleArgs_FrameVec_destroy(c->enter_args);
        LifecycleArgs_FrameVec_destroy(c->exit_args);
        free(c);
    }
}

static LifecycleArgs_Compartment* LifecycleArgs_Compartment_copy(LifecycleArgs_Compartment* src) {
    LifecycleArgs_Compartment* c = malloc(sizeof(LifecycleArgs_Compartment));
    c->state = src->state;
    c->state_args = LifecycleArgs_FrameVec_copy(src->state_args);
    c->state_vars = LifecycleArgs_FrameDict_copy(src->state_vars);
    c->enter_args = LifecycleArgs_FrameVec_copy(src->enter_args);
    c->exit_args = LifecycleArgs_FrameVec_copy(src->exit_args);
    c->forward_event = src->forward_event;  // Shallow copy OK
    c->parent_compartment = src->parent_compartment;
    return c;
}

static void LifecycleArgs_Compartment_destroy(LifecycleArgs_Compartment* c) {
    LifecycleArgs_FrameVec_destroy(c->state_args);
    LifecycleArgs_FrameDict_destroy(c->state_vars);
    LifecycleArgs_FrameVec_destroy(c->enter_args);
    LifecycleArgs_FrameVec_destroy(c->exit_args);
    free(c);
}

// Helper macros for context access
#define LifecycleArgs_CTX(self) ((LifecycleArgs_FrameContext*)LifecycleArgs_FrameVec_last((self)->_context_stack))
#define LifecycleArgs_PARAM(self, key) LifecycleArgs_FrameDict_get(LifecycleArgs_CTX(self)->event->_parameters, key)
#define LifecycleArgs_RETURN(self) LifecycleArgs_CTX(self)->_return
#define LifecycleArgs_DATA(self, key) LifecycleArgs_FrameDict_get(LifecycleArgs_CTX(self)->_data, key)
#define LifecycleArgs_DATA_SET(self, key, val) LifecycleArgs_FrameDict_set(LifecycleArgs_CTX(self)->_data, key, val)

// Forward declarations
typedef struct LifecycleArgs LifecycleArgs;
static void LifecycleArgs_kernel(LifecycleArgs* self, LifecycleArgs_FrameEvent* __e);
static void LifecycleArgs_router(LifecycleArgs* self, LifecycleArgs_FrameEvent* __e);
static void LifecycleArgs_transition(LifecycleArgs* self, LifecycleArgs_Compartment* next);
static int LifecycleArgs_hsm_chain(LifecycleArgs* self, const char* leaf, const char*** out_chain);
static LifecycleArgs_Compartment* LifecycleArgs_prepareEnter(LifecycleArgs* self, const char* leaf, LifecycleArgs_FrameVec* state_args, LifecycleArgs_FrameVec* enter_args);
static void LifecycleArgs_prepareExit(LifecycleArgs* self, LifecycleArgs_FrameVec* exit_args);
static void LifecycleArgs_state_Idle(LifecycleArgs* self, LifecycleArgs_FrameEvent* __e, LifecycleArgs_Compartment* compartment);
static void LifecycleArgs_state_Active(LifecycleArgs* self, LifecycleArgs_FrameEvent* __e, LifecycleArgs_Compartment* compartment);
static void LifecycleArgs_s_Idle_hdl_user_load(LifecycleArgs* self, LifecycleArgs_FrameEvent* __e, LifecycleArgs_Compartment* compartment);
static void LifecycleArgs_s_Active_hdl_frame_enter(LifecycleArgs* self, LifecycleArgs_FrameEvent* __e, LifecycleArgs_Compartment* compartment);
static void LifecycleArgs_s_Active_hdl_user_tag(LifecycleArgs* self, LifecycleArgs_FrameEvent* __e, LifecycleArgs_Compartment* compartment);
static void LifecycleArgs_s_Active_hdl_user_total(LifecycleArgs* self, LifecycleArgs_FrameEvent* __e, LifecycleArgs_Compartment* compartment);
void LifecycleArgs_load (LifecycleArgs* self, int n, char* label);
int LifecycleArgs_total (LifecycleArgs* self);
char* LifecycleArgs_tag (LifecycleArgs* self);

struct LifecycleArgs {
    LifecycleArgs_FrameVec* _state_stack;
    LifecycleArgs_Compartment* __compartment;
    LifecycleArgs_Compartment* __next_compartment;
    LifecycleArgs_FrameVec* _context_stack;
    int sum;
    char* label;
};

LifecycleArgs* LifecycleArgs_new(void) {
    LifecycleArgs* self = calloc(1, sizeof(LifecycleArgs));
    self->_state_stack = LifecycleArgs_FrameVec_new();
    self->_context_stack = LifecycleArgs_FrameVec_new();
    self->sum = 0;
    self->label = "";
    LifecycleArgs_FrameVec* __sa = NULL;
    LifecycleArgs_FrameVec* __ea = NULL;
    self->__compartment = LifecycleArgs_prepareEnter(self, "Idle", __sa, __ea);
    self->__next_compartment = NULL;
    LifecycleArgs_FrameEvent* __e = LifecycleArgs_FrameEvent_new("$>", self->__compartment->enter_args, 0);
    LifecycleArgs_FrameContext* __ctx = LifecycleArgs_FrameContext_new(__e, NULL);
    LifecycleArgs_FrameVec_push(self->_context_stack, __ctx);
    LifecycleArgs_FrameContext* __init_ctx = (LifecycleArgs_FrameContext*)LifecycleArgs_FrameVec_pop(self->_context_stack);
    LifecycleArgs_FrameContext_destroy(__init_ctx);
    LifecycleArgs_FrameEvent_destroy(__e);
    return self;
}

LifecycleArgs* LifecycleArgs_create(void) {
    LifecycleArgs* self = LifecycleArgs_new();
    self->_state_stack = LifecycleArgs_FrameVec_new();
    self->_context_stack = LifecycleArgs_FrameVec_new();
    self->sum = 0;
    self->label = "";
    LifecycleArgs_FrameVec* __sa = NULL;
    LifecycleArgs_FrameVec* __ea = NULL;
    self->__compartment = LifecycleArgs_prepareEnter(self, "Idle", __sa, __ea);
    self->__next_compartment = NULL;
    LifecycleArgs_FrameEvent* __e = LifecycleArgs_FrameEvent_new("$>", self->__compartment->enter_args, 0);
    LifecycleArgs_FrameContext* __ctx = LifecycleArgs_FrameContext_new(__e, NULL);
    LifecycleArgs_FrameVec_push(self->_context_stack, __ctx);
    LifecycleArgs_kernel(self, __e);
    LifecycleArgs_FrameContext* __init_ctx = (LifecycleArgs_FrameContext*)LifecycleArgs_FrameVec_pop(self->_context_stack);
    LifecycleArgs_FrameContext_destroy(__init_ctx);
    LifecycleArgs_FrameEvent_destroy(__e);
    return self;
}

static int LifecycleArgs_hsm_chain(LifecycleArgs* self, const char* leaf, const char*** out_chain) {
    if (false) { (void)0; }
        else if (strcmp(leaf, "Idle") == 0) {
            static const char* __chain[] = { "Idle" };
            *out_chain = __chain;
            return 1;
        }
        else if (strcmp(leaf, "Active") == 0) {
            static const char* __chain[] = { "Active" };
            *out_chain = __chain;
            return 1;
        }
        *out_chain = NULL;
        return 0;
}

static LifecycleArgs_Compartment* LifecycleArgs_prepareEnter(LifecycleArgs* self, const char* leaf, LifecycleArgs_FrameVec* state_args, LifecycleArgs_FrameVec* enter_args) {
    const char** chain = NULL;
    int n = LifecycleArgs_hsm_chain(self, leaf, &chain);
    LifecycleArgs_Compartment* comp = NULL;
    for (int i = 0; i < n; i++) {
        LifecycleArgs_Compartment* nc = LifecycleArgs_Compartment_new(chain[i]);
        if (state_args) {
            for (int j = 0; j < state_args->size; j++) LifecycleArgs_FrameVec_push(nc->state_args, state_args->items[j]);
        }
        if (enter_args) {
            for (int j = 0; j < enter_args->size; j++) LifecycleArgs_FrameVec_push(nc->enter_args, enter_args->items[j]);
        }
        nc->parent_compartment = comp;  // adopts ref
        comp = nc;
    }
    return comp;
}

static void LifecycleArgs_prepareExit(LifecycleArgs* self, LifecycleArgs_FrameVec* exit_args) {
    LifecycleArgs_Compartment* comp = self->__compartment;
    while (comp != NULL) {
        // Clear any prior exit_args before copying the new ones in.
        while (comp->exit_args->size > 0) comp->exit_args->size--;
        if (exit_args) {
            for (int j = 0; j < exit_args->size; j++) LifecycleArgs_FrameVec_push(comp->exit_args, exit_args->items[j]);
        }
        comp = comp->parent_compartment;
    }
}

static void LifecycleArgs_kernel(LifecycleArgs* self, LifecycleArgs_FrameEvent* __e) {
    LifecycleArgs_router(self, __e);
    while (self->__next_compartment != NULL) {
        LifecycleArgs_Compartment* next_compartment = self->__next_compartment;
        self->__next_compartment = NULL;
        // Exit the current (leaf) state
        LifecycleArgs_FrameEvent* __exit_event = LifecycleArgs_FrameEvent_new("<$", self->__compartment->exit_args, 0);
        LifecycleArgs_router(self, __exit_event);
        LifecycleArgs_FrameEvent_destroy(__exit_event);
        LifecycleArgs_Compartment_unref(self->__compartment);
        self->__compartment = next_compartment;
        if (next_compartment->forward_event == NULL) {
            // No forwarded event — synthesize a fresh $>
            LifecycleArgs_FrameEvent* __enter_event = LifecycleArgs_FrameEvent_new("$>", self->__compartment->enter_args, 0);
            LifecycleArgs_router(self, __enter_event);
            LifecycleArgs_FrameEvent_destroy(__enter_event);
        } else if (strcmp(next_compartment->forward_event->_message, "$>") == 0) {
            // Forwarded event IS $> — dispatch directly so the
            // destination's $> handler receives the caller's payload.
            // The forward_event is borrowed (owned by the wrapper that
            // queued the transition) — do NOT destroy it here.
            LifecycleArgs_FrameEvent* forward_event = next_compartment->forward_event;
            next_compartment->forward_event = NULL;
            LifecycleArgs_router(self, forward_event);
        } else {
            // Forwarded event is not $> — initialize the destination
            // with a fresh $>, then dispatch the forward to it. The
            // forward_event is borrowed; only the synthesized $> belongs
            // to the kernel and is freed here.
            LifecycleArgs_FrameEvent* forward_event = next_compartment->forward_event;
            next_compartment->forward_event = NULL;
            LifecycleArgs_FrameEvent* __enter_event = LifecycleArgs_FrameEvent_new("$>", self->__compartment->enter_args, 0);
            LifecycleArgs_router(self, __enter_event);
            LifecycleArgs_FrameEvent_destroy(__enter_event);
            LifecycleArgs_router(self, forward_event);
        }
        // Mark every stacked context as having transitioned. Read by
        // @@:self.X() guard so outer self-calls short-circuit.
        for (int __i = 0; __i < self->_context_stack->size; __i++) {
            ((LifecycleArgs_FrameContext*)self->_context_stack->items[__i])->_transitioned = 1;
        }
    }
}

static void LifecycleArgs_router(LifecycleArgs* self, LifecycleArgs_FrameEvent* __e) {
    if (strcmp(self->__compartment->state, "Idle") == 0) {
        LifecycleArgs_state_Idle(self, __e, self->__compartment);
    } else if (strcmp(self->__compartment->state, "Active") == 0) {
        LifecycleArgs_state_Active(self, __e, self->__compartment);
    }
}

static void LifecycleArgs_transition(LifecycleArgs* self, LifecycleArgs_Compartment* next_compartment) {
    self->__next_compartment = next_compartment;
}

void LifecycleArgs_destroy(LifecycleArgs* self) {
    // Unref current compartment (may free if not on stack)
    if (self->__compartment) LifecycleArgs_Compartment_unref(self->__compartment);
    if (self->__next_compartment) LifecycleArgs_Compartment_unref(self->__next_compartment);
    // Unref all state stack entries
    if (self->_state_stack) {
        for (int __i = 0; __i < self->_state_stack->size; __i++) {
            LifecycleArgs_Compartment_unref((LifecycleArgs_Compartment*)self->_state_stack->items[__i]);
        }
        LifecycleArgs_FrameVec_destroy(self->_state_stack);
    }
    if (self->_context_stack) LifecycleArgs_FrameVec_destroy(self->_context_stack);
    free(self);
}

void LifecycleArgs_load(LifecycleArgs* self, int n, char* label) {
    LifecycleArgs_FrameVec* __params = LifecycleArgs_FrameVec_new();
    LifecycleArgs_FrameVec_push(__params, (void*)(intptr_t)n);
    LifecycleArgs_FrameVec_push(__params, (void*)(intptr_t)label);
    LifecycleArgs_FrameEvent* __e = LifecycleArgs_FrameEvent_new("load", __params, 1);
    LifecycleArgs_FrameContext* __ctx = LifecycleArgs_FrameContext_new(__e, NULL);
    LifecycleArgs_FrameVec_push(self->_context_stack, __ctx);
    LifecycleArgs_kernel(self, __e);
    LifecycleArgs_FrameContext* __result_ctx = (LifecycleArgs_FrameContext*)LifecycleArgs_FrameVec_pop(self->_context_stack);
    LifecycleArgs_FrameContext_destroy(__result_ctx);
    LifecycleArgs_FrameEvent_destroy(__e);
}

int LifecycleArgs_total(LifecycleArgs* self) {
    LifecycleArgs_FrameEvent* __e = LifecycleArgs_FrameEvent_new("total", NULL, 0);
    LifecycleArgs_FrameContext* __ctx = LifecycleArgs_FrameContext_new(__e, NULL);
    LifecycleArgs_FrameVec_push(self->_context_stack, __ctx);
    LifecycleArgs_kernel(self, __e);
    LifecycleArgs_FrameContext* __result_ctx = (LifecycleArgs_FrameContext*)LifecycleArgs_FrameVec_pop(self->_context_stack);
    int __result = (int)(intptr_t)__result_ctx->_return;
    LifecycleArgs_FrameContext_destroy(__result_ctx);
    LifecycleArgs_FrameEvent_destroy(__e);
    return __result;
}

char* LifecycleArgs_tag(LifecycleArgs* self) {
    LifecycleArgs_FrameEvent* __e = LifecycleArgs_FrameEvent_new("tag", NULL, 0);
    LifecycleArgs_FrameContext* __ctx = LifecycleArgs_FrameContext_new(__e, NULL);
    LifecycleArgs_FrameVec_push(self->_context_stack, __ctx);
    LifecycleArgs_kernel(self, __e);
    LifecycleArgs_FrameContext* __result_ctx = (LifecycleArgs_FrameContext*)LifecycleArgs_FrameVec_pop(self->_context_stack);
    char* __result = (char*)__result_ctx->_return;
    LifecycleArgs_FrameContext_destroy(__result_ctx);
    LifecycleArgs_FrameEvent_destroy(__e);
    return __result;
}

static void LifecycleArgs_state_Idle(LifecycleArgs* self, LifecycleArgs_FrameEvent* __e, LifecycleArgs_Compartment* compartment) {
    if (strcmp(__e->_message, "load") == 0) {
        LifecycleArgs_s_Idle_hdl_user_load(self, __e, compartment);
        return;
    }
}

static void LifecycleArgs_state_Active(LifecycleArgs* self, LifecycleArgs_FrameEvent* __e, LifecycleArgs_Compartment* compartment) {
    if (strcmp(__e->_message, "$>") == 0) {
        LifecycleArgs_s_Active_hdl_frame_enter(self, __e, compartment);
        return;
    }
    if (strcmp(__e->_message, "tag") == 0) {
        LifecycleArgs_s_Active_hdl_user_tag(self, __e, compartment);
        return;
    }
    if (strcmp(__e->_message, "total") == 0) {
        LifecycleArgs_s_Active_hdl_user_total(self, __e, compartment);
        return;
    }
}

static void LifecycleArgs_s_Idle_hdl_user_load(LifecycleArgs* self, LifecycleArgs_FrameEvent* __e, LifecycleArgs_Compartment* compartment) {
    int n = (int)(intptr_t)LifecycleArgs_FrameVec_get(__e->_parameters, 0);
    (void)n;
    const char* label = (const char*)LifecycleArgs_FrameVec_get(__e->_parameters, 1);
    (void)label;
    {
        LifecycleArgs_FrameVec* __sa = NULL;
        LifecycleArgs_FrameVec* __ea = LifecycleArgs_FrameVec_new();
        LifecycleArgs_FrameVec_push(__ea, (void*)(intptr_t)(n));
        LifecycleArgs_FrameVec_push(__ea, (void*)(intptr_t)(label));
        LifecycleArgs_Compartment* __compartment = LifecycleArgs_prepareEnter(self, "Active", __sa, __ea);
        LifecycleArgs_FrameVec_destroy(__ea);
        LifecycleArgs_transition(self, __compartment);
    }
    return;
}

static void LifecycleArgs_s_Active_hdl_frame_enter(LifecycleArgs* self, LifecycleArgs_FrameEvent* __e, LifecycleArgs_Compartment* compartment) {
    int count = (int)(intptr_t)LifecycleArgs_FrameVec_get(compartment->enter_args, 0);
    (void)count;
    const char* name = (const char*)LifecycleArgs_FrameVec_get(compartment->enter_args, 1);
    (void)name;
    self.sum = count + 1;
    self.label = name;
}

static void LifecycleArgs_s_Active_hdl_user_tag(LifecycleArgs* self, LifecycleArgs_FrameEvent* __e, LifecycleArgs_Compartment* compartment) {
    LifecycleArgs_CTX(self)->_return = (void*)(intptr_t)(self.label);
                    return
}

static void LifecycleArgs_s_Active_hdl_user_total(LifecycleArgs* self, LifecycleArgs_FrameEvent* __e, LifecycleArgs_Compartment* compartment) {
    LifecycleArgs_CTX(self)->_return = (void*)(intptr_t)(self.sum);
                    return
}
