#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 */
char *clearBrackets(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char);
int stackLength();
char *stackPop();
int /*<<< orphan*/ stackPush(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *prefixToX(char *s, int outputFormat) {
  int i;
  char *out = (char *)malloc(sizeof(char) * 100);
  char *buffer = (char *)malloc(sizeof(char) * 100);
  char *stringA = (char *)malloc(sizeof(char) * 100);
  char *stringB = (char *)malloc(sizeof(char) * 100);
  for (i = strlen(s) - 1; i >= 0; i--) {
    switch (s[i]) {
    case '^':
    case '/':
    case '*':
    case '+':
    case '-':
      strcpy(out, "");
      sprintf(buffer, "%c", s[i]);
      if (stackLength() < 2) {
        return "Invalid infix string. Check your operators and operands.\n";
      } else {
        if (outputFormat == 2) {
          strcpy(stringA, stackPop());
          strcpy(stringB, stackPop());
          strcat(out, "(");
          strcat(out, stringA);
          strcat(out, buffer);
          strcat(out, stringB);
          strcat(out, ")");
          stackPush(out);
        } else if (outputFormat == 3) {
          strcpy(stringA, stackPop());
          strcpy(stringB, stackPop());
          strcat(out, stringA);
          strcat(out, stringB);
          strcat(out, buffer);
          stackPush(out);
        }
      }
      break;
    default:
      sprintf(buffer, "%c", s[i]);
      stackPush(buffer);
      break;
    }
  }
  if (stackLength() > 1) {
    return "Invalid infix string. Check your operators and operands.\n";
  } else {
    if (outputFormat == 2)
      return clearBrackets(stackPop());
    else
      return stackPop();
  }
}


x86 assembly (clang, -O0):
<prefixToX>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     13db <prefixToX+0x24b>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x3c(%rbp)
add    $0xffffffd6,%eax
sub    $0x2,%eax
jb     1243 <prefixToX+0xb3>
jmp    1210 <prefixToX+0x80>
mov    -0x3c(%rbp),%eax
sub    $0x2d,%eax
je     1243 <prefixToX+0xb3>
jmp    1221 <prefixToX+0x91>
mov    -0x3c(%rbp),%eax
sub    $0x2f,%eax
je     1243 <prefixToX+0xb3>
jmp    1232 <prefixToX+0xa2>
mov    -0x3c(%rbp),%eax
sub    $0x5e,%eax
jne    13a3 <prefixToX+0x213>
jmp    1243 <prefixToX+0xb3>
mov    -0x20(%rbp),%rdi
lea    0xdee(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
lea    0xd9a(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   10a0 <sprintf@plt>
mov    $0x0,%al
call   1050 <stackLength@plt>
cmp    $0x2,%eax
jge    128f <prefixToX+0xff>
lea    0xd7d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1428 <prefixToX+0x298>
cmpl   $0x2,-0x14(%rbp)
jne    1324 <prefixToX+0x194>
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   1090 <stackPop@plt>
mov    -0x50(%rbp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   1090 <stackPop@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xd63(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xd2e(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
call   10b0 <stackPush@plt>
jmp    1399 <prefixToX+0x209>
cmpl   $0x3,-0x14(%rbp)
jne    1394 <prefixToX+0x204>
mov    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    $0x0,%al
call   1090 <stackPop@plt>
mov    -0x60(%rbp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   1090 <stackPop@plt>
mov    -0x58(%rbp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
call   10b0 <stackPush@plt>
jmp    1399 <prefixToX+0x209>
jmp    139e <prefixToX+0x20e>
jmp    13c8 <prefixToX+0x238>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
lea    0xc4a(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   10a0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   10b0 <stackPush@plt>
jmp    13cd <prefixToX+0x23d>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    11e6 <prefixToX+0x56>
mov    $0x0,%al
call   1050 <stackLength@plt>
cmp    $0x1,%eax
jle    13fb <prefixToX+0x26b>
lea    0xc11(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1428 <prefixToX+0x298>
cmpl   $0x2,-0x14(%rbp)
jne    141d <prefixToX+0x28d>
mov    $0x0,%al
call   1090 <stackPop@plt>
mov    %rax,%rdi
call   1070 <clearBrackets@plt>
mov    %rax,-0x8(%rbp)
jmp    1428 <prefixToX+0x298>
mov    $0x0,%al
call   1090 <stackPop@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prefixToX>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebx
mov    %rdi,%rbp
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,0x20(%rsp)
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,0x18(%rsp)
mov    %rbp,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    134a <prefixToX+0x1ca>
mov    %eax,%r12d
add    $0x1,%r12
mov    %ebx,0xc(%rsp)
mov    %rbp,0x10(%rsp)
jmp    125e <prefixToX+0xde>
nopl   (%rax)
xor    %eax,%eax
call   1090 <stackPop@plt>
mov    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
call   1090 <stackPop@plt>
mov    0x18(%rsp),%rbp
mov    %rbp,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    0xc(%rsp),%ebx
call   1080 <strcat@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    0x10(%rsp),%rbp
call   1080 <strcat@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
mov    %r15,%rdi
call   10a0 <stackPush@plt>
add    $0xffffffffffffffff,%r12
cmp    $0x1,%r12
jbe    134a <prefixToX+0x1ca>
lea    -0x2(%r12),%r13d
movsbl 0x0(%rbp,%r13,1),%eax
lea    -0x2a(%rax),%ecx
cmp    $0x34,%ecx
ja     133a <prefixToX+0x1ba>
movabs $0x1000000000002b,%rdx
bt     %rcx,%rdx
jae    133a <prefixToX+0x1ba>
mov    %r15,%rdi
lea    0xda6(%rip),%rsi
call   1030 <strcpy@plt>
movzbl 0x0(%rbp,%r13,1),%eax
mov    %al,(%r14)
movb   $0x0,0x1(%r14)
xor    %eax,%eax
call   1050 <stackLength@plt>
cmp    $0x2,%eax
jl     1356 <prefixToX+0x1d6>
cmp    $0x3,%ebx
je     11f0 <prefixToX+0x70>
cmp    $0x2,%ebx
jne    1250 <prefixToX+0xd0>
xor    %eax,%eax
call   1090 <stackPop@plt>
mov    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
call   1090 <stackPop@plt>
mov    0x18(%rsp),%rbp
mov    %rbp,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
lea    0xd3e(%rip),%rsi
call   1080 <strcat@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    0xc(%rsp),%ebx
call   1080 <strcat@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    0x10(%rsp),%rbp
call   1080 <strcat@plt>
mov    %r15,%rdi
lea    0xd07(%rip),%rsi
jmp    1243 <prefixToX+0xc3>
mov    %al,(%r14)
movb   $0x0,0x1(%r14)
mov    %r14,%rdi
jmp    124b <prefixToX+0xcb>
xor    %eax,%eax
call   1050 <stackLength@plt>
cmp    $0x1,%eax
jle    135f <prefixToX+0x1df>
lea    0xca3(%rip),%rax
jmp    1381 <prefixToX+0x201>
xor    %eax,%eax
call   1090 <stackPop@plt>
cmp    $0x2,%ebx
jne    1381 <prefixToX+0x201>
mov    %rax,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <clearBrackets@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [58 x i8] c"Invalid infix string. Check your operators and operands.\0A\00"
@.str.3 = [2 x i8] c"(\00"
@.str.4 = [2 x i8] c")\00"
define i8* @prefixToX(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%11 = call i64 @malloc(i32 100)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %7
%13 = call i64 @malloc(i32 100)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %8
%15 = call i64 @malloc(i32 100)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %9
%17 = call i64 @malloc(i32 100)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %10
%19 = load i8*, i8** %4
%20 = call i32 @strlen(i8* %19)
%21 = sub nsw i32 %20, 1
store i32 %21, i32* %6
br label %22
22: ; preds = %105, %2
%23 = load i32, i32* %6
%24 = icmp sge i32 %23, 0
br i1 %24, label %25, label %108
25: ; preds = %22
%26 = load i8*, i8** %4
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
switch i32 %31, label %94 [
i32 94, label %32
i32 47, label %32
i32 42, label %32
i32 43, label %32
i32 45, label %32
]
32: ; preds = %25, %25, %25, %25, %25
%33 = load i8*, i8** %7
%34 = call i32 @strcpy(i8* %33, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%35 = load i8*, i8** %8
%36 = load i8*, i8** %4
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = call i32 @sprintf(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %40)
%42 = call i32 (...) @stackLength()
%43 = icmp slt i32 %42, 2
br i1 %43, label %44, label %45
44: ; preds = %32
store i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %120
45: ; preds = %32
%46 = load i32, i32* %5
%47 = icmp eq i32 %46, 2
br i1 %47, label %48, label %70
48: ; preds = %45
%49 = load i8*, i8** %9
%50 = call i8* (...) @stackPop()
%51 = call i32 @strcpy(i8* %49, i8* %50)
%52 = load i8*, i8** %10
%53 = call i8* (...) @stackPop()
%54 = call i32 @strcpy(i8* %52, i8* %53)
%55 = load i8*, i8** %7
%56 = call i32 @strcat(i8* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%57 = load i8*, i8** %7
%58 = load i8*, i8** %9
%59 = call i32 @strcat(i8* %57, i8* %58)
%60 = load i8*, i8** %7
%61 = load i8*, i8** %8
%62 = call i32 @strcat(i8* %60, i8* %61)
%63 = load i8*, i8** %7
%64 = load i8*, i8** %10
%65 = call i32 @strcat(i8* %63, i8* %64)
%66 = load i8*, i8** %7
%67 = call i32 @strcat(i8* %66, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%68 = load i8*, i8** %7
%69 = call i32 @stackPush(i8* %68)
br label %92
70: ; preds = %45
%71 = load i32, i32* %5
%72 = icmp eq i32 %71, 3
br i1 %72, label %73, label %91
73: ; preds = %70
%74 = load i8*, i8** %9
%75 = call i8* (...) @stackPop()
%76 = call i32 @strcpy(i8* %74, i8* %75)
%77 = load i8*, i8** %10
%78 = call i8* (...) @stackPop()
%79 = call i32 @strcpy(i8* %77, i8* %78)
%80 = load i8*, i8** %7
%81 = load i8*, i8** %9
%82 = call i32 @strcat(i8* %80, i8* %81)
%83 = load i8*, i8** %7
%84 = load i8*, i8** %10
%85 = call i32 @strcat(i8* %83, i8* %84)
%86 = load i8*, i8** %7
%87 = load i8*, i8** %8
%88 = call i32 @strcat(i8* %86, i8* %87)
%89 = load i8*, i8** %7
%90 = call i32 @stackPush(i8* %89)
br label %91
91: ; preds = %73, %70
br label %92
92: ; preds = %91, %48
br label %93
93: ; preds = %92
br label %104
94: ; preds = %25
%95 = load i8*, i8** %8
%96 = load i8*, i8** %4
%97 = load i32, i32* %6
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8, i8* %96, i64 %98
%100 = load i8, i8* %99
%101 = call i32 @sprintf(i8* %95, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %100)
%102 = load i8*, i8** %8
%103 = call i32 @stackPush(i8* %102)
br label %104
104: ; preds = %94, %93
br label %105
105: ; preds = %104
%106 = load i32, i32* %6
%107 = add nsw i32 %106, -1
store i32 %107, i32* %6
br label %22
108: ; preds = %22
%109 = call i32 (...) @stackLength()
%110 = icmp sgt i32 %109, 1
br i1 %110, label %111, label %112
111: ; preds = %108
store i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %120
112: ; preds = %108
%113 = load i32, i32* %5
%114 = icmp eq i32 %113, 2
br i1 %114, label %115, label %118
115: ; preds = %112
%116 = call i8* (...) @stackPop()
%117 = call i8* @clearBrackets(i8* %116)
store i8* %117, i8** %3
br label %120
118: ; preds = %112
%119 = call i8* (...) @stackPop()
store i8* %119, i8** %3
br label %120
120: ; preds = %118, %115, %111, %44
%121 = load i8*, i8** %3
ret i8* %121
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.2 = [58 x i8] c"Invalid infix string. Check your operators and operands.\0A\00"
@.str.3 = [2 x i8] c"(\00"
@.str.4 = [2 x i8] c")\00"
define i8* @prefixToX(i8* %0, i32 %1) {
%3 = tail call i64 @malloc(i32 100)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i64 @malloc(i32 100)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i64 @malloc(i32 100)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i64 @malloc(i32 100)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @strlen(i8* %0)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %53
13: ; preds = %2
%14 = getelementptr i8, i8* %6, i64 1
%15 = zext i32 %11 to i64
br label %16
16: ; preds = %13, %51
%17 = phi i64 [ %15, %13 ], [ %18, %51 ]
%18 = add nsw i64 %17, -1
%19 = and i64 %18, 4294967295
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
switch i32 %22, label %49 [
i32 94, label %23
i32 47, label %23
i32 42, label %23
i32 43, label %23
i32 45, label %23
]
23: ; preds = %16, %16, %16, %16, %16
%24 = tail call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%25 = load i8, i8* %20
store i8 %25, i8* %6
store i8 0, i8* %14
%26 = tail call i32 (...) @stackLength()
%27 = icmp slt i32 %26, 2
br i1 %27, label %61, label %28
28: ; preds = %23
switch i32 %1, label %51 [
i32 2, label %29
i32 3, label %40
]
29: ; preds = %28
%30 = tail call i8* (...) @stackPop()
%31 = tail call i32 @strcpy(i8* %8, i8* %30)
%32 = tail call i8* (...) @stackPop()
%33 = tail call i32 @strcpy(i8* %10, i8* %32)
%34 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%35 = tail call i32 @strcat(i8* %4, i8* %8)
%36 = tail call i32 @strcat(i8* %4, i8* %6)
%37 = tail call i32 @strcat(i8* %4, i8* %10)
%38 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%39 = tail call i32 @stackPush(i8* %4)
br label %51
40: ; preds = %28
%41 = tail call i8* (...) @stackPop()
%42 = tail call i32 @strcpy(i8* %8, i8* %41)
%43 = tail call i8* (...) @stackPop()
%44 = tail call i32 @strcpy(i8* %10, i8* %43)
%45 = tail call i32 @strcat(i8* %4, i8* %8)
%46 = tail call i32 @strcat(i8* %4, i8* %10)
%47 = tail call i32 @strcat(i8* %4, i8* %6)
%48 = tail call i32 @stackPush(i8* %4)
br label %51
49: ; preds = %16
store i8 %21, i8* %6
store i8 0, i8* %14
%50 = tail call i32 @stackPush(i8* %6)
br label %51
51: ; preds = %28, %49, %29, %40
%52 = icmp ugt i64 %17, 1
br i1 %52, label %16, label %53
53: ; preds = %51, %2
%54 = tail call i32 (...) @stackLength()
%55 = icmp sgt i32 %54, 1
br i1 %55, label %61, label %56
56: ; preds = %53
%57 = icmp eq i32 %1, 2
%58 = tail call i8* (...) @stackPop()
br i1 %57, label %59, label %61
59: ; preds = %56
%60 = tail call i8* @clearBrackets(i8* %58)
br label %61
61: ; preds = %23, %56, %53, %59
%62 = phi i8* [ %60, %59 ], [ getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), %53 ], [ %58, %56 ], [ getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), %23 ]
ret i8* %62
}