// File: /workspace/github_cpp_makefile_star2_O2/luooofan[P]hblzbd_compiler/src/Pass/generate_arm_from_ssa.cpp
// Function: GenerateArmFromSSA::GenImmLdrStrInst(ArmBasicBlock*, arm::LdrStr::OpKind, arm::Reg*, arm::Reg*, int, bool)
void GenerateArmFromSSA::GenImmLdrStrInst(ArmBasicBlock* armbb, LdrStr::OpKind opkind, Reg* rd, Reg* rn, int imm,
                                          bool record) {
  Instruction* inst = nullptr;
  if (record) {
    // NOTE: sp_arg_fixup待补充的最后的栈空间大小+被调用者保护的寄存器的总大小
    auto vreg = NewVirtualReg();
    inst = new LdrPseudo(Cond::AL, vreg, imm, armbb);
    new LdrStr(opkind, rd, rn, new Operand2(vreg), armbb);
    this->sp_arg_fixup.insert(inst);
  } else {
    if (LdrStr::CheckImm12(imm)) {
      new LdrStr(opkind, rd, rn, imm, armbb);
    } else {
      auto vreg = NewVirtualReg();
      if (Operand2::CheckImm8m(imm)) {  // mov
        new Move(vreg, new Operand2(imm), armbb);
      } else if (imm < 0 && Operand2::CheckImm8m(-imm - 1)) {  // mvn
        new Move(vreg, new Operand2(-imm - 1), armbb, true);
      } else {  // ldr-pseudo
        new LdrPseudo(vreg, imm, armbb);
      }
      new LdrStr(opkind, rd, rn, new Operand2(vreg), armbb);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, %r13d
movq %r8, %r15
movq %rcx, %rbp
movl %edx, 0xc(%rsp)
movq %rsi, %rbx
movq %rdi, %r12
cmpb $0x0, 0x60(%rsp)
je 0x3ce48
movq %rbp, 0x10(%rsp)
movq %r15, 0x18(%rsp)
movq %r12, %rdi
callq 0x3cb82
movq %rax, %r14
pushq $0x48
popq %rdi
callq 0x8250
movq %rax, %r15
pushq $0x1
popq %r9
movq %rax, %rdi
xorl %esi, %esi
movq %r14, %rdx
movl %r13d, %ecx
movq %rbx, %rbp
movq %rbx, %r8
callq 0x2d7b6
movq %r15, 0x20(%rsp)
pushq $0x40
popq %rdi
callq 0x8250
movq %rax, %r13
pushq $0x18
popq %rdi
callq 0x8250
movb $0x0, (%rax)
andl $0x0, 0x4(%rax)
movq %r14, 0x8(%rax)
andq $0x0, 0x10(%rax)
movl $0x1, (%rsp)
movq %r13, %rdi
movl 0xc(%rsp), %esi
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rcx
movq %rax, %r8
movq %rbp, %r9
callq 0x3fc68
addq $0x98, %r12
leaq 0x20(%rsp), %rsi
movq %r12, %rdi
callq 0xa66a
jmp 0x3cf8b
leal 0xfff(%r13), %eax
cmpl $0x1ffe, %eax           # imm = 0x1FFE
ja 0x3ce85
pushq $0x40
popq %rdi
callq 0x8250
movq %rax, %r14
movl $0x1, (%rsp)
movq %rax, %rdi
movl 0xc(%rsp), %esi
movq %rbp, %rdx
movq %r15, %rcx
movl %r13d, %r8d
movq %rbx, %r9
callq 0x3fcd2
jmp 0x3cf8b
movq %r12, %rdi
callq 0x3cb82
movq %rax, %r12
movl %r13d, %edi
callq 0x9374
testb %al, %al
je 0x3ced7
pushq $0x28
popq %rdi
callq 0x8250
movq %rax, %r14
pushq $0x18
popq %rdi
callq 0x8250
movb $0x1, (%rax)
movl %r13d, 0x4(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
pushq $0x1
popq %r9
movq %r14, %rdi
movq %r12, %rsi
movq %rax, %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x3fbc8
jmp 0x3cf49
testl %r13d, %r13d
jns 0x3cf29
movl %r13d, %r14d
notl %r14d
movl %r14d, %edi
callq 0x9374
testb %al, %al
je 0x3cf29
pushq $0x28
popq %rdi
callq 0x8250
movq %rax, %r13
pushq $0x18
popq %rdi
callq 0x8250
movb $0x1, (%rax)
movl %r14d, 0x4(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
pushq $0x1
popq %r8
movq %r13, %rdi
movq %r12, %rsi
movq %rax, %rdx
movq %rbx, %rcx
movl %r8d, %r9d
callq 0x3fbc8
jmp 0x3cf49
pushq $0x48
popq %rdi
callq 0x8250
movq %rax, %r14
pushq $0x1
popq %r8
movq %rax, %rdi
movq %r12, %rsi
movl %r13d, %edx
movq %rbx, %rcx
callq 0x3fc1c
pushq $0x40
popq %rdi
callq 0x8250
movq %rax, %r14
pushq $0x18
popq %rdi
callq 0x8250
movb $0x0, (%rax)
andl $0x0, 0x4(%rax)
movq %r12, 0x8(%rax)
andq $0x0, 0x10(%rax)
movl $0x1, (%rsp)
movq %r14, %rdi
movl 0xc(%rsp), %esi
movq %rbp, %rdx
movq %r15, %rcx
movq %rax, %r8
movq %rbx, %r9
callq 0x3fc68
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
pushq $0x28
jmp 0x3cfcc
movq %rax, %rbx
pushq $0x48
jmp 0x3cfb6
movq %rax, %rbx
pushq $0x28
jmp 0x3cfb6
jmp 0x3cfb1
movq %rax, %rbx
pushq $0x40
popq %rsi
movq %r14, %rdi
jmp 0x3cfd0
movq %rax, %rbx
pushq $0x48
popq %rsi
movq %r15, %rdi
jmp 0x3cfd0
movq %rax, %rbx
pushq $0x40
popq %rsi
movq %r13, %rdi
callq 0x8260
movq %rbx, %rdi
callq 0x84d0
nop