#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__ PolishExpressionParse(char *, double *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(void) {
  char buffer[256] = {0};
  double result = 0.0;
  while (1) {
    printf(">>> ");
    fgets(buffer, 256, stdin);
    if (PolishExpressionParse(buffer, &result) != 0) {
      fprintf(stderr, "Input invalid.\n");
      continue;
    }
    printf("%lf\n", result);
  }
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x118(%rbp)
ff
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e4c(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1050 <fgets@plt>
lea    -0x110(%rbp),%rdi
lea    -0x118(%rbp),%rsi
call   1070 <PolishExpressionParse@plt>
cmp    $0x0,%rax
je     11df <main+0x8f>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1180 <main+0x30>
movsd  -0x118(%rbp),%xmm0
ff
lea    0xe27(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1180 <main+0x30>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xe31(%rip),%r14
mov    0x2e12(%rip),%rbp
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r15
mov    0x2df1(%rip),%r12
lea    0xe17(%rip),%r13
jmp    11fc <main+0xbc>
mov    (%r12),%edi
mov    %r13,%rsi
call   1050 <fprintf@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1040 <fgets@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <PolishExpressionParse@plt>
test   %rax,%rax
jne    11f0 <main+0xb0>
movsd  0x8(%rsp),%xmm0
lea    0xde2(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    11fc <main+0xbc>

LLVM IR (-O0):
@.str = [5 x i8] c">>> \00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"Input invalid.\0A\00"
@.str.2 = [5 x i8] c"%lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca double
store i32 0, i32* %1
%4 = bitcast [256 x i8]* %2 to i8*
store double 0.000000e+00, double* %3
br label %5
5: ; preds = %0, %13, %16
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %7, i32 256, i32 %8)
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%11 = call i64 @PolishExpressionParse(i8* %10, double* %3)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %5
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %5
16: ; preds = %5
%17 = load double, double* %3
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %17)
br label %5
}

LLVM IR (-O2):
@.str = [5 x i8] c">>> \00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"Input invalid.\0A\00"
@.str.2 = [5 x i8] c"%lf\0A\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca double
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = bitcast double* %2 to i8*
store double 0.000000e+00, double* %2
br label %5
5: ; preds = %14, %0
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %3, i32 256, i32 %7)
%9 = call i64 @PolishExpressionParse(i8* %3, double* %2)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %5
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %11, %15
br label %5
15: ; preds = %5
%16 = load double, double* %2
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %16)
br label %14
}