// File: /workspace/github_c_makefile_star2_O2/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
testq %rdi, %rdi
je 0xbb2d
movl 0x14(%rdi), %eax
cmpl $0x2, %eax
jb 0xbb32
je 0xbb6a
cmpl $0x3, %eax
jne 0xbb30
movq %rcx, %r9
movl 0x18(%rdi), %eax
leaq 0x90f3(%rip), %rcx      # 0x14be0
movl (%rcx,%rax,4), %r10d
movq 0x30(%rdi), %rcx
movl 0x28(%rcx), %r11d
movq 0x38(%rdi), %rcx
cmpl $0x2, 0x14(%rcx)
jne 0xbbbd
movl 0x30(%rcx), %r9d
testb %dl, %dl
je 0xbc2a
imulq $0xa, %rax, %rax
leaq 0xe3b2(%rip), %rcx      # 0x19ed0
addq %rax, %rcx
decl %r9d
imull %r10d, %r9d
addl %r11d, %r9d
jmp 0xbb4b
movb $0x0, (%rsi)
popq %rbp
retq
testb %dl, %dl
je 0xbb9a
movl 0x18(%rdi), %eax
movl 0x28(%rdi), %r9d
imulq $0xa, %rax, %rax
leaq 0xe388(%rip), %rcx      # 0x19ed0
addq %rax, %rcx
leaq 0x32e4(%rip), %rdx      # 0xee36
leaq 0x3173(%rip), %r8       # 0xeccc
pushq $0x1e
popq %rax
movq %rsi, %rdi
movq %rax, %rsi
xorl %eax, %eax
popq %rbp
jmp 0x30c0
movl 0x18(%rdi), %eax
cmpl $0x2, %eax
je 0xbbfd
cmpl $0x1, %eax
jne 0xbc1a
movl 0x30(%rdi), %ecx
leaq 0x1ebf(%rip), %rdx      # 0xda48
pushq $0x1e
popq %rax
movq %rsi, %rdi
movq %rax, %rsi
xorl %eax, %eax
popq %rbp
jmp 0x30c0
movl 0x28(%rdi), %r8d
leaq 0x3294(%rip), %rdx      # 0xee39
leaq 0x3120(%rip), %rcx      # 0xeccc
pushq $0x1e
popq %rax
movq %rsi, %rdi
movq %rax, %rsi
xorl %eax, %eax
popq %rbp
jmp 0x30c0
testb %dl, %dl
je 0xbc53
imulq $0xa, %rax, %rax
leaq 0xe300(%rip), %rcx      # 0x19ed0
addq %rax, %rcx
subl %r10d, %r11d
leaq 0x3266(%rip), %rdx      # 0xee43
leaq 0x30e8(%rip), %r8       # 0xeccc
pushq $0x1e
popq %rax
movq %rsi, %rdi
movq %rax, %rsi
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x30c0
jmp 0xbc80
movsd 0x30(%rdi), %xmm0
leaq 0x1f07(%rip), %rdx      # 0xdb10
pushq $0x1e
popq %rax
movq %rsi, %rdi
movq %rax, %rsi
movb $0x1, %al
popq %rbp
jmp 0x30c0
movb 0x30(%rdi), %al
orb $0x30, %al
movb %al, (%rsi)
movb $0x0, 0x1(%rsi)
jmp 0xbb30
decl %r9d
imull %r10d, %r9d
addl %r11d, %r9d
leaq 0x31fe(%rip), %rdx      # 0xee39
leaq 0x308a(%rip), %rcx      # 0xeccc
pushq $0x1e
popq %rax
movq %rsi, %rdi
movq %rax, %rsi
movl %r9d, %r8d
jmp 0xbbb5
subl %r10d, %r11d
subq $0x8, %rsp
leaq 0x31e5(%rip), %rdx      # 0xee46
leaq 0x3064(%rip), %rcx      # 0xeccc
pushq $0x1e
popq %rax
movq %rsi, %rdi
movq %rax, %rsi
movq %r9, %r8
movl %r10d, %r9d
xorl %eax, %eax
pushq %r11
callq 0x30c0
popq %rcx
popq %rdx
jmp 0xbb30