#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*/ abort();
double evaluate(char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
unsigned int strlen(char *);
int main(void) {
  char input[2048];
  double ans;
  unsigned int len;
  do {
    printf("Enter an expression to evaluate: ");
    fflush(stdout);
    if (!fgets(input, 2048, stdin))
      abort();
    len = strlen(input);
    if (len > 0 && input[len - 1] == '\n') {
      input[len - 1] = '\0';
      --len;
    }
    if (len == 0)
      break;
    ans = evaluate(input);
    printf("%s => %g\n", input, ans);
  } while (1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    -0x810(%rbp),%rdi
mov    0x2e4c(%rip),%rax
mov    (%rax),%edx
mov    $0x800,%esi
call   1060 <fgets@plt>
cmp    $0x0,%eax
jne    11b8 <main+0x58>
mov    $0x0,%al
call   1030 <abort@plt>
lea    -0x810(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x81c(%rbp)
cmpl   $0x0,-0x81c(%rbp)
jbe    1215 <main+0xb5>
mov    -0x81c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,%eax
movsbl -0x810(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1215 <main+0xb5>
mov    -0x81c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,%eax
movb   $0x0,-0x810(%rbp,%rax,1)
mov    -0x81c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x81c(%rbp)
cmpl   $0x0,-0x81c(%rbp)
jne    1227 <main+0xc7>
jmp    1267 <main+0x107>
lea    -0x810(%rbp),%rdi
call   1080 <evaluate@plt>
movsd  %xmm0,-0x818(%rbp)
ff
lea    -0x810(%rbp),%rsi
movsd  -0x818(%rbp),%xmm0
ff
lea    0xdd1(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0x1,%al
test   $0x1,%al
jne    1172 <main+0x12>
jmp    1267 <main+0x107>
xor    %eax,%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x800,%rsp
lea    0xe89(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e53(%rip),%r12
mov    (%r12),%edi
call   1070 <fflush@plt>
mov    0x2e53(%rip),%r13
mov    0x0(%r13),%edx
mov    %rsp,%rdi
mov    $0x800,%esi
call   1060 <fgets@plt>
test   %eax,%eax
je     123e <main+0xde>
mov    %rsp,%rbx
lea    0xe6a(%rip),%r14
lea    0xe41(%rip),%r15
jmp    120d <main+0xad>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1080 <evaluate@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r12),%edi
call   1070 <fflush@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x800,%esi
call   1060 <fgets@plt>
test   %eax,%eax
je     123e <main+0xde>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     122b <main+0xcb>
add    $0xffffffff,%eax
cmpb   $0xa,(%rsp,%rax,1)
jne    11d0 <main+0x70>
movb   $0x0,(%rsp,%rax,1)
test   %rax,%rax
jne    11d0 <main+0x70>
xor    %eax,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"Enter an expression to evaluate: \00"
@stdout = global i32 0
@stdin = global i32 0
@.str.1 = [10 x i8] c"%s => %g\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2048 x i8]
%3 = alloca double
%4 = alloca i32
store i32 0, i32* %1
br label %5
5: ; preds = %45, %0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stdout
%8 = call i32 @fflush(i32 %7)
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %9, i32 2048, i32 %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %5
%14 = call i32 (...) @abort()
unreachable
15: ; preds = %5
%16 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp ugt i32 %18, 0
br i1 %19, label %20, label %35
20: ; preds = %15
%21 = load i32, i32* %4
%22 = sub i32 %21, 1
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %35
28: ; preds = %20
%29 = load i32, i32* %4
%30 = sub i32 %29, 1
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %31
store i8 0, i8* %32
%33 = load i32, i32* %4
%34 = add i32 %33, -1
store i32 %34, i32* %4
br label %35
35: ; preds = %28, %20, %15
%36 = load i32, i32* %4
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %35
br label %46
39: ; preds = %35
%40 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%41 = call double @evaluate(i8* %40)
store double %41, double* %3
%42 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%43 = load double, double* %3
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %42, double %43)
br label %45
45: ; preds = %39
br i1 true, label %5, label %46
46: ; preds = %45, %38
ret i32 0
}

LLVM IR (-O2):
@.str = [34 x i8] c"Enter an expression to evaluate: \00"
@stdout = global i32 0
@stdin = global i32 0
@.str.1 = [10 x i8] c"%s => %g\0A\00"
define i32 @main() {
%1 = alloca [2048 x i8]
%2 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%3 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdout
%5 = call i32 @fflush(i32 %4)
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %2, i32 2048, i32 %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %22, %0
%10 = call i32 (...) @abort()
unreachable
11: ; preds = %0, %22
%12 = call i32 @strlen(i8* %2)
%13 = icmp eq i32 %12, 0
br i1 %13, label %31, label %14
14: ; preds = %11
%15 = add i32 %12, -1
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 10
br i1 %19, label %20, label %22
20: ; preds = %14
store i8 0, i8* %17
%21 = icmp eq i32 %15, 0
br i1 %21, label %31, label %22
22: ; preds = %14, %20
%23 = call double @evaluate(i8* %2)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %2, double %23)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @stdout
%27 = call i32 @fflush(i32 %26)
%28 = load i32, i32* @stdin
%29 = call i32 @fgets(i8* %2, i32 2048, i32 %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %9, label %11
31: ; preds = %11, %20
ret i32 0
}