#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ gets(char *);
int lex(char *, int *);
int /*<<< orphan*/ printf(char *);
int main() {
  char str[50];
  int token, pos = 0;
  printf("\nDigite uma expressao:");
  gets(str);
  do {
    token = lex(str, &pos);
    switch (token) {
    case 0x0500:
      printf("const");
      break;
    case 0x0100:
      printf("+");
      break;
    case 0x0200:
      printf("-");
      break;
    case 0x0300:
      printf("*");
      break;
    case 0x0400:
      printf("/");
      break;
    case 0x0600:
      printf("(");
      break;
    case 0x0700:
      printf(")");
      break;
    case 0x0000:
      printf("Erro");
      break;
    }
  } while (token != 0x0800);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x48(%rbp)
lea    0xeb3(%rip),%rdi
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
call   1050 <gets@plt>
lea    -0x40(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1030 <lex@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x4c(%rbp)
test   %eax,%eax
je     127a <main+0x14a>
jmp    117e <main+0x4e>
mov    -0x4c(%rbp),%eax
sub    $0x100,%eax
je     1214 <main+0xe4>
jmp    1191 <main+0x61>
mov    -0x4c(%rbp),%eax
sub    $0x200,%eax
je     1225 <main+0xf5>
jmp    11a4 <main+0x74>
mov    -0x4c(%rbp),%eax
sub    $0x300,%eax
je     1236 <main+0x106>
jmp    11b7 <main+0x87>
mov    -0x4c(%rbp),%eax
sub    $0x400,%eax
je     1247 <main+0x117>
jmp    11ca <main+0x9a>
mov    -0x4c(%rbp),%eax
sub    $0x500,%eax
je     1203 <main+0xd3>
jmp    11dd <main+0xad>
mov    -0x4c(%rbp),%eax
sub    $0x600,%eax
je     1258 <main+0x128>
jmp    11f0 <main+0xc0>
mov    -0x4c(%rbp),%eax
sub    $0x700,%eax
je     1269 <main+0x139>
jmp    1286 <main+0x156>
lea    0xe0d(%rip),%rdi
call   1040 <printf@plt>
jmp    1286 <main+0x156>
lea    0xe02(%rip),%rdi
call   1040 <printf@plt>
jmp    1286 <main+0x156>
lea    0xdf3(%rip),%rdi
call   1040 <printf@plt>
jmp    1286 <main+0x156>
lea    0xde4(%rip),%rdi
call   1040 <printf@plt>
jmp    1286 <main+0x156>
lea    0xdd5(%rip),%rdi
call   1040 <printf@plt>
jmp    1286 <main+0x156>
lea    0xdc6(%rip),%rdi
call   1040 <printf@plt>
jmp    1286 <main+0x156>
lea    0xdb7(%rip),%rdi
call   1040 <printf@plt>
jmp    1286 <main+0x156>
lea    0xda8(%rip),%rdi
call   1040 <printf@plt>
jmp    128b <main+0x15b>
cmpl   $0x800,-0x44(%rbp)
jne    115b <main+0x2b>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movl   $0x0,0xc(%rsp)
lea    0xec3(%rip),%rdi
call   1050 <printf@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1060 <gets@plt>
lea    0xc(%rsp),%r13
lea    0xe85(%rip),%rbx
lea    0xebb(%rip),%r15
lea    0xeae(%rip),%r12
jmp    119b <main+0x5b>
mov    %r15,%rdi
call   1050 <printf@plt>
cmp    $0x800,%ebp
je     1206 <main+0xc6>
mov    %r14,%rdi
mov    %r13,%rsi
call   1040 <lex@plt>
mov    %eax,%ebp
rol    $0x18,%eax
cmp    $0x7,%eax
ja     1193 <main+0x53>
movslq (%rbx,%rax,4),%rax
add    %rbx,%rax
jmp    *%rax
mov    $0x2b,%edi
call   1030 <putchar@plt>
jmp    1193 <main+0x53>
mov    $0x2d,%edi
call   1030 <putchar@plt>
jmp    1193 <main+0x53>
mov    $0x2a,%edi
call   1030 <putchar@plt>
jmp    1193 <main+0x53>
mov    $0x2f,%edi
call   1030 <putchar@plt>
jmp    1193 <main+0x53>
mov    %r12,%rdi
jmp    118e <main+0x4e>
mov    $0x28,%edi
call   1030 <putchar@plt>
jmp    1193 <main+0x53>
mov    $0x29,%edi
call   1030 <putchar@plt>
jmp    1193 <main+0x53>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"\0ADigite uma expressao:\00"
@.str.1 = [6 x i8] c"const\00"
@.str.2 = [2 x i8] c"+\00"
@.str.3 = [2 x i8] c"-\00"
@.str.4 = [2 x i8] c"*\00"
@.str.5 = [2 x i8] c"/\00"
@.str.6 = [2 x i8] c"(\00"
@.str.7 = [2 x i8] c")\00"
@.str.8 = [5 x i8] c"Erro\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [50 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%5 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%7 = call i32 @gets(i8* %6)
br label %8
8: ; preds = %29, %0
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%10 = call i32 @lex(i8* %9, i32* %4)
store i32 %10, i32* %3
%11 = load i32, i32* %3
switch i32 %11, label %28 [
i32 1280, label %12
i32 256, label %14
i32 512, label %16
i32 768, label %18
i32 1024, label %20
i32 1536, label %22
i32 1792, label %24
i32 0, label %26
]
12: ; preds = %8
%13 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %28
14: ; preds = %8
%15 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %28
16: ; preds = %8
%17 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %28
18: ; preds = %8
%19 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %28
20: ; preds = %8
%21 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %28
22: ; preds = %8
%23 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %28
24: ; preds = %8
%25 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %28
26: ; preds = %8
%27 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %28
28: ; preds = %8, %26, %24, %22, %20, %18, %16, %14, %12
br label %29
29: ; preds = %28
%30 = load i32, i32* %3
%31 = icmp ne i32 %30, 2048
br i1 %31, label %8, label %32
32: ; preds = %29
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"\0ADigite uma expressao:\00"
@.str.1 = [6 x i8] c"const\00"
@.str.8 = [5 x i8] c"Erro\00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @gets(i8* %3)
br label %7
7: ; preds = %26, %0
%8 = call i32 @lex(i8* %3, i32* %2)
%9 = call i32 @llvm.fshl.i32(i32 %8, i32 %8, i32 24)
switch i32 %9, label %26 [
i32 5, label %10
i32 1, label %12
i32 2, label %14
i32 3, label %16
i32 4, label %18
i32 6, label %20
i32 7, label %22
i32 0, label %24
]
10: ; preds = %7
%11 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %26
12: ; preds = %7
%13 = call i32 @putchar(i32 43)
br label %26
14: ; preds = %7
%15 = call i32 @putchar(i32 45)
br label %26
16: ; preds = %7
%17 = call i32 @putchar(i32 42)
br label %26
18: ; preds = %7
%19 = call i32 @putchar(i32 47)
br label %26
20: ; preds = %7
%21 = call i32 @putchar(i32 40)
br label %26
22: ; preds = %7
%23 = call i32 @putchar(i32 41)
br label %26
24: ; preds = %7
%25 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %26
26: ; preds = %10, %12, %14, %16, %18, %20, %22, %24, %7
%27 = icmp eq i32 %8, 2048
br i1 %27, label %28, label %7
28: ; preds = %26
ret i32 0
}