// File: /workspace/github_cpp_makefile_star2_O1/luooofan[P]hblzbd_compiler/src/generate_ir.cpp
// Function: ast::UnaryExpression::GenerateIR(ir::ContextInfo&, std::vector<ir::IR*, std::allocator<ir::IR*>>&)
void UnaryExpression::GenerateIR(ir::ContextInfo &ctx, std::vector<ir::IR *> &gIRList) {
  rhs_.GenerateIR(ctx, gIRList);
  ir::Opn opn1 = ctx.opn_;
  CHECK_OPN_INT("rhs exp");

  if (opn1.type_ == OpnType::Imm) {
    int result;
    int num1 = opn1.imm_num_;
    switch (op_) {
      case ADD:
        result = num1;
        break;
      case SUB:
        result = -num1;
        break;
      case NOT:
        result = !num1;
        break;
      default:
        // printf("mystery operator code: %d", op_);
        MyAssert(0);
        break;
    }
    ctx.opn_ = ir::Opn(OpnType::Imm, result);
  } else {
    IROpKind op;
    switch (op_) {
      case ADD:
        // op = IROpKind::POS;
        return;
        break;
      case SUB:
        op = IROpKind::NEG;
        break;
      case NOT:
        op = IROpKind::NOT;
        break;
      default:
        // printf("mystery operator code: %d", op_);
        MyAssert(0);
        break;
    }
    std::string rhs_temp_var = ir::NewTemp();

    // NOTE: 中间变量栈偏移-1 并且不维护scope的dynamic offset
    ir::gScopes[ctx.scope_id_].symbol_table_.insert({rhs_temp_var, {false, false}});

    ir::Opn temp = ir::Opn(OpnType::Var, rhs_temp_var, ctx.scope_id_);
    ctx.opn_ = temp;
    gIRList.push_back(new ir::IR(op, opn1, temp));
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %r12
movq 0x10(%rdi), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
leaq 0x8(%r15), %r14
leaq 0x108(%rsp), %rdi
movq %r14, %rsi
callq 0x28186
movq 0x50(%r15), %rax
cmpq 0x58(%r15), %rax
je 0x15556
cmpl $0x4, 0x8(%r15)
jne 0x15556
movl 0x8(%r12), %ebp
leaq 0x10(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x10(%r15), %rsi
movq 0x18(%r15), %rdx
addq %rsi, %rdx
movq %rsp, %rdi
callq 0xca10
leaq 0x5aec7(%rip), %rsi     # 0x702f0
movq %rsp, %rdi
callq 0x8590
movq %r14, 0x90(%rsp)
leaq 0x5a9d9(%rip), %rsi     # 0x6fe19
movq %rsp, %rdi
callq 0x8590
leaq 0xc8(%rsp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x1547b
movq %rsi, %r14
movq %rdx, 0xb8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xc8(%rsp)
jmp 0x15484
movups (%rcx), %xmm0
movq %rsi, %r14
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
leaq 0xb8(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x5a6db(%rip), %rsi     # 0x6fb85
callq 0x8590
leaq 0x30(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x154d6
movq %rdx, 0x20(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
jmp 0x154dc
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
leaq 0x20(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl %ebp, %edi
callq 0x2b12a
movq 0x20(%rsp), %rdi
cmpq %rbx, %rdi
je 0x15516
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0xb8(%rsp), %rdi
cmpq %r14, %rdi
leaq 0x10(%rsp), %rbx
je 0x15538
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x82a0
movq (%rsp), %rdi
cmpq %rbx, %rdi
movq 0x90(%rsp), %r14
je 0x15556
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x82a0
cmpl $0x1, 0x108(%rsp)
jne 0x15594
movl 0x10c(%rsp), %edx
movl 0xc(%r12), %eax
cmpl $0x102, %eax            # imm = 0x102
je 0x15839
cmpl $0x104, %eax            # imm = 0x104
je 0x15830
cmpl $0x103, %eax            # imm = 0x103
jne 0x158a3
negl %edx
jmp 0x15839
movl 0xc(%r12), %eax
cmpl $0x102, %eax            # imm = 0x102
je 0x15870
movl $0x6, %ebp
cmpl $0x103, %eax            # imm = 0x103
je 0x155c0
cmpl $0x104, %eax            # imm = 0x104
jne 0x15906
movl $0x5, %ebp
movq %rsp, %rdi
callq 0x27ed3
movslq (%r15), %r12
leaq 0x7afa6(%rip), %rax     # 0x90578
shlq $0x6, %r12
addq (%rax), %r12
leaq 0xb8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x24c9c
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
leaq 0xb8(%rsp), %rdx
callq 0x24d34
leaq 0x20(%rsp), %rsi
movq %r12, %rdi
callq 0x26522
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x15626
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x1563d
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x15654
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1566f
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
je 0x1568c
movq 0x100(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0x156a9
movq 0xe8(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x156c6
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
leaq 0xa8(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x98(%rsp), %rdi
callq 0xca10
movl (%r15), %ebx
leaq 0x28(%rsp), %rdi
movl $0x0, -0x8(%rdi)
leaq 0x38(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x98(%rsp), %rsi
movq 0xa0(%rsp), %rdx
addq %rsi, %rdx
callq 0xca10
movl %ebx, 0x48(%rsp)
movq $0x0, 0x50(%rsp)
movl $0xffffffff, 0x58(%rsp) # imm = 0xFFFFFFFF
movq 0x98(%rsp), %rdi
cmpq %r12, %rdi
je 0x1574e
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x2822e
movl $0xe0, %edi
callq 0x8290
movq %rax, %r14
leaq 0x188(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x28186
leaq 0x148(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x28186
movb $0x1, %r12b
leaq 0x188(%rsp), %rdx
leaq 0x148(%rsp), %rcx
movq %r14, %rdi
movl %ebp, %esi
callq 0x24e94
leaq 0xb8(%rsp), %rsi
movq %r14, (%rsi)
xorl %r12d, %r12d
movq %r13, %rdi
callq 0x114b8
leaq 0x160(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x157e3
movq 0x160(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x1a0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15804
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x1581b
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15870
movq 0x10(%rsp), %rsi
jmp 0x15868
xorl %eax, %eax
testl %edx, %edx
sete %al
movl %eax, %edx
leaq 0x20(%rsp), %rdi
movl $0x1, %esi
callq 0x12ade
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x28312
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15870
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x120(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15891
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x82a0
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x7a746(%rip), %rdi     # 0x8fff0
leaq 0x598b7(%rip), %rsi     # 0x6f168
movl $0x8, %edx
callq 0x8330
movq 0x7a72e(%rip), %rdi     # 0x8fff0
leaq 0x5a2ca(%rip), %rsi     # 0x6fb93
movl $0x13, %edx
callq 0x8330
movq 0x7a716(%rip), %rdi     # 0x8fff0
leaq 0x5aadf(%rip), %rsi     # 0x703c0
movl $0x1, %edx
callq 0x8330
movq 0x7a6fe(%rip), %rdi     # 0x8fff0
movl $0x13c, %esi            # imm = 0x13C
callq 0x8520
movq %rax, %rdi
callq 0x8180
jmp 0x15967
movq 0x7a6e3(%rip), %rdi     # 0x8fff0
leaq 0x59854(%rip), %rsi     # 0x6f168
movl $0x8, %edx
callq 0x8330
movq 0x7a6cb(%rip), %rdi     # 0x8fff0
leaq 0x5a267(%rip), %rsi     # 0x6fb93
movl $0x13, %edx
callq 0x8330
movq 0x7a6b3(%rip), %rdi     # 0x8fff0
leaq 0x5aa7c(%rip), %rsi     # 0x703c0
movl $0x1, %edx
callq 0x8330
movq 0x7a69b(%rip), %rdi     # 0x8fff0
movl $0x14f, %esi            # imm = 0x14F
callq 0x8520
movq %rax, %rdi
callq 0x8180
movl $0xff, %edi
callq 0x8380
jmp 0x15a74
jmp 0x15a74
movq %rax, %r13
movb $0x1, %r12b
jmp 0x15aa0
movq %rax, %r13
movb $0x1, %r12b
jmp 0x15ac1
jmp 0x15993
movq %rax, %r13
jmp 0x15ad3
movq %rax, %r13
movq 0x98(%rsp), %rdi
cmpq %r12, %rdi
je 0x15aea
movq 0xa8(%rsp), %rsi
jmp 0x15ae2
jmp 0x159e2
movq %rax, %r13
leaq 0x20(%rsp), %rdi
callq 0x24df0
jmp 0x159d0
movq %rax, %r13
leaq 0xb8(%rsp), %rdi
callq 0x24e4e
jmp 0x15aea
movq %rax, %r13
jmp 0x15aea
jmp 0x15a74
movq %rax, %r13
movq 0x20(%rsp), %rdi
cmpq %rbx, %rdi
je 0x15a2d
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x15a2d
movq %rax, %r13
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15b05
movq 0x38(%rsp), %rsi
jmp 0x15afd
movq %rax, %r13
movq 0xb8(%rsp), %rdi
cmpq %r14, %rdi
je 0x15a51
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x15a51
jmp 0x15a74
movq %rax, %r13
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
jmp 0x15af3
movq %rax, %r13
movq (%rsp), %rdi
cmpq %rbx, %rdi
jne 0x15af8
jmp 0x15b05
movq %rax, %r13
jmp 0x15b05
movq %rax, %r13
leaq 0x160(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15aa0
movq 0x160(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x1a0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15ac1
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x82a0
testb %r12b, %r12b
je 0x15ad3
movl $0xe0, %esi
movq %r14, %rdi
callq 0x82a0
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x15aea
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15b05
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x120(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15b26
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x82a0
movq %r13, %rdi
callq 0x8540