// File: /workspace/github_c_makefile_star2_O0/cogbee[P]vmir-latest/src/vmir_wasm_parser.c
// Function: wasm_parse_section_type
static void
wasm_parse_section_type(ir_unit_t *iu, wasm_bytestream_t *wbs)
{
  ir_type_t it;
  uint32_t count = wbs_get_vu32(wbs);
  for(int i = 0; i < count; i++) {
    uint8_t form = wbs_get_byte(wbs);

    if(form != 0x60) {
      // Function type
      parser_error(iu, "Bad form 0x%x in type section", form);
    }
    const uint32_t param_count = wbs_get_vu32(wbs);
    it.it_code = IR_TYPE_FUNCTION;
    it.it_function.varargs = 0;
    it.it_function.num_parameters = param_count;
    it.it_function.parameters =
      malloc(it.it_function.num_parameters * sizeof(int));

    for(int i = 0; i < it.it_function.num_parameters; i++) {
      it.it_function.parameters[i] = wasm_parse_value_type(iu, wbs);
    }

    const uint32_t return_count = wbs_get_vu32(wbs);
    if(return_count > 1) {
      parser_error(iu, "Multiple return values not supported");
    }
    if(return_count == 0) {
      it.it_function.return_type = 0; // (void) is type #0


    } else {
      it.it_function.return_type = wasm_parse_value_type(iu, wbs);
    }
    VECTOR_PUSH_BACK(&iu->iu_wasm_type_map, iu->iu_types.vh_length);
    VECTOR_PUSH_BACK(&iu->iu_types, it);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1d450
movl %eax, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jae 0x1d7d0
movq -0x10(%rbp), %rdi
callq 0x1e210
movb %al, -0x41(%rbp)
movzbl -0x41(%rbp), %eax
cmpl $0x60, %eax
je 0x1d5c7
movq -0x8(%rbp), %rdi
movzbl -0x41(%rbp), %r8d
leaq 0x21228(%rip), %rsi     # 0x3e7dc
movl $0xd4, %edx
leaq 0x2124a(%rip), %rcx     # 0x3e80a
movb $0x0, %al
callq 0x18220
movq -0x10(%rbp), %rdi
callq 0x1d450
movl %eax, -0x48(%rbp)
movl $0xc, -0x38(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x24(%rbp)
movslq -0x24(%rbp), %rdi
shlq $0x2, %rdi
callq 0x3360
movq %rax, -0x30(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x1d62c
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x1e260
movl %eax, %edx
movq -0x30(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x1d5ff
movq -0x10(%rbp), %rdi
callq 0x1d450
movl %eax, -0x50(%rbp)
cmpl $0x1, -0x50(%rbp)
jbe 0x1d65c
movq -0x8(%rbp), %rdi
leaq 0x21193(%rip), %rsi     # 0x3e7dc
movl $0xe3, %edx
leaq 0x211d3(%rip), %rcx     # 0x3e828
movb $0x0, %al
callq 0x18220
cmpl $0x0, -0x50(%rbp)
jne 0x1d66b
movl $0x0, -0x28(%rbp)
jmp 0x1d67b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x1e260
movl %eax, -0x28(%rbp)
jmp 0x1d67d
movq -0x8(%rbp), %rax
movq 0x588(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq -0x8(%rbp), %rcx
cmpq 0x590(%rcx), %rax
jbe 0x1d6ec
movq -0x58(%rbp), %rcx
addq $0x1, %rcx
shlq %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x590(%rax)
movq -0x8(%rbp), %rax
movq 0x590(%rax), %rax
shlq $0x2, %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x580(%rax), %rdi
movq -0x60(%rbp), %rsi
callq 0x3390
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x580(%rax)
movq -0x58(%rbp), %rcx
addq $0x1, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x588(%rax)
movq -0x8(%rbp), %rax
movq 0x170(%rax), %rax
movl %eax, %edx
movq -0x8(%rbp), %rax
movq 0x580(%rax), %rax
movq -0x58(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x1d720
movq -0x8(%rbp), %rax
movq 0x170(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq -0x8(%rbp), %rcx
cmpq 0x178(%rcx), %rax
jbe 0x1d78c
movq -0x68(%rbp), %rcx
addq $0x1, %rcx
shlq %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x178(%rax)
movq -0x8(%rbp), %rax
imulq $0x28, 0x178(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rax
movq 0x168(%rax), %rdi
movq -0x70(%rbp), %rsi
callq 0x3390
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x168(%rax)
movq -0x68(%rbp), %rcx
addq $0x1, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x170(%rax)
movq -0x8(%rbp), %rax
movq 0x168(%rax), %rdi
imulq $0x28, -0x68(%rbp), %rax
addq %rax, %rdi
leaq -0x38(%rbp), %rsi
movl $0x28, %edx
callq 0x3330
jmp 0x1d7c2
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x1d583
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)