#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 */
scalar_t__ Parse(char *, double *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main() {
  char strExpr[255];
  double dblRes;
  while (1) {
    printf("Enter an arithmetic expression: ");
    if (fgets(strExpr, 254, stdin) == NULL)
      break;
    strExpr[strlen(strExpr) - 1] = '\0';
    if (strlen(strExpr) == 0)
      break;
    if (Parse(strExpr, &dblRes))
      printf("\nThe result is: %g\n\n", dblRes);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
mov    $0xfe,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    1189 <main+0x49>
jmp    11f4 <main+0xb4>
lea    -0x110(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jne    11bc <main+0x7c>
jmp    11f4 <main+0xb4>
lea    -0x110(%rbp),%rdi
lea    -0x118(%rbp),%rsi
call   1060 <Parse@plt>
cmp    $0x0,%rax
je     11ef <main+0xaf>
movsd  -0x118(%rbp),%xmm0
ff
lea    0xe39(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    1152 <main+0x12>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x110,%rsp
lea    0xea9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e83(%rip),%r13
mov    0x0(%r13),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xfe,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11fd <main+0xbd>
lea    0x8(%rsp),%r14
lea    0xe74(%rip),%r15
lea    0xe8e(%rip),%r12
jmp    11c0 <main+0x80>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0xfe,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11fd <main+0xbd>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     11fd <main+0xbd>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <Parse@plt>
test   %rax,%rax
je     11a0 <main+0x60>
movsd  0x8(%rsp),%xmm0
mov    %r12,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    11a0 <main+0x60>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Enter an arithmetic expression: \00"
@stdin = global i32 0
@.str.1 = [21 x i8] c"\0AThe result is: %g\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [255 x i8]
%3 = alloca double
store i32 0, i32* %1
br label %4
4: ; preds = %0, %28
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32* @fgets(i8* %6, i32 254, i32 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %4
br label %29
11: ; preds = %4
%12 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
%14 = sub nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 %15
store i8 0, i8* %16
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %11
br label %29
21: ; preds = %11
%22 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%23 = call i64 @Parse(i8* %22, double* %3)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load double, double* %3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), double %26)
br label %28
28: ; preds = %25, %21
br label %4
29: ; preds = %20, %10
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"Enter an arithmetic expression: \00"
@stdin = global i32 0
@.str.1 = [21 x i8] c"\0AThe result is: %g\0A\0A\00"
define i32 @main() {
%1 = alloca [255 x i8]
%2 = alloca double
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%4 = bitcast double* %2 to i8*
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32* @fgets(i8* %3, i32 254, i32 %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %27, label %9
9: ; preds = %0, %22
%10 = call i32 @strlen(i8* %3)
%11 = add nsw i32 %10, -1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 %12
store i8 0, i8* %13
%14 = call i32 @strlen(i8* %3)
%15 = icmp eq i32 %14, 0
br i1 %15, label %27, label %16
16: ; preds = %9
%17 = call i64 @Parse(i8* %3, double* %2)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load double, double* %2
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), double %20)
br label %22
22: ; preds = %19, %16
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @stdin
%25 = call i32* @fgets(i8* %3, i32 254, i32 %24)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %9
27: ; preds = %22, %9, %0
ret i32 0
}