// File: /workspace/github_cpp_makefile_star2_O3/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 0x148(%rsp), %rdi
movq %r14, %rsi
callq 0x28816
movq 0x50(%r15), %rax
cmpq 0x58(%r15), %rax
je 0x15276
cmpl $0x4, 0x8(%r15)
jne 0x15276
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 0xc6dc
leaq 0x5a1a7(%rip), %rsi     # 0x6f2f0
movq %rsp, %rdi
callq 0x8590
movq %r14, 0x90(%rsp)
leaq 0x59cb9(%rip), %rsi     # 0x6ee19
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 0x1519b
movq %rsi, %r14
movq %rdx, 0xb8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xc8(%rsp)
jmp 0x151a4
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 0x599bb(%rip), %rsi     # 0x6eb85
callq 0x8590
leaq 0x30(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x151f6
movq %rdx, 0x20(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
jmp 0x151fc
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 0x2b6aa
movq 0x20(%rsp), %rdi
cmpq %rbx, %rdi
je 0x15236
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0xb8(%rsp), %rdi
cmpq %r14, %rdi
leaq 0x10(%rsp), %rbx
je 0x15258
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x82a0
movq (%rsp), %rdi
cmpq %rbx, %rdi
movq 0x90(%rsp), %r14
je 0x15276
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x82a0
cmpl $0x1, 0x148(%rsp)
jne 0x152b4
movl 0x14c(%rsp), %edx
movl 0xc(%r12), %eax
cmpl $0x102, %eax            # imm = 0x102
je 0x15559
cmpl $0x104, %eax            # imm = 0x104
je 0x15550
cmpl $0x103, %eax            # imm = 0x103
jne 0x155c3
negl %edx
jmp 0x15559
movl 0xc(%r12), %eax
cmpl $0x102, %eax            # imm = 0x102
je 0x15590
movl $0x6, %ebp
cmpl $0x103, %eax            # imm = 0x103
je 0x152e0
cmpl $0x104, %eax            # imm = 0x104
jne 0x15626
movl $0x5, %ebp
movq %rsp, %rdi
callq 0x28564
movslq (%r15), %r12
leaq 0x7a286(%rip), %rax     # 0x8f578
shlq $0x6, %r12
addq (%rax), %r12
leaq 0xb8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x25368
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
leaq 0xb8(%rsp), %rdx
callq 0x25400
leaq 0x20(%rsp), %rsi
movq %r12, %rdi
callq 0x26bbc
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x15346
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x1535d
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x15374
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1538f
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
je 0x153ac
movq 0x100(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0x153c9
movq 0xe8(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x153e6
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 0xc6dc
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 0xc6dc
movl %ebx, 0x48(%rsp)
movq $0x0, 0x50(%rsp)
movl $0xffffffff, 0x58(%rsp) # imm = 0xFFFFFFFF
movq 0x98(%rsp), %rdi
cmpq %r12, %rdi
je 0x1546e
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x288be
movl $0xe0, %edi
callq 0x8290
movq %rax, %r14
leaq 0x108(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x28816
leaq 0x188(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x28816
movb $0x1, %r12b
leaq 0x108(%rsp), %rdx
leaq 0x188(%rsp), %rcx
movq %r14, %rdi
movl %ebp, %esi
callq 0x25560
leaq 0xb8(%rsp), %rsi
movq %r14, (%rsi)
xorl %r12d, %r12d
movq %r13, %rdi
callq 0x11182
leaq 0x1a0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15503
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x120(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15524
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x1553b
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15590
movq 0x10(%rsp), %rsi
jmp 0x15588
xorl %eax, %eax
testl %edx, %edx
sete %al
movl %eax, %edx
leaq 0x20(%rsp), %rdi
movl $0x1, %esi
callq 0x1279c
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x289a2
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15590
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x160(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x155b1
movq 0x160(%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 0x79a1e(%rip), %rdi     # 0x8efe8
leaq 0x58b97(%rip), %rsi     # 0x6e168
movl $0x8, %edx
callq 0x8330
movq 0x79a06(%rip), %rdi     # 0x8efe8
leaq 0x595aa(%rip), %rsi     # 0x6eb93
movl $0x13, %edx
callq 0x8330
movq 0x799ee(%rip), %rdi     # 0x8efe8
leaq 0x59dbf(%rip), %rsi     # 0x6f3c0
movl $0x1, %edx
callq 0x8330
movq 0x799d6(%rip), %rdi     # 0x8efe8
movl $0x13c, %esi            # imm = 0x13C
callq 0x8520
movq %rax, %rdi
callq 0x8180
jmp 0x15687
movq 0x799bb(%rip), %rdi     # 0x8efe8
leaq 0x58b34(%rip), %rsi     # 0x6e168
movl $0x8, %edx
callq 0x8330
movq 0x799a3(%rip), %rdi     # 0x8efe8
leaq 0x59547(%rip), %rsi     # 0x6eb93
movl $0x13, %edx
callq 0x8330
movq 0x7998b(%rip), %rdi     # 0x8efe8
leaq 0x59d5c(%rip), %rsi     # 0x6f3c0
movl $0x1, %edx
callq 0x8330
movq 0x79973(%rip), %rdi     # 0x8efe8
movl $0x14f, %esi            # imm = 0x14F
callq 0x8520
movq %rax, %rdi
callq 0x8180
movl $0xff, %edi
callq 0x8380
jmp 0x157b3
jmp 0x157b3
movq %rax, %r13
leaq 0x120(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15805
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x15805
movq %rax, %r13
jmp 0x15805
jmp 0x156d2
movq %rax, %r13
jmp 0x15812
movq %rax, %r13
movq 0x98(%rsp), %rdi
cmpq %r12, %rdi
je 0x15829
movq 0xa8(%rsp), %rsi
jmp 0x15821
jmp 0x15721
movq %rax, %r13
leaq 0x20(%rsp), %rdi
callq 0x254bc
jmp 0x1570f
movq %rax, %r13
leaq 0xb8(%rsp), %rdi
callq 0x2551a
jmp 0x15829
movq %rax, %r13
jmp 0x15829
jmp 0x157b3
movq %rax, %r13
movq 0x20(%rsp), %rdi
cmpq %rbx, %rdi
je 0x1576c
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x1576c
movq %rax, %r13
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15844
movq 0x38(%rsp), %rsi
jmp 0x1583c
movq %rax, %r13
movq 0xb8(%rsp), %rdi
cmpq %r14, %rdi
je 0x15790
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x15790
jmp 0x157b3
movq %rax, %r13
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
jmp 0x15832
movq %rax, %r13
movq (%rsp), %rdi
cmpq %rbx, %rdi
jne 0x15837
jmp 0x15844
movq %rax, %r13
jmp 0x15844
movq %rax, %r13
leaq 0x1a0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x157df
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x120(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15800
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x82a0
testb %r12b, %r12b
je 0x15812
movl $0xe0, %esi
movq %r14, %rdi
callq 0x82a0
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x15829
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15844
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x160(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15865
movq 0x160(%rsp), %rsi
incq %rsi
callq 0x82a0
movq %r13, %rdi
callq 0x8540
nop