// File: /workspace/github_cpp_makefile_star2_O1/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, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %rbx
movb 0x60(%rsp), %al
movq $0x0, 0x18(%rsp)
testb %al, %al
je 0x4cf9d
movl $0x40, %edi
callq 0x8290
movq %rax, %r12
movl 0x50(%rbx), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x50(%rbx)
leaq 0x30(%r12), %rcx
movq %rcx, (%r12)
movq $0x1, 0x8(%r12)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r12)
movl $0x3f800000, 0x20(%r12) # imm = 0x3F800000
movups %xmm0, 0x28(%r12)
movl %eax, 0x38(%r12)
movl $0x48, %edi
callq 0x8290
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
movq %r15, %rdx
movl $0x1, %ecx
callq 0xa67a
leaq 0x41509(%rip), %rax     # 0x8e3d0
addq $0x10, %rax
movq %rax, (%r14)
movq %r12, 0x18(%r14)
movq %r14, %rax
addq $0x30, %rax
movq %rax, 0x20(%r14)
movq $0x0, 0x28(%r14)
movb $0x0, 0x30(%r14)
movl %r13d, 0x40(%r14)
movb $0x1, 0x44(%r14)
movq %r14, 0x18(%rsp)
movl $0x40, %edi
callq 0x8290
movq %rax, %r13
movl $0x18, %edi
callq 0x8290
movq %rax, %r14
movb $0x0, (%rax)
movl $0x0, 0x4(%rax)
movq %r12, 0x8(%rax)
movq $0x0, 0x10(%rax)
movq %r13, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0xa6a8
leaq 0x415f9(%rip), %rax     # 0x8e538
leaq 0x10(%rax), %rcx
movq %rcx, (%r13)
movl %ebp, 0x14(%r13)
movl $0x1, 0x18(%r13)
movq 0x8(%rsp), %rcx
movq %rcx, 0x20(%r13)
movq 0x10(%rsp), %rcx
movq %rcx, 0x28(%r13)
movb $0x0, 0x30(%r13)
movl $0xffffffff, 0x34(%r13) # imm = 0xFFFFFFFF
movq %r14, 0x38(%r13)
movq %r13, %rdi
callq *0x28(%rax)
addq $0x98, %rbx
leaq 0x20(%rsp), %rdx
movq %rbx, (%rdx)
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
callq 0xc724
jmp 0x4d204
leal 0xfff(%r13), %r14d
movl $0x40, %edi
callq 0x8290
movq %rax, %r12
cmpl $0x1ffe, %r14d          # imm = 0x1FFE
ja 0x4d01a
movq %r12, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0xa6a8
leaq 0x41567(%rip), %rax     # 0x8e538
leaq 0x10(%rax), %rcx
movq %rcx, (%r12)
movl %ebp, 0x14(%r12)
movl $0x1, 0x18(%r12)
movq 0x8(%rsp), %rcx
movq %rcx, 0x20(%r12)
movq 0x10(%rsp), %rcx
movq %rcx, 0x28(%r12)
movb $0x1, 0x30(%r12)
movl %r13d, 0x34(%r12)
movq $0x0, 0x38(%r12)
movq %r12, %rdi
callq *0x28(%rax)
jmp 0x4d204
movl 0x50(%rbx), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x50(%rbx)
movq %r12, %rcx
addq $0x30, %rcx
movq %rcx, (%r12)
movq $0x1, 0x8(%r12)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r12)
movl $0x3f800000, 0x20(%r12) # imm = 0x3F800000
movups %xmm0, 0x28(%r12)
movl %eax, 0x38(%r12)
movl %r13d, %edi
callq 0xa656
testb %al, %al
je 0x4d0bf
movl $0x28, %edi
callq 0x8290
movq %rax, %rbx
movl $0x18, %edi
callq 0x8290
movq %rax, %r14
movb $0x1, (%rax)
movl %r13d, 0x4(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movq %rbx, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0xa6a8
leaq 0x41421(%rip), %rax     # 0x8e4c0
leaq 0x10(%rax), %rcx
movq %rcx, (%rbx)
movw $0x0, 0x14(%rbx)
movq %r12, 0x18(%rbx)
movq %r14, 0x20(%rbx)
movq %rbx, %rdi
callq *0x28(%rax)
jmp 0x4d180
testl %r13d, %r13d
jns 0x4d132
movl %r13d, %r14d
notl %r14d
movl %r14d, %edi
callq 0xa656
testb %al, %al
je 0x4d132
movl $0x28, %edi
callq 0x8290
movq %rax, %rbx
movl $0x18, %edi
callq 0x8290
movq %rax, %r13
movb $0x1, (%rax)
movl %r14d, 0x4(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movq %rbx, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0xa6a8
leaq 0x413ab(%rip), %rax     # 0x8e4c0
leaq 0x10(%rax), %rcx
movq %rcx, (%rbx)
movw $0x1, 0x14(%rbx)
movq %r12, 0x18(%rbx)
movq %r13, 0x20(%rbx)
movq %rbx, %rdi
callq *0x28(%rax)
jmp 0x4d180
movl $0x48, %edi
callq 0x8290
movq %rax, %rbx
movq %rax, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0xa6a8
leaq 0x4127a(%rip), %rax     # 0x8e3d0
addq $0x10, %rax
movq %rax, (%rbx)
movq %r12, 0x18(%rbx)
movq %rbx, %rax
addq $0x30, %rax
movq %rax, 0x20(%rbx)
movq $0x0, 0x28(%rbx)
movb $0x0, 0x30(%rbx)
movl %r13d, 0x40(%rbx)
movb $0x1, 0x44(%rbx)
movl $0x40, %edi
callq 0x8290
movq %rax, %r13
movl $0x18, %edi
callq 0x8290
movq %rax, %rbx
movb $0x0, (%rax)
movl $0x0, 0x4(%rax)
movq %r12, 0x8(%rax)
movq $0x0, 0x10(%rax)
movq %r13, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0xa6a8
leaq 0x41371(%rip), %rax     # 0x8e538
leaq 0x10(%rax), %rcx
movq %rcx, (%r13)
movl %ebp, 0x14(%r13)
movl $0x1, 0x18(%r13)
movq 0x8(%rsp), %rcx
movq %rcx, 0x20(%r13)
movq 0x10(%rsp), %rcx
movq %rcx, 0x28(%r13)
movb $0x0, 0x30(%r13)
movl $0xffffffff, 0x34(%r13) # imm = 0xFFFFFFFF
movq %rbx, 0x38(%r13)
movq %r13, %rdi
callq *0x28(%rax)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4d21f
movq %rax, %r15
movl $0x48, %esi
jmp 0x4d227
movq %rax, %r15
movl $0x28, %esi
movq %rbx, %rdi
jmp 0x4d253
movq %rax, %r15
movl $0x40, %esi
movq %r12, %rdi
jmp 0x4d253
movq %rax, %r15
movl $0x48, %esi
movq %r14, %rdi
jmp 0x4d253
jmp 0x4d248
movq %rax, %r15
movl $0x40, %esi
movq %r13, %rdi
callq 0x82a0
movq %r15, %rdi
callq 0x8540