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

  if(c->tag == CDEC){
    int idtemp = gen_id();
    fprintf(output,"\t%%t%d = add i32 0, %d\n",idtemp,c->val.i);
    return idtemp;
  }
  else if (c->tag == CREAL){
    int idtemp = gen_id();
    fprintf(output,"\t%%t%d = fadd float 0.0, %f\n",idtemp,c->val.f);
    return idtemp;
  }
  else if (c->tag == CSTRING) {
    int idtemp, originalStringLen;
    char *originalString;
    char snum[200];
    char *finalString;
    char *strPrint;
    StringList *nv;

    idtemp = gen_stringid();
    originalString = traduz_escapes_string(c->val.s,&originalStringLen);
    //originalStringLen = strlen(originalString)+1;

    sprintf(snum,"@.s%d = private unnamed_addr constant [%d x i8] c\"",idtemp,originalStringLen);

    // +4 pelo \00 e "
    finalString = (char*) malloc((strlen(snum)+strlen(originalString)+4)*sizeof(char));

    sprintf(finalString,"%s%s\\00\"",snum,originalString);
    //printf("%s",finalString);
    nv = (StringList*) malloc(sizeof(StringList));
    if (nv == NULL) {printf("Falta de memoria\n");exit(1);}
    nv->s = finalString;
    nv->prox = strLst;
    strLst = nv;

    strPrint = (char*) malloc(200*sizeof(char));
    if (strPrint == NULL) {printf("Falta de memoria\n");exit(1);}

    sprintf(strPrint,"call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([%d x i8], [%d x i8]* @.s%d, i32 0, i32 0))\n",originalStringLen,originalStringLen,idtemp);
    if (lastStringToPrint != NULL) free(lastStringToPrint);
    lastStringToPrint = strPrint;

    return idtemp;
  }
  return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x7f7a
callq 0x77b0
movl %eax, -0x14(%rbp)
movq 0x6231(%rip), %rdi      # 0xe188
movl -0x14(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
leaq 0x2d15(%rip), %rsi      # 0xac7d
movb $0x0, %al
callq 0x10e0
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8147
movq -0x10(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x7fbb
callq 0x77b0
movl %eax, -0x18(%rbp)
movq 0x61f6(%rip), %rdi      # 0xe188
movl -0x18(%rbp), %edx
movq -0x10(%rbp), %rax
movss 0x8(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x2cec(%rip), %rsi      # 0xac95
movb $0x1, %al
callq 0x10e0
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8147
movq -0x10(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x813c
callq 0x8e10
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x8c20
movq %rax, -0x28(%rbp)
leaq -0xf0(%rbp), %rdi
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
leaq 0x2cb9(%rip), %rsi      # 0xacb2
movb $0x0, %al
callq 0x1180
leaq -0xf0(%rbp), %rdi
callq 0x1090
movq %rax, -0x110(%rbp)
movq -0x28(%rbp), %rdi
callq 0x1090
movq -0x110(%rbp), %rdi
addq %rax, %rdi
addq $0x4, %rdi
shlq $0x0, %rdi
callq 0x1130
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rdi
leaq -0xf0(%rbp), %rdx
movq -0x28(%rbp), %rcx
leaq 0x2c92(%rip), %rsi      # 0xace5
movb $0x0, %al
callq 0x1180
movl $0x10, %edi
callq 0x1130
movq %rax, -0x108(%rbp)
cmpq $0x0, -0x108(%rbp)
jne 0x808d
leaq 0x2991(%rip), %rdi      # 0xaa0d
movb $0x0, %al
callq 0x10a0
movl $0x1, %edi
callq 0x1190
movq -0xf8(%rbp), %rcx
movq -0x108(%rbp), %rax
movq %rcx, (%rax)
movq 0x60eb(%rip), %rcx      # 0xe190
movq -0x108(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x108(%rbp), %rax
movq %rax, 0x60d2(%rip)      # 0xe190
movl $0xc8, %edi
callq 0x1130
movq %rax, -0x100(%rbp)
cmpq $0x0, -0x100(%rbp)
jne 0x80f1
leaq 0x292d(%rip), %rdi      # 0xaa0d
movb $0x0, %al
callq 0x10a0
movl $0x1, %edi
callq 0x1190
movq -0x100(%rbp), %rdi
movl -0x20(%rbp), %edx
movl -0x20(%rbp), %ecx
movl -0x1c(%rbp), %r8d
leaq 0x2be5(%rip), %rsi      # 0xacee
movb $0x0, %al
callq 0x1180
cmpq $0x0, 0x6088(%rip)      # 0xe1a0
je 0x8126
movq 0x607f(%rip), %rdi      # 0xe1a0
callq 0x1030
movq -0x100(%rbp), %rax
movq %rax, 0x606c(%rip)      # 0xe1a0
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8147
jmp 0x813e
jmp 0x8140
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopw %cs:(%rax,%rax)