// File: /workspace/github_c_makefile_star2_O3/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 0xcac5
movq %rcx, %r9
movl 0x14(%rdi), %ecx
cmpl $0x2, %ecx
jb 0xcaca
je 0xcb02
cmpl $0x3, %ecx
jne 0xcac8
movl 0x18(%rdi), %ecx
leaq 0x915c(%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 0xcb53
movl 0x30(%rsi), %r9d
testb %dl, %dl
je 0xcbc0
leaq (%rcx,%rcx,4), %rcx
leaq 0xe41b(%rip), %rdx      # 0x1aed0
leaq (%rdx,%rcx,2), %rcx
decl %r9d
imull %r10d, %r9d
addl %r11d, %r9d
jmp 0xcae4
movb $0x0, (%rax)
popq %rbp
retq
testb %dl, %dl
je 0xcb31
movl 0x18(%rdi), %ecx
movl 0x28(%rdi), %r9d
leaq (%rcx,%rcx,4), %rcx
leaq 0xe3f0(%rip), %rdx      # 0x1aed0
leaq (%rdx,%rcx,2), %rcx
leaq 0x334b(%rip), %rdx      # 0xfe36
leaq 0x31da(%rip), %r8       # 0xfccc
movl $0x1e, %esi
movq %rax, %rdi
xorl %eax, %eax
popq %rbp
jmp 0x30c0
movl 0x18(%rdi), %ecx
cmpl $0x2, %ecx
je 0xcb93
cmpl $0x1, %ecx
jne 0xcbaf
movl 0x30(%rdi), %ecx
leaq 0x1f27(%rip), %rdx      # 0xea48
movl $0x1e, %esi
movq %rax, %rdi
xorl %eax, %eax
popq %rbp
jmp 0x30c0
movl 0x28(%rdi), %r8d
leaq 0x32fd(%rip), %rdx      # 0xfe39
leaq 0x3189(%rip), %rcx      # 0xfccc
movl $0x1e, %esi
movq %rax, %rdi
xorl %eax, %eax
popq %rbp
jmp 0x30c0
testb %dl, %dl
je 0xcbe8
leaq (%rcx,%rcx,4), %rcx
leaq 0xe36a(%rip), %rdx      # 0x1aed0
leaq (%rdx,%rcx,2), %rcx
subl %r10d, %r11d
leaq 0x32cf(%rip), %rdx      # 0xfe43
leaq 0x3151(%rip), %r8       # 0xfccc
movl $0x1e, %esi
movq %rax, %rdi
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x30c0
jmp 0xcc14
movsd 0x30(%rdi), %xmm0
leaq 0x1f71(%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 0xcac8
decl %r9d
imull %r10d, %r9d
addl %r11d, %r9d
leaq 0x3268(%rip), %rdx      # 0xfe39
leaq 0x30f4(%rip), %rcx      # 0xfccc
movl $0x1e, %esi
movq %rax, %rdi
movl %r9d, %r8d
jmp 0xcb4b
subl %r10d, %r11d
subq $0x8, %rsp
leaq 0x3250(%rip), %rdx      # 0xfe46
leaq 0x30cf(%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 0xcac8