#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 */
double fcalc(char const **, int *, int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int main() {
  char line[2048];
  const char *ptr = line;
  int err;
  while (1) {
    printf("> ");
    fgets(line, 2048, stdin);
    if (line[0] == 'q')
      break;
    double ret = fcalc(&ptr, &err, 0);
    if (err)
      printf("<err>\n");
    else
      printf("= %f\n", ret);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x810(%rbp),%rax
mov    %rax,-0x818(%rbp)
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x810(%rbp),%rdi
mov    0x2e7c(%rip),%rax
mov    (%rax),%edx
mov    $0x800,%esi
call   1040 <fgets@plt>
movsbl -0x810(%rbp),%eax
cmp    $0x71,%eax
jne    118d <main+0x5d>
jmp    11e5 <main+0xb5>
lea    -0x818(%rbp),%rdi
lea    -0x81c(%rbp),%rsi
xor    %edx,%edx
call   1050 <fcalc@plt>
movsd  %xmm0,-0x828(%rbp)
ff
cmpl   $0x0,-0x81c(%rbp)
je     11ca <main+0x9a>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e0 <main+0xb0>
movsd  -0x828(%rbp),%xmm0
ff
lea    0xe31(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1150 <main+0x20>
xor    %eax,%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
lea    0x10(%rsp),%rbx
mov    %rbx,0x8(%rsp)
lea    0xe9e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e78(%rip),%r15
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x800,%esi
call   1050 <fgets@plt>
cmpb   $0x71,0x10(%rsp)
jne    119b <main+0x5b>
xor    %eax,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x8(%rsp),%r14
lea    0x4(%rsp),%r12
lea    0xe54(%rip),%r13
lea    0x10(%rsp),%rbx
lea    0xe51(%rip),%rbp
jmp    11ef <main+0xaf>
nopw   0x0(%rax,%rax,1)
lea    0xe3c(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x800,%esi
call   1050 <fgets@plt>
cmpb   $0x71,0x10(%rsp)
je     1187 <main+0x47>
mov    %r14,%rdi
mov    %r12,%rsi
xor    %edx,%edx
call   1060 <fcalc@plt>
cmpl   $0x0,0x4(%rsp)
je     11c0 <main+0x80>
mov    %rbp,%rdi
call   1030 <puts@plt>
jmp    11ce <main+0x8e>

LLVM IR (-O0):
@.str = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.1 = [7 x i8] c"<err>\0A\00"
@.str.2 = [6 x i8] c"= %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2048 x i8]
%3 = alloca i8*
%4 = alloca i32
%5 = alloca double
store i32 0, i32* %1
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
store i8* %6, i8** %3
br label %7
7: ; preds = %0, %26
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%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 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 113
br i1 %15, label %16, label %17
16: ; preds = %7
br label %27
17: ; preds = %7
%18 = call double @fcalc(i8** %3, i32* %4, i32 0)
store double %18, double* %5
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %26
23: ; preds = %17
%24 = load double, double* %5
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %24)
br label %26
26: ; preds = %23, %21
br label %7
27: ; preds = %16
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.2 = [6 x i8] c"= %f\0A\00"
@str = [6 x i8] c"<err>\00"
define i32 @main() {
%1 = alloca [2048 x i8]
%2 = alloca i8*
%3 = alloca i32
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%5 = bitcast i8** %2 to i8*
store i8* %4, i8** %2
%6 = bitcast i32* %3 to i8*
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %4, i32 2048, i32 %8)
%10 = load i8, i8* %4
%11 = icmp eq i8 %10, 113
br i1 %11, label %26, label %12
12: ; preds = %0, %20
%13 = call double @fcalc(i8** %2, i32* %3, i32 0)
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %20
18: ; preds = %12
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %13)
br label %20
20: ; preds = %18, %16
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* @stdin
%23 = call i32 @fgets(i8* %4, i32 2048, i32 %22)
%24 = load i8, i8* %4
%25 = icmp eq i8 %24, 113
br i1 %25, label %26, label %12
26: ; preds = %20, %0
ret i32 0
}