// File: /workspace/github_c_makefile_star2_O1/sharmaeklavya2[P]cerplag/compile_x86.c
// Function: addr_to_x86_arg
void addr_to_x86_arg(const AddrNode* an, char* dest, bool add_size, const char* index_reg) {
    if(an == NULL) {
        dest[0] = '\0';
        return;
    }
    switch(an->addr_type) {
        case ADDR_VAR:
        case ADDR_TEMP:
            if(add_size) {
                snprintf(dest, X86_ARG_SIZE, "%s [%s + %d]", std_size_name[an->type],
                    DATA_REG, an->offset);
            }
            else {
                snprintf(dest, X86_ARG_SIZE, "[%s + %d]", DATA_REG, an->offset);
            }
            break;
        case ADDR_CONST:
            if(an->type == TYPE_INTEGER) {
                snprintf(dest, X86_ARG_SIZE, "%d", an->imm.i);
            }
            else if(an->type == TYPE_REAL) {
                snprintf(dest, X86_ARG_SIZE, "%lf", an->imm.f);
            }
            else {
                snprintf(dest, X86_ARG_SIZE, "%c", (an->imm.b)?'1':'0');
            }
            break;
        case ADDR_ARR: {
            int size = TYPE_SIZES[an->type];
            int base_addr = an->base_addr->offset;
            if(an->index->addr_type == ADDR_CONST) {
                int i = an->index->imm.i;
                if(add_size) {
                    snprintf(dest, X86_ARG_SIZE, "%s [%s + %d]", std_size_name[an->type],
                        DATA_REG, base_addr + size * (i-1));
                }
                else {
                    snprintf(dest, X86_ARG_SIZE, "[%s + %d]", DATA_REG, base_addr + size * (i-1));
                }
            }
            else if(add_size) {
                snprintf(dest, X86_ARG_SIZE, "%s [%s + %s*%d + %d]", std_size_name[an->type],
                    DATA_REG, index_reg, size, base_addr - size);
            }
            else {
                snprintf(dest, X86_ARG_SIZE, "[%s + %s*%d + %d]", DATA_REG, index_reg,
                    size, base_addr - size);
            }
            break;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rsi, %rax
testq %rdi, %rdi
je 0xcb4d
movq %rcx, %r9
movl 0x14(%rdi), %ecx
cmpl $0x2, %ecx
jb 0xcb52
je 0xcb8a
cmpl $0x3, %ecx
jne 0xcb50
movl 0x18(%rdi), %ecx
leaq 0x90d4(%rip), %rsi      # 0x15be0
movl (%rsi,%rcx,4), %r10d
movq 0x30(%rdi), %rsi
movl 0x28(%rsi), %r11d
movq 0x38(%rdi), %rsi
cmpl $0x2, 0x14(%rsi)
jne 0xcbdb
movl 0x30(%rsi), %r9d
testb %dl, %dl
je 0xcc48
leaq (%rcx,%rcx,4), %rcx
leaq 0xe393(%rip), %rdx      # 0x1aed0
leaq (%rdx,%rcx,2), %rcx
decl %r9d
imull %r10d, %r9d
addl %r11d, %r9d
jmp 0xcb6c
movb $0x0, (%rax)
popq %rbp
retq
testb %dl, %dl
je 0xcbb9
movl 0x18(%rdi), %ecx
movl 0x28(%rdi), %r9d
leaq (%rcx,%rcx,4), %rcx
leaq 0xe368(%rip), %rdx      # 0x1aed0
leaq (%rdx,%rcx,2), %rcx
leaq 0x32c3(%rip), %rdx      # 0xfe36
leaq 0x3152(%rip), %r8       # 0xfccc
movl $0x1e, %esi
movq %rax, %rdi
xorl %eax, %eax
popq %rbp
jmp 0x30c0
movl 0x18(%rdi), %ecx
cmpl $0x2, %ecx
je 0xcc1b
cmpl $0x1, %ecx
jne 0xcc37
movl 0x30(%rdi), %ecx
leaq 0x1e9f(%rip), %rdx      # 0xea48
movl $0x1e, %esi
movq %rax, %rdi
xorl %eax, %eax
popq %rbp
jmp 0x30c0
movl 0x28(%rdi), %r8d
leaq 0x3275(%rip), %rdx      # 0xfe39
leaq 0x3101(%rip), %rcx      # 0xfccc
movl $0x1e, %esi
movq %rax, %rdi
xorl %eax, %eax
popq %rbp
jmp 0x30c0
testb %dl, %dl
je 0xcc70
leaq (%rcx,%rcx,4), %rcx
leaq 0xe2e2(%rip), %rdx      # 0x1aed0
leaq (%rdx,%rcx,2), %rcx
subl %r10d, %r11d
leaq 0x3247(%rip), %rdx      # 0xfe43
leaq 0x30c9(%rip), %r8       # 0xfccc
movl $0x1e, %esi
movq %rax, %rdi
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x30c0
jmp 0xcc9c
movsd 0x30(%rdi), %xmm0
leaq 0x1ee9(%rip), %rdx      # 0xeb10
movl $0x1e, %esi
movq %rax, %rdi
movb $0x1, %al
popq %rbp
jmp 0x30c0
movb 0x30(%rdi), %cl
orb $0x30, %cl
movb %cl, (%rax)
movb $0x0, 0x1(%rax)
jmp 0xcb50
decl %r9d
imull %r10d, %r9d
addl %r11d, %r9d
leaq 0x31e0(%rip), %rdx      # 0xfe39
leaq 0x306c(%rip), %rcx      # 0xfccc
movl $0x1e, %esi
movq %rax, %rdi
movl %r9d, %r8d
jmp 0xcbd3
subl %r10d, %r11d
subq $0x8, %rsp
leaq 0x31c8(%rip), %rdx      # 0xfe46
leaq 0x3047(%rip), %rcx      # 0xfccc
movl $0x1e, %esi
movq %rax, %rdi
movq %r9, %r8
movl %r10d, %r9d
xorl %eax, %eax
pushq %r11
callq 0x30c0
addq $0x10, %rsp
jmp 0xcb50