#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*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
double rpn_eval(char *, double);
int /*<<< orphan*/ sscanf(char *, char *, double *);
int main(int argc, char **argv) {
  printf("RPN Calculator.\n");
  if (argc < 2) {
    printf("Usage: rpncalc filename [xvalue]\n");
    exit(1);
  }
  char *fileName = argv[1];
  double x = 0;
  if (argc > 2) {
    sscanf(argv[2], "%lf", &x);
  }
  double result = rpn_eval(fileName, x);
  printf("Result: %lf\n", result);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
jge    1186 <main+0x46>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11bc <main+0x7c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe80(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <sscanf@plt>
mov    -0x18(%rbp),%rdi
movsd  -0x20(%rbp),%xmm0
call   1060 <rpn_eval@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    0xe5c(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xead(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x1,%ebp
jle    11bf <main+0x6f>
mov    0x8(%rbx),%r14
movq   $0x0,0x8(%rsp)
xorps  %xmm0,%xmm0
cmp    $0x2,%ebp
je     119e <main+0x4e>
mov    0x10(%rbx),%rdi
lea    0xe72(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1050 <sscanf@plt>
movsd  0x8(%rsp),%xmm0
mov    %r14,%rdi
call   1070 <rpn_eval@plt>
lea    0xe57(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"RPN Calculator.\0A\00"
@.str.1 = [34 x i8] c"Usage: rpncalc filename [xvalue]\0A\00"
@.str.2 = [4 x i8] c"%lf\00"
@.str.3 = [13 x i8] c"Result: %lf\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca double
%8 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %6
store double 0.000000e+00, double* %7
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 2
br i1 %20, label %21, label %26
21: ; preds = %15
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @sscanf(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %7)
br label %26
26: ; preds = %21, %15
%27 = load i8*, i8** %6
%28 = load double, double* %7
%29 = call double @rpn_eval(i8* %27, double %28)
store double %29, double* %8
%30 = load double, double* %8
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), double %30)
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str.2 = [4 x i8] c"%lf\00"
@.str.3 = [13 x i8] c"Result: %lf\0A\00"
@str = [16 x i8] c"RPN Calculator.\00"
@str.4 = [33 x i8] c"Usage: rpncalc filename [xvalue]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca double
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.4, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = bitcast double* %3 to i8*
store double 0.000000e+00, double* %3
%13 = icmp eq i32 %0, 2
br i1 %13, label %19, label %14
14: ; preds = %9
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %3)
%18 = load double, double* %3
br label %19
19: ; preds = %14, %9
%20 = phi double [ %18, %14 ], [ 0.000000e+00, %9 ]
%21 = call double @rpn_eval(i8* %11, double %20)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), double %21)
ret i32 0
}