#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 evaluate_expression(char *);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ strcat(char *, char *);
int main(int argc, char *argv[]) {
  char input[1000] = {0};
  if (argc == 1) {
    puts("usage: ./exercise_5-10.out <arg1> <arg2> ...");
    return -1;
  }
  for (int i = 1; i < argc; ++i) {
    if (i == 1000 - 1) {
      puts("error: too much input");
      break;
    } else {
      strcat(input, (i == 1 ? "" : " "));
      strcat(input, argv[i]);
    }
  }
  int type;
  char token[100];
  double result = evaluate_expression(input);
  printf("%g\n", result);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x480,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x400(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1050 <memset@plt>
cmpl   $0x1,-0x8(%rbp)
jne    119e <main+0x4e>
lea    0xe73(%rip),%rdi
call   1030 <puts@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1262 <main+0x112>
movl   $0x1,-0x404(%rbp)
mov    -0x404(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1233 <main+0xe3>
cmpl   $0x3e7,-0x404(%rbp)
jne    11d8 <main+0x88>
lea    0xe5f(%rip),%rdi
call   1030 <puts@plt>
jmp    1233 <main+0xe3>
lea    -0x400(%rbp),%rdi
mov    -0x404(%rbp),%ecx
lea    0xe57(%rip),%rsi
lea    0xe55(%rip),%rax
cmp    $0x1,%ecx
cmove  %rax,%rsi
call   1060 <strcat@plt>
lea    -0x400(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x404(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcat@plt>
jmp    121f <main+0xcf>
mov    -0x404(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x404(%rbp)
jmp    11a8 <main+0x58>
lea    -0x400(%rbp),%rdi
call   1070 <evaluate_expression@plt>
movsd  %xmm0,-0x478(%rbp)
ff
movsd  -0x478(%rbp),%xmm0
ff
lea    0xdef(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x480,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3e8,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
mov    %rsp,%rdi
mov    $0x3e8,%edx
xor    %esi,%esi
call   1050 <memset@plt>
cmp    $0x1,%ebx
jne    118d <main+0x3d>
lea    0xe7f(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    1205 <main+0xb5>
jle    11ef <main+0x9f>
mov    %ebx,%r15d
add    $0xffffffffffffffff,%r15
xor    %ebx,%ebx
lea    0xea9(%rip),%r13
lea    0xe9d(%rip),%rbp
mov    %rsp,%r12
nopl   0x0(%rax)
cmp    $0x3e6,%rbx
je     11e3 <main+0x93>
test   %rbx,%rbx
mov    %rbp,%rsi
cmove  %r13,%rsi
mov    %r12,%rdi
call   1060 <strcat@plt>
mov    0x8(%r14,%rbx,8),%rsi
mov    %r12,%rdi
call   1060 <strcat@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11b0 <main+0x60>
jmp    11ef <main+0x9f>
lea    0xe43(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1070 <evaluate_expression@plt>
lea    0xe47(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"usage: ./exercise_5-10.out <arg1> <arg2> ...\00"
@.str.1 = [22 x i8] c"error: too much input\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [2 x i8] c" \00"
@.str.4 = [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 [1000 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca [100 x i8]
%10 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [1000 x i8]* %6 to i8*
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @puts(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %49
16: ; preds = %2
store i32 1, i32* %7
br label %17
17: ; preds = %41, %16
%18 = load i32, i32* %7
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %44
21: ; preds = %17
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, 999
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %44
26: ; preds = %21
%27 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, 1
%30 = zext i1 %29 to i64
%31 = select i1 %29, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0)
%32 = call i32 @strcat(i8* %27, i8* %31)
%33 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%34 = load i8**, i8*** %5
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @strcat(i8* %33, i8* %38)
br label %40
40: ; preds = %26
br label %41
41: ; preds = %40
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %17
44: ; preds = %24, %17
%45 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%46 = call double @evaluate_expression(i8* %45)
store double %46, double* %10
%47 = load double, double* %10
%48 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double %47)
store i32 0, i32* %3
br label %49
49: ; preds = %44, %14
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str = [45 x i8] c"usage: ./exercise_5-10.out <arg1> <arg2> ...\00"
@.str.1 = [22 x i8] c"error: too much input\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [2 x i8] c" \00"
@.str.4 = [4 x i8] c"%g\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 1
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %26
8: ; preds = %6
%9 = zext i32 %0 to i64
br label %12
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %29
12: ; preds = %8, %17
%13 = phi i64 [ 1, %8 ], [ %24, %17 ]
%14 = icmp eq i64 %13, 999
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %26
17: ; preds = %12
%18 = icmp eq i64 %13, 1
%19 = select i1 %18, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0)
%20 = call i32 @strcat(i8* %4, i8* %19)
%21 = getelementptr inbounds i8*, i8** %1, i64 %13
%22 = load i8*, i8** %21
%23 = call i32 @strcat(i8* %4, i8* %22)
%24 = add nuw nsw i64 %13, 1
%25 = icmp eq i64 %24, %9
br i1 %25, label %26, label %12
26: ; preds = %17, %6, %15
%27 = call double @evaluate_expression(i8* %4)
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double %27)
br label %29
29: ; preds = %26, %10
%30 = phi i32 [ -1, %10 ], [ 0, %26 ]
ret i32 %30
}