#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 calc_string(char *);
double calculate(char, int, int);
double pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char *test[] = {"((((((3+(((((5*4)*5))))))))))",
                  "(13+14)*5",
                  "(13-14)*5",
                  "3*(4+5)",
                  "3+(4*5)^2",
                  "3*(4-5)^2",
                  "3*4^(5-2)",
                  "3+4*5-4*2+3",
                  "3+4*(5*4-18)^2+3",
                  "3*4*(5-2*4)",
                  "(3^(((2*3-4^1*(2-1)+4*2))))+3"};
  int i;
  for (i = 0; i < 11; i++)
    printf("%s=%d\n", test[i], calc_string(test[i]));
  printf("%f %f\n", calculate('^', -4, 2), pow(4, 0.5));
  for (i = 0; i < 5; i++)
    printf("%d %f\n", i, pow(i, 2));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x60(%rbp),%rdi
lea    0x2c53(%rip),%rsi
mov    $0x58,%edx
call   1050 <memcpy@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0xb,-0x64(%rbp)
jge    11c5 <main+0x75>
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rax
mov    %rax,-0x70(%rbp)
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rdi
call   1060 <calc_string@plt>
mov    -0x70(%rbp),%rsi
mov    %eax,%edx
lea    0xeef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    117e <main+0x2e>
mov    $0x5e,%edi
mov    $0xfffffffc,%esi
mov    $0x2,%edx
call   1040 <calculate@plt>
movsd  %xmm0,-0x78(%rbp)
mov    $0x4,%edi
xor    %esi,%esi
call   1070 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
lea    0xead(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0x5,-0x64(%rbp)
jge    1243 <main+0xf3>
mov    -0x64(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x64(%rbp),%edi
mov    $0x2,%esi
call   1070 <pow@plt>
mov    -0x7c(%rbp),%esi
lea    0xe7f(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1207 <main+0xb7>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rbx
mov    %rbx,%rdi
call   1050 <calc_string@plt>
lea    0xf45(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeae(%rip),%rbx
mov    %rbx,%rdi
call   1050 <calc_string@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe9a(%rip),%rbx
mov    %rbx,%rdi
call   1050 <calc_string@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe86(%rip),%rbx
mov    %rbx,%rdi
call   1050 <calc_string@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe70(%rip),%rbx
mov    %rbx,%rdi
call   1050 <calc_string@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe5c(%rip),%rbx
mov    %rbx,%rdi
call   1050 <calc_string@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe48(%rip),%rbx
mov    %rbx,%rdi
call   1050 <calc_string@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe34(%rip),%rbx
mov    %rbx,%rdi
call   1050 <calc_string@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe22(%rip),%rbx
mov    %rbx,%rdi
call   1050 <calc_string@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe15(%rip),%rbx
mov    %rbx,%rdi
call   1050 <calc_string@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe03(%rip),%rbx
mov    %rbx,%rdi
call   1050 <calc_string@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x5e,%edi
mov    $0xfffffffc,%esi
mov    $0x2,%edx
call   1040 <calculate@plt>
movsd  %xmm0,(%rsp)
mov    $0x4,%edi
xor    %esi,%esi
call   1060 <pow@plt>
movaps %xmm0,%xmm1
lea    0xde2(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x2,%al
call   1030 <printf@plt>
xor    %edi,%edi
mov    $0x2,%esi
call   1060 <pow@plt>
lea    0xdca(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1,%al
call   1030 <printf@plt>
mov    $0x1,%edi
mov    $0x2,%esi
call   1060 <pow@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%al
call   1030 <printf@plt>
mov    $0x2,%edi
mov    $0x2,%esi
call   1060 <pow@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x1,%al
call   1030 <printf@plt>
mov    $0x3,%edi
mov    $0x2,%esi
call   1060 <pow@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x1,%al
call   1030 <printf@plt>
mov    $0x4,%edi
mov    $0x2,%esi
call   1060 <pow@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [30 x i8] c"((((((3+(((((5*4)*5))))))))))\00"
@.str.1 = [10 x i8] c"(13+14)*5\00"
@.str.2 = [10 x i8] c"(13-14)*5\00"
@.str.3 = [8 x i8] c"3*(4+5)\00"
@.str.4 = [10 x i8] c"3+(4*5)^2\00"
@.str.5 = [10 x i8] c"3*(4-5)^2\00"
@.str.6 = [10 x i8] c"3*4^(5-2)\00"
@.str.7 = [12 x i8] c"3+4*5-4*2+3\00"
@.str.8 = [17 x i8] c"3+4*(5*4-18)^2+3\00"
@.str.9 = [12 x i8] c"3*4*(5-2*4)\00"
@.str.10 = [30 x i8] c"(3^(((2*3-4^1*(2-1)+4*2))))+3\00"
@__const.main.test = [11 x i8*] [i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i32 0, i32 0)]
@.str.11 = [7 x i8] c"%s=%d\0A\00"
@.str.12 = [7 x i8] c"%f %f\0A\00"
@.str.13 = [7 x i8] c"%d %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [11 x i8*]
%3 = alloca i32
store i32 0, i32* %1
%4 = bitcast [11 x i8*]* %2 to i8*
store i32 0, i32* %3
br label %5
5: ; preds = %19, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 11
br i1 %7, label %8, label %22
8: ; preds = %5
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [11 x i8*], [11 x i8*]* %2, i64 0, i64 %10
%12 = load i8*, i8** %11
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [11 x i8*], [11 x i8*]* %2, i64 0, i64 %14
%16 = load i8*, i8** %15
%17 = call i32 @calc_string(i8* %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* %12, i32 %17)
br label %19
19: ; preds = %8
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %5
22: ; preds = %5
%23 = call double @calculate(i8 signext 94, i32 -4, i32 2)
%24 = call double @pow(i32 4, i32 0)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), double %23, double %24)
store i32 0, i32* %3
br label %26
26: ; preds = %34, %22
%27 = load i32, i32* %3
%28 = icmp slt i32 %27, 5
br i1 %28, label %29, label %37
29: ; preds = %26
%30 = load i32, i32* %3
%31 = load i32, i32* %3
%32 = call double @pow(i32 %31, i32 2)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0), i32 %30, double %32)
br label %34
34: ; preds = %29
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %26
37: ; preds = %26
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"((((((3+(((((5*4)*5))))))))))\00"
@.str.1 = [10 x i8] c"(13+14)*5\00"
@.str.2 = [10 x i8] c"(13-14)*5\00"
@.str.3 = [8 x i8] c"3*(4+5)\00"
@.str.4 = [10 x i8] c"3+(4*5)^2\00"
@.str.5 = [10 x i8] c"3*(4-5)^2\00"
@.str.6 = [10 x i8] c"3*4^(5-2)\00"
@.str.7 = [12 x i8] c"3+4*5-4*2+3\00"
@.str.8 = [17 x i8] c"3+4*(5*4-18)^2+3\00"
@.str.9 = [12 x i8] c"3*4*(5-2*4)\00"
@.str.10 = [30 x i8] c"(3^(((2*3-4^1*(2-1)+4*2))))+3\00"
@.str.11 = [7 x i8] c"%s=%d\0A\00"
@.str.12 = [7 x i8] c"%f %f\0A\00"
@.str.13 = [7 x i8] c"%d %f\0A\00"
define i32 @main() {
%1 = tail call i32 @calc_string(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 @calc_string(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = tail call i32 @calc_string(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = tail call i32 @calc_string(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %7)
%9 = tail call i32 @calc_string(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %9)
%11 = tail call i32 @calc_string(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %11)
%13 = tail call i32 @calc_string(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %13)
%15 = tail call i32 @calc_string(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %15)
%17 = tail call i32 @calc_string(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i32 %17)
%19 = tail call i32 @calc_string(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0))
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i32 %19)
%21 = tail call i32 @calc_string(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0))
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0), i32 %21)
%23 = tail call double @calculate(i8 signext 94, i32 -4, i32 2)
%24 = tail call double @pow(i32 4, i32 0)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), double %23, double %24)
%26 = tail call double @pow(i32 0, i32 2)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0), i32 0, double %26)
%28 = tail call double @pow(i32 1, i32 2)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0), i32 1, double %28)
%30 = tail call double @pow(i32 2, i32 2)
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0), i32 2, double %30)
%32 = tail call double @pow(i32 3, i32 2)
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0), i32 3, double %32)
%34 = tail call double @pow(i32 4, i32 2)
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0), i32 4, double %34)
ret i32 0
}