// File: /workspace/github_c_makefile_star2_O0/cogbee[P]vmir-latest/src/vmir_wasm_parser.c
// Function: wasm_parse_section_global
static void
wasm_parse_section_global(ir_unit_t *iu, wasm_bytestream_t *wbs)
{
  uint32_t count = wbs_get_vu32(wbs);
  for(uint32_t i = 0; i < count; i++) {
    const int pointee_type = wasm_parse_value_type(iu, wbs);
    const int pointer_type = type_make_pointer(iu, pointee_type, 1);
    const uint32_t mutable = wbs_get_vu32(wbs);

    // cogbee
    const int val_id = value_create_global(iu, pointee_type, pointer_type, 0, 0, 0);
    const ir_valuetype_t vt = { val_id, pointer_type };
    VECTOR_PUSH_BACK(&iu->iu_wasm_globalvar_map, vt);

    parse_init_expr(iu, wbs); // Will leave value on vstack
    const ir_initializer_t ii = {val_id, vstack_pop(iu).value};
    VECTOR_PUSH_BACK(&iu->iu_initializers, ii);
    printf("Global var %s (globaindex: %zd) mutable=%d\n",
           value_str_id(iu, val_id),
           VECTOR_LEN(&iu->iu_wasm_globalvar_map) - 1, mutable);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1d450
movl %eax, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x1de4b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x1e260
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl $0x1, %edx
callq 0x1e6e0
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1d450
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl -0x20(%rbp), %edx
xorl %r9d, %r9d
movl %r9d, %ecx
movl %r9d, %r8d
callq 0x1e840
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movq 0x5a0(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq -0x8(%rbp), %rcx
cmpq 0x5a8(%rcx), %rax
jbe 0x1dd25
movq -0x38(%rbp), %rcx
addq $0x1, %rcx
shlq %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x5a8(%rax)
movq -0x8(%rbp), %rax
movq 0x5a8(%rax), %rax
shlq $0x3, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x598(%rax), %rdi
movq -0x40(%rbp), %rsi
callq 0x3390
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x598(%rax)
movq -0x38(%rbp), %rcx
addq $0x1, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x5a0(%rax)
movq -0x8(%rbp), %rax
movq 0x598(%rax), %rax
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x1e960
movl -0x28(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1ea10
movq %rax, -0x50(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rax
movq 0x2f8(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq -0x8(%rbp), %rcx
cmpq 0x300(%rcx), %rax
jbe 0x1dde4
movq -0x58(%rbp), %rcx
addq $0x1, %rcx
shlq %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x300(%rax)
movq -0x8(%rbp), %rax
movq 0x300(%rax), %rax
shlq $0x3, %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x2f0(%rax), %rdi
movq -0x60(%rbp), %rsi
callq 0x3390
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x2f0(%rax)
movq -0x58(%rbp), %rcx
addq $0x1, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x2f8(%rax)
movq -0x8(%rbp), %rax
movq 0x2f0(%rax), %rax
movq -0x58(%rbp), %rcx
movq -0x48(%rbp), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rdi
movl -0x28(%rbp), %esi
callq 0x1ea80
movq %rax, %rsi
movq -0x8(%rbp), %rax
movq 0x5a0(%rax), %rdx
subq $0x1, %rdx
movl -0x24(%rbp), %ecx
leaq 0x20e4e(%rip), %rdi     # 0x3ec84
movb $0x0, %al
callq 0x3170
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1dc53
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)