#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 EvalInfix(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
double eval_infix(int *ierr, const char *strExpression, int len) {
  double result = 0.0;
  char strHelper[257];
  char strError[257];
  int i;
  if (len > 256) {
    printf("[eval_infix.c] expression longer than 256 characters\n");
    ierr[0] = 1;
    return result;
  }
  for (i = 0; i < len; i++)
    strHelper[i] = ' ';
  strHelper[len] = '\0';
  for (i = 0; i < len; i++)
    strHelper[i] = strExpression[i];
  for (i = 0; i < len; i++)
    strError[i] = ' ';
  strError[len] = '\0';
  result = EvalInfix(strHelper, strError);
  if (strError[0] != '\0') {
    printf("[eval_infix.c] A parsing error occurred\n");
    printf("helper string:\n%s\n", strHelper);
    printf("error code:   \n%s\n", strError);
    ierr[0] = 1;
  } else
    ierr[0] = 0;
  return result;
}


x86 assembly (clang, -O0):
<eval_infix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x100,-0x1c(%rbp)
jle    1172 <eval_infix+0x52>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12ce <eval_infix+0x1ae>
movl   $0x0,-0x244(%rbp)
mov    -0x244(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ae <eval_infix+0x8e>
movslq -0x244(%rbp),%rax
movb   $0x20,-0x130(%rbp,%rax,1)
20
mov    -0x244(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x244(%rbp)
jmp    117c <eval_infix+0x5c>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x130(%rbp,%rax,1)
movl   $0x0,-0x244(%rbp)
mov    -0x244(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1203 <eval_infix+0xe3>
mov    -0x18(%rbp),%rax
movslq -0x244(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x244(%rbp),%rax
mov    %cl,-0x130(%rbp,%rax,1)
mov    -0x244(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x244(%rbp)
jmp    11c4 <eval_infix+0xa4>
movl   $0x0,-0x244(%rbp)
mov    -0x244(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    123f <eval_infix+0x11f>
movslq -0x244(%rbp),%rax
movb   $0x20,-0x240(%rbp,%rax,1)
20
mov    -0x244(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x244(%rbp)
jmp    120d <eval_infix+0xed>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x240(%rbp,%rax,1)
lea    -0x130(%rbp),%rdi
lea    -0x240(%rbp),%rsi
call   1040 <EvalInfix@plt>
movsd  %xmm0,-0x28(%rbp)
movsbl -0x240(%rbp),%eax
cmp    $0x0,%eax
je     12ba <eval_infix+0x19a>
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x130(%rbp),%rsi
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x240(%rbp),%rsi
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
jmp    12c4 <eval_infix+0x1a4>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eval_infix>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %rdi,%r14
cmp    $0x100,%edx
jle    117d <eval_infix+0x2d>
lea    0xede(%rip),%rdi
call   1030 <puts@plt>
xorps  %xmm0,%xmm0
jmp    1232 <eval_infix+0xe2>
test   %edx,%edx
jle    11c8 <eval_infix+0x78>
mov    %rsi,%r15
mov    %edx,%ebx
lea    0x120(%rsp),%r12
mov    %r12,%rdi
mov    $0x20,%esi
mov    %rbx,%rdx
call   1050 <memset@plt>
movb   $0x0,0x120(%rsp,%rbx,1)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <memcpy@plt>
lea    0x10(%rsp),%rdi
mov    $0x20,%esi
mov    %rbx,%rdx
call   1050 <memset@plt>
jmp    11d3 <eval_infix+0x83>
movslq %edx,%rbx
movb   $0x0,0x120(%rsp,%rbx,1)
movb   $0x0,0x10(%rsp,%rbx,1)
lea    0x120(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1070 <EvalInfix@plt>
cmpb   $0x0,0x10(%rsp)
je     1239 <eval_infix+0xe9>
lea    0xe2e(%rip),%rdi
movsd  %xmm0,0x8(%rsp)
call   1030 <puts@plt>
lea    0xdf6(%rip),%rdi
lea    0x120(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdf3(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
mov    $0x1,%eax
jmp    123b <eval_infix+0xeb>
xor    %eax,%eax
mov    %eax,(%r14)
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [54 x i8] c"[eval_infix.c] expression longer than 256 characters\0A\00"
@.str.1 = [41 x i8] c"[eval_infix.c] A parsing error occurred\0A\00"
@.str.2 = [19 x i8] c"helper string:\0A%s\0A\00"
@.str.3 = [19 x i8] c"error code: \0A%s\0A\00"
define double @eval_infix(i32* %0, i8* %1, i32 %2) {
%4 = alloca double
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca double
%9 = alloca [257 x i8]
%10 = alloca [257 x i8]
%11 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store double 0.000000e+00, double* %8
%12 = load i32, i32* %7
%13 = icmp sgt i32 %12, 256
br i1 %13, label %14, label %19
14: ; preds = %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%16 = load i32*, i32** %5
%17 = getelementptr inbounds i32, i32* %16, i64 0
store i32 1, i32* %17
%18 = load double, double* %8
store double %18, double* %4
br label %87
19: ; preds = %3
store i32 0, i32* %11
br label %20
20: ; preds = %28, %19
%21 = load i32, i32* %11
%22 = load i32, i32* %7
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %31
24: ; preds = %20
%25 = load i32, i32* %11
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [257 x i8], [257 x i8]* %9, i64 0, i64 %26
store i8 32, i8* %27
br label %28
28: ; preds = %24
%29 = load i32, i32* %11
%30 = add nsw i32 %29, 1
store i32 %30, i32* %11
br label %20
31: ; preds = %20
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [257 x i8], [257 x i8]* %9, i64 0, i64 %33
store i8 0, i8* %34
store i32 0, i32* %11
br label %35
35: ; preds = %48, %31
%36 = load i32, i32* %11
%37 = load i32, i32* %7
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %51
39: ; preds = %35
%40 = load i8*, i8** %6
%41 = load i32, i32* %11
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = load i32, i32* %11
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [257 x i8], [257 x i8]* %9, i64 0, i64 %46
store i8 %44, i8* %47
br label %48
48: ; preds = %39
%49 = load i32, i32* %11
%50 = add nsw i32 %49, 1
store i32 %50, i32* %11
br label %35
51: ; preds = %35
store i32 0, i32* %11
br label %52
52: ; preds = %60, %51
%53 = load i32, i32* %11
%54 = load i32, i32* %7
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %63
56: ; preds = %52
%57 = load i32, i32* %11
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [257 x i8], [257 x i8]* %10, i64 0, i64 %58
store i8 32, i8* %59
br label %60
60: ; preds = %56
%61 = load i32, i32* %11
%62 = add nsw i32 %61, 1
store i32 %62, i32* %11
br label %52
63: ; preds = %52
%64 = load i32, i32* %7
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [257 x i8], [257 x i8]* %10, i64 0, i64 %65
store i8 0, i8* %66
%67 = getelementptr inbounds [257 x i8], [257 x i8]* %9, i64 0, i64 0
%68 = getelementptr inbounds [257 x i8], [257 x i8]* %10, i64 0, i64 0
%69 = call double @EvalInfix(i8* %67, i8* %68)
store double %69, double* %8
%70 = getelementptr inbounds [257 x i8], [257 x i8]* %10, i64 0, i64 0
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %82
74: ; preds = %63
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%76 = getelementptr inbounds [257 x i8], [257 x i8]* %9, i64 0, i64 0
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %76)
%78 = getelementptr inbounds [257 x i8], [257 x i8]* %10, i64 0, i64 0
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %78)
%80 = load i32*, i32** %5
%81 = getelementptr inbounds i32, i32* %80, i64 0
store i32 1, i32* %81
br label %85
82: ; preds = %63
%83 = load i32*, i32** %5
%84 = getelementptr inbounds i32, i32* %83, i64 0
store i32 0, i32* %84
br label %85
85: ; preds = %82, %74
%86 = load double, double* %8
store double %86, double* %4
br label %87
87: ; preds = %85, %14
%88 = load double, double* %4
ret double %88
}

LLVM IR (-O2):
@.str.2 = [19 x i8] c"helper string:\0A%s\0A\00"
@.str.3 = [19 x i8] c"error code: \0A%s\0A\00"
@str = [40 x i8] c"[eval_infix.c] A parsing error occurred\00"
@str.4 = [53 x i8] c"[eval_infix.c] expression longer than 256 characters\00"
define double @eval_infix(i32* nocapture writeonly %0, i8* nocapture %1, i32 %2) {
%4 = alloca [257 x i8]
%5 = getelementptr inbounds [257 x i8], [257 x i8]* %4, i64 0, i64 0
%6 = alloca [257 x i8]
%7 = getelementptr inbounds [257 x i8], [257 x i8]* %6, i64 0, i64 0
%8 = getelementptr inbounds [257 x i8], [257 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [257 x i8], [257 x i8]* %6, i64 0, i64 0
%10 = icmp sgt i32 %2, 256
br i1 %10, label %13, label %11
11: ; preds = %3
%12 = icmp sgt i32 %2, 0
br i1 %12, label %18, label %15
13: ; preds = %3
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.4, i64 0, i64 0))
br label %34
15: ; preds = %11
%16 = sext i32 %2 to i64
%17 = getelementptr inbounds [257 x i8], [257 x i8]* %4, i64 0, i64 %16
store i8 0, i8* %17
br label %24
18: ; preds = %11
%19 = zext i32 %2 to i64
%20 = zext i32 %2 to i64
%21 = getelementptr inbounds [257 x i8], [257 x i8]* %4, i64 0, i64 %20
store i8 0, i8* %21
%22 = zext i32 %2 to i64
%23 = zext i32 %2 to i64
br label %24
24: ; preds = %15, %18
%25 = phi i64 [ %20, %18 ], [ %16, %15 ]
%26 = getelementptr inbounds [257 x i8], [257 x i8]* %6, i64 0, i64 %25
store i8 0, i8* %26
%27 = call double @EvalInfix(i8* %8, i8* %9)
%28 = load i8, i8* %9
%29 = icmp eq i8 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %24
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %9)
br label %34
34: ; preds = %30, %24, %13
%35 = phi i32 [ 1, %13 ], [ 1, %30 ], [ 0, %24 ]
%36 = phi double [ 0.000000e+00, %13 ], [ %27, %30 ], [ %27, %24 ]
store i32 %35, i32* %0
ret double %36
}