// File: luooofan[P]hblzbd_compiler/src/arm.cpp
// Function: arm::LdrPseudo::EmitCode(std::ostream&)
void LdrPseudo::EmitCode(std::ostream& outfile) {
  // convert ldr-pseudo inst to movw&movt
  // https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/how-to-load-constants-in-assembly-for-arm-architecture
  if (!this->is_imm_) {
    outfile << "\tmov32 " << CondToString(this->cond_) << ", " << std::string(*(this->rd_)) + ", " << this->literal_
            << std::endl;
  } else if (0 == ((this->imm_ >> 16) & 0xFFFF)) {
    outfile << "\tmovw" << CondToString(this->cond_) << " " << std::string(*(this->rd_)) + ", #"
            << (this->imm_ & 0xFFFF) << std::endl;
  } else {
    outfile << "\tmov32 " << CondToString(this->cond_) << ", " << std::string(*(this->rd_)) + ", " << this->imm_
            << std::endl;
  }
  // outfile << "\tmov32 " << std::string(*(this->rd_)) << ", "
  //         << (this->is_imm_ ? std::to_string(this->imm_) : this->literal_) << std::endl;
}

// Assembly:
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rdi, 0x1d0(%rsp)
movq %rsi, 0x1c8(%rsp)
movq 0x1d0(%rsp), %rax
movq %rax, 0x90(%rsp)
testb $0x1, 0x44(%rax)
jne 0xbe5e
movq 0x1c8(%rsp), %rdi
leaq 0xee492(%rip), %rsi     # 0xfa172
callq 0x8330
movq %rax, %rcx
movq 0x90(%rsp), %rax
movq %rcx, 0x78(%rsp)
movl 0x10(%rax), %esi
leaq 0x1a8(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0x9ab0
movq 0x78(%rsp), %rdi
movq 0x80(%rsp), %rsi
callq 0x8310
movq %rax, 0x88(%rsp)
jmp 0xbd29
movq 0x88(%rsp), %rdi
leaq 0xee437(%rip), %rsi     # 0xfa16f
callq 0x8330
movq %rax, 0x70(%rsp)
jmp 0xbd44
movq 0x90(%rsp), %rax
movq 0x18(%rax), %rsi
leaq 0x158(%rsp), %rdi
callq 0xc8f0
jmp 0xbd5f
leaq 0xee409(%rip), %rdx     # 0xfa16f
leaq 0x178(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0xcbd0
jmp 0xbd7d
movq 0x70(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x8310
movq %rax, 0x68(%rsp)
jmp 0xbd96
movq 0x68(%rsp), %rdi
movq 0x90(%rsp), %rsi
addq $0x20, %rsi
callq 0x8310
movq %rax, 0x60(%rsp)
jmp 0xbdb3
movq 0x60(%rsp), %rdi
movq 0x1401c1(%rip), %rsi    # 0x14bf80
callq 0x8380
jmp 0xbdc6
leaq 0x178(%rsp), %rdi
callq 0x8728
leaq 0x158(%rsp), %rdi
callq 0x8728
leaq 0x1a8(%rsp), %rdi
callq 0x8728
jmp 0xc177
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0xbe4c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0xbe3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
leaq 0x178(%rsp), %rdi
callq 0x8728
leaq 0x158(%rsp), %rdi
callq 0x8728
leaq 0x1a8(%rsp), %rdi
callq 0x8728
jmp 0xc17f
movq 0x90(%rsp), %rax
movl 0x40(%rax), %ecx
sarl $0x10, %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
xorl %eax, %eax
cmpl %ecx, %eax
jne 0xbffd
movq 0x1c8(%rsp), %rdi
leaq 0xee2ef(%rip), %rsi     # 0xfa17a
callq 0x8330
movq %rax, %rcx
movq 0x90(%rsp), %rax
movq %rcx, 0x48(%rsp)
movl 0x10(%rax), %esi
leaq 0x138(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x9ab0
movq 0x48(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x8310
movq %rax, 0x58(%rsp)
jmp 0xbecb
movq 0x58(%rsp), %rdi
leaq 0xee47e(%rip), %rsi     # 0xfa355
callq 0x8330
movq %rax, 0x40(%rsp)
jmp 0xbee3
movq 0x90(%rsp), %rax
movq 0x18(%rax), %rsi
leaq 0xf8(%rsp), %rdi
callq 0xc8f0
jmp 0xbefe
leaq 0xee27b(%rip), %rdx     # 0xfa180
leaq 0x118(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0xcbd0
jmp 0xbf1c
movq 0x40(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x8310
movq %rax, 0x38(%rsp)
jmp 0xbf35
movq 0x38(%rsp), %rdi
movq 0x90(%rsp), %rax
movzwl 0x40(%rax), %esi
callq 0x8650
movq %rax, 0x30(%rsp)
jmp 0xbf52
movq 0x30(%rsp), %rdi
movq 0x140022(%rip), %rsi    # 0x14bf80
callq 0x8380
jmp 0xbf65
leaq 0x118(%rsp), %rdi
callq 0x8728
leaq 0xf8(%rsp), %rdi
callq 0x8728
leaq 0x138(%rsp), %rdi
callq 0x8728
jmp 0xc175
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0xbfeb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0xbfde
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x8728
leaq 0xf8(%rsp), %rdi
callq 0x8728
leaq 0x138(%rsp), %rdi
callq 0x8728
jmp 0xc17f
movq 0x1c8(%rsp), %rdi
leaq 0xee166(%rip), %rsi     # 0xfa172
callq 0x8330
movq %rax, %rcx
movq 0x90(%rsp), %rax
movq %rcx, 0x18(%rsp)
movl 0x10(%rax), %esi
leaq 0xd8(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x9ab0
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x8310
movq %rax, 0x28(%rsp)
jmp 0xc04c
movq 0x28(%rsp), %rdi
leaq 0xee117(%rip), %rsi     # 0xfa16f
callq 0x8330
movq %rax, 0x10(%rsp)
jmp 0xc064
movq 0x90(%rsp), %rax
movq 0x18(%rax), %rsi
leaq 0x98(%rsp), %rdi
callq 0xc8f0
jmp 0xc07f
leaq 0xee0e9(%rip), %rdx     # 0xfa16f
leaq 0xb8(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0xcbd0
jmp 0xc09d
movq 0x10(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x8310
movq %rax, 0x8(%rsp)
jmp 0xc0b6
movq 0x8(%rsp), %rdi
movq 0x90(%rsp), %rax
movl 0x40(%rax), %esi
callq 0x8650
movq %rax, (%rsp)
jmp 0xc0d1
movq (%rsp), %rdi
movq 0x13fea4(%rip), %rsi    # 0x14bf80
callq 0x8380
jmp 0xc0e3
leaq 0xb8(%rsp), %rdi
callq 0x8728
leaq 0x98(%rsp), %rdi
callq 0x8728
leaq 0xd8(%rsp), %rdi
callq 0x8728
jmp 0xc175
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0xc166
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0xc159
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x8728
leaq 0x98(%rsp), %rdi
callq 0x8728
leaq 0xd8(%rsp), %rdi
callq 0x8728
jmp 0xc17f
jmp 0xc177
addq $0x1d8, %rsp            # imm = 0x1D8
retq
movq 0x1a0(%rsp), %rdi
callq 0x8670
nopl (%rax)