#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ len(char *);
int parse(char *, int /*<<< orphan*/, double *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  char cmd[100] = {0};
  while (1) {
    printf("> ");
    fgets(cmd, 100, stdin);
    double result;
    if (parse(cmd, len(cmd), &result) == -1) {
      printf("Please enter a valid expression\n\n");
    }
    printf("%g\n", result);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2e56(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1060 <fgets@plt>
lea    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0x80(%rbp),%rdi
call   1030 <len@plt>
mov    -0x90(%rbp),%rdi
mov    %eax,%esi
lea    -0x88(%rbp),%rdx
call   1070 <parse@plt>
cmp    $0xffffffff,%eax
jne    11de <main+0x8e>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x88(%rbp),%xmm0
ff
lea    0xe38(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    1179 <main+0x29>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x70(%rsp)
lea    0xe72(%rip),%r14
mov    0x2e53(%rip),%rbp
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r15
lea    0xe61(%rip),%r12
lea    0xe56(%rip),%r13
jmp    11c0 <main+0x70>
nop
movsd  0x8(%rsp),%xmm0
mov    %r13,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1030 <len@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15,%rdx
call   1070 <parse@plt>
cmp    $0xffffffff,%eax
jne    11b0 <main+0x60>
mov    %r12,%rdi
call   1040 <puts@plt>
jmp    11b0 <main+0x60>

LLVM IR (-O0):
@.str = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.1 = [34 x i8] c"Please enter a valid expression\0A\0A\00"
@.str.2 = [4 x i8] c"%g\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [100 x i8]* %6 to i8*
br label %9
9: ; preds = %2, %21
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%12 = load i32, i32* @stdin
%13 = call i32 @fgets(i8* %11, i32 100, i32 %12)
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%16 = call i32 @len(i8* %15)
%17 = call i32 @parse(i8* %14, i32 %16, double* %7)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %9
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %9
%22 = load double, double* %7
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %22)
br label %9
}

LLVM IR (-O2):
@.str = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.2 = [4 x i8] c"%g\0A\00"
@str = [33 x i8] c"Please enter a valid expression\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [100 x i8]
%4 = alloca double
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = bitcast double* %4 to i8*
br label %7
7: ; preds = %16, %2
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %5, i32 100, i32 %9)
%11 = call i32 @len(i8* %5)
%12 = call i32 @parse(i8* %5, i32 %11, double* %4)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %7
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %16
16: ; preds = %14, %7
%17 = load double, double* %4
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %17)
br label %7
}