// File: /workspace/github_cpp_makefile_star2_O3/luooofan[P]hblzbd_compiler/src/Pass/generate_arm_from_ssa.cpp
// Function: GenerateArmFromSSA::ResolveImm2Reg(ArmBasicBlock*, int, bool)
Reg* GenerateArmFromSSA::ResolveImm2Reg(ArmBasicBlock* armbb, int imm, bool record) {
  auto vreg = NewVirtualReg();
  Instruction* inst = nullptr;
  if (Operand2::CheckImm8m(imm)) {
    // NOTE: 寄存器分配后立即数值可能会变
    inst = new Move(vreg, new Operand2(imm), armbb);
  } else {
    if (imm < 0 && Operand2::CheckImm8m(-imm - 1)) {  // mvn
      inst = new Move(vreg, new Operand2(-imm - 1), armbb, true);
    } else {  // use ldr pseudo-inst instead of mov.
      inst = new LdrPseudo(vreg, imm, armbb);
    }
  }
  MyAssert(nullptr != inst);
  if (record) {
    this->sp_fixup.insert(inst);
  }
  return vreg;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %ebp
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, %r14
movl $0x40, %edi
callq 0x8290
movq %rax, %rbx
movl 0x50(%r14), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x50(%r14)
leaq 0x30(%rbx), %rcx
movq %rcx, (%rbx)
movq $0x1, 0x8(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbx)
movl $0x3f800000, 0x20(%rbx) # imm = 0x3F800000
movups %xmm0, 0x28(%rbx)
movl %eax, 0x38(%rbx)
movl %r12d, %edi
callq 0xa3cc
testb %al, %al
je 0x4c0dd
movl %ebp, 0x4(%rsp)
movl $0x28, %edi
callq 0x8290
movq %rax, %r13
movl $0x18, %edi
callq 0x8290
movq %rax, %rbp
movb $0x1, (%rax)
movl %r12d, 0x4(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movq %r13, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0xa41e
leaq 0x4143e(%rip), %rax     # 0x8d4f0
leaq 0x10(%rax), %rcx
movq %rcx, (%r13)
movw $0x0, 0x14(%r13)
movq %rbx, 0x18(%r13)
movq %rbp, 0x20(%r13)
movq %r13, %rdi
callq *0x28(%rax)
movq %r13, 0x8(%rsp)
movl 0x4(%rsp), %ebp
jmp 0x4c1b7
testl %r12d, %r12d
jns 0x4c161
movl %r12d, %r13d
notl %r13d
movl %r13d, %edi
callq 0xa3cc
testb %al, %al
je 0x4c161
movl %ebp, 0x4(%rsp)
movl $0x28, %edi
callq 0x8290
movq %rax, %r12
movl $0x18, %edi
callq 0x8290
movq %rax, %rbp
movb $0x1, (%rax)
movl %r13d, 0x4(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movq %r12, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0xa41e
leaq 0x413b9(%rip), %rax     # 0x8d4f0
leaq 0x10(%rax), %rcx
movq %rcx, (%r12)
movw $0x1, 0x14(%r12)
movq %rbx, 0x18(%r12)
movq %rbp, 0x20(%r12)
movq %r12, %rdi
callq *0x28(%rax)
movq %r12, 0x8(%rsp)
jmp 0x4c0d4
movl $0x48, %edi
callq 0x8290
movq %rax, %r13
movq %rax, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0xa41e
leaq 0x4127b(%rip), %rax     # 0x8d400
addq $0x10, %rax
movq %rax, (%r13)
movq %rbx, 0x18(%r13)
movq %r13, %rax
addq $0x30, %rax
movq %rax, 0x20(%r13)
movq $0x0, 0x28(%r13)
movb $0x0, 0x30(%r13)
movl %r12d, 0x40(%r13)
movb $0x1, 0x44(%r13)
movq %r13, 0x8(%rsp)
testb %bpl, %bpl
je 0x4c1d8
addq $0xd0, %r14
leaq 0x10(%rsp), %rdx
movq %r14, (%rdx)
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0xc426
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x28, %esi
movq %r12, %rdi
jmp 0x4c20c
movq %rax, %rbx
movl $0x48, %esi
jmp 0x4c209
movq %rax, %rbx
movl $0x28, %esi
movq %r13, %rdi
callq 0x82a0
movq %rbx, %rdi
callq 0x8540
nop