// File: /workspace/github_c_makefile_star2_O0/thiagok00[P]INF1715-Compilers/GeraCodigo.c
// Function: gera_codigo_exparith
static int gera_codigo_exparith(Exp *e) {

  int idesq, iddir, idtemp=-1;
  int flag = 0;
  char *op, *strtipobase;
  Base_TAG tipoexp;

  tipoexp = e->u.expbin.expesq->tipo->tipo_base; //assumindo que os dois tipos sao iguais, garantido pela tipagem
  strtipobase = tipo_base_string(tipoexp);

  idesq = gera_codigo_expressao(e->u.expbin.expesq);
  iddir = gera_codigo_expressao(e->u.expbin.expdir);


  if (e->u.expbin.opbin == opadd){
    flag = 1;
    if (tipoexp == bFloat)
      op = "fadd";
    else
      op = "add";
  }
  if (e->u.expbin.opbin == opsub){
    flag = 1;
    if (tipoexp == bFloat)
      op = "fsub";
    else
      op = "sub nsw";
  }
  if (e->u.expbin.opbin == opmult){
    flag = 1;
    if (tipoexp == bFloat)
      op = "fmul";
    else
      op = "mul nsw";
  }
  if (e->u.expbin.opbin == opdiv) {
    flag = 1;
    if (tipoexp == bFloat)
      op = "fdiv";
    else
      op = "sdiv";
  }
  if (flag){
    idtemp = gen_id();
    //%t(idtemp) = fsub float %idesq, %iddir
    fprintf(output,"\t%%t%d = %s %s %%t%d, %%t%d\n",idtemp,op,strtipobase,idesq,iddir);
    return idtemp;
  }
  return idtemp;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movl 0x4(%rax), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %edi
callq 0x7300
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x7b60
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x7b60
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x20(%rax)
jne 0x85d9
movl $0x1, -0x20(%rbp)
cmpl $0x3, -0x34(%rbp)
jne 0x85cc
leaq 0x2909(%rip), %rax      # 0xaecf
movq %rax, -0x28(%rbp)
jmp 0x85d7
leaq 0x28fd(%rip), %rax      # 0xaed0
movq %rax, -0x28(%rbp)
jmp 0x85d9
movq -0x10(%rbp), %rax
cmpl $0x1, 0x20(%rax)
jne 0x860a
movl $0x1, -0x20(%rbp)
cmpl $0x3, -0x34(%rbp)
jne 0x85fd
leaq 0x28dd(%rip), %rax      # 0xaed4
movq %rax, -0x28(%rbp)
jmp 0x8608
leaq 0x28d5(%rip), %rax      # 0xaed9
movq %rax, -0x28(%rbp)
jmp 0x860a
movq -0x10(%rbp), %rax
cmpl $0x2, 0x20(%rax)
jne 0x863b
movl $0x1, -0x20(%rbp)
cmpl $0x3, -0x34(%rbp)
jne 0x862e
leaq 0x28b9(%rip), %rax      # 0xaee1
movq %rax, -0x28(%rbp)
jmp 0x8639
leaq 0x28b1(%rip), %rax      # 0xaee6
movq %rax, -0x28(%rbp)
jmp 0x863b
movq -0x10(%rbp), %rax
cmpl $0x3, 0x20(%rax)
jne 0x866c
movl $0x1, -0x20(%rbp)
cmpl $0x3, -0x34(%rbp)
jne 0x865f
leaq 0x2895(%rip), %rax      # 0xaeee
movq %rax, -0x28(%rbp)
jmp 0x866a
leaq 0x288d(%rip), %rax      # 0xaef3
movq %rax, -0x28(%rbp)
jmp 0x866c
cmpl $0x0, -0x20(%rbp)
je 0x86ac
callq 0x77b0
movl %eax, -0x1c(%rbp)
movq 0x5b07(%rip), %rdi      # 0xe188
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
movl -0x14(%rbp), %r9d
movl -0x18(%rbp), %eax
leaq 0x285e(%rip), %rsi      # 0xaef8
movl %eax, (%rsp)
movb $0x0, %al
callq 0x10e0
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x86b2
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)