#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 *postfixToX(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 = 0; i < strlen(s); 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, stringB);
          strcat(out, buffer);
          strcat(out, stringA);
          strcat(out, ")");
          stackPush(out);
        } else if (outputFormat == 1) {
          strcpy(stringA, stackPop());
          strcpy(stringB, stackPop());
          strcat(out, buffer);
          strcat(out, stringB);
          strcat(out, stringA);
          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):
<postfixToX>:
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)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cmp    %ecx,%eax
jge    13e5 <postfixToX+0x255>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x40(%rbp)
add    $0xffffffd6,%eax
sub    $0x2,%eax
jb     124d <postfixToX+0xbd>
jmp    121a <postfixToX+0x8a>
mov    -0x40(%rbp),%eax
sub    $0x2d,%eax
je     124d <postfixToX+0xbd>
jmp    122b <postfixToX+0x9b>
mov    -0x40(%rbp),%eax
sub    $0x2f,%eax
je     124d <postfixToX+0xbd>
jmp    123c <postfixToX+0xac>
mov    -0x40(%rbp),%eax
sub    $0x5e,%eax
jne    13ad <postfixToX+0x21d>
jmp    124d <postfixToX+0xbd>
mov    -0x20(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
lea    0xd90(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   10a0 <sprintf@plt>
mov    $0x0,%al
call   1050 <stackLength@plt>
cmp    $0x2,%eax
jge    1299 <postfixToX+0x109>
lea    0xd73(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1432 <postfixToX+0x2a2>
cmpl   $0x2,-0x14(%rbp)
jne    132e <postfixToX+0x19e>
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    0xd59(%rip),%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
mov    -0x30(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xd24(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
call   10b0 <stackPush@plt>
jmp    13a3 <postfixToX+0x213>
cmpl   $0x1,-0x14(%rbp)
jne    139e <postfixToX+0x20e>
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    -0x28(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
call   10b0 <stackPush@plt>
jmp    13a3 <postfixToX+0x213>
jmp    13a8 <postfixToX+0x218>
jmp    13d2 <postfixToX+0x242>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
lea    0xc40(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   10a0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   10b0 <stackPush@plt>
jmp    13d7 <postfixToX+0x247>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11de <postfixToX+0x4e>
mov    $0x0,%al
call   1050 <stackLength@plt>
cmp    $0x1,%eax
jle    1405 <postfixToX+0x275>
lea    0xc07(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1432 <postfixToX+0x2a2>
cmpl   $0x2,-0x14(%rbp)
jne    1427 <postfixToX+0x297>
mov    $0x0,%al
call   1090 <stackPop@plt>
mov    %rax,%rdi
call   1070 <clearBrackets@plt>
mov    %rax,-0x8(%rbp)
jmp    1432 <postfixToX+0x2a2>
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):
<postfixToX>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,0x4(%rsp)
mov    %rdi,%r14
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    133e <postfixToX+0x1be>
xor    %r12d,%r12d
jmp    125e <postfixToX+0xde>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1090 <stackPop@plt>
mov    0x10(%rsp),%r13
mov    %r13,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
call   1090 <stackPop@plt>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1080 <strcat@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1080 <strcat@plt>
mov    %rbp,%rdi
call   10a0 <stackPush@plt>
add    $0x1,%r12
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%r12
jge    133e <postfixToX+0x1be>
movsbl (%r14,%r12,1),%eax
lea    -0x2a(%rax),%ecx
cmp    $0x34,%ecx
ja     132e <postfixToX+0x1ae>
movabs $0x1000000000002b,%rdx
bt     %rcx,%rdx
jae    132e <postfixToX+0x1ae>
mov    %rbp,%rdi
lea    0xdac(%rip),%rsi
call   1030 <strcpy@plt>
movzbl (%r14,%r12,1),%eax
mov    %al,(%r15)
movb   $0x0,0x1(%r15)
xor    %eax,%eax
call   1050 <stackLength@plt>
cmp    $0x2,%eax
jl     134a <postfixToX+0x1ca>
cmpl   $0x1,0x4(%rsp)
je     11f0 <postfixToX+0x70>
cmpl   $0x2,0x4(%rsp)
jne    1247 <postfixToX+0xc7>
xor    %eax,%eax
call   1090 <stackPop@plt>
mov    0x10(%rsp),%r13
mov    %r13,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
call   1090 <stackPop@plt>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
lea    0xd41(%rip),%rsi
call   1080 <strcat@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1080 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1080 <strcat@plt>
mov    %rbp,%rdi
lea    0xd13(%rip),%rsi
jmp    123a <postfixToX+0xba>
mov    %al,(%r15)
movb   $0x0,0x1(%r15)
mov    %r15,%rdi
jmp    1242 <postfixToX+0xc2>
xor    %eax,%eax
call   1050 <stackLength@plt>
cmp    $0x1,%eax
jle    1353 <postfixToX+0x1d3>
lea    0xcaf(%rip),%rax
jmp    1377 <postfixToX+0x1f7>
xor    %eax,%eax
call   1090 <stackPop@plt>
cmpl   $0x2,0x4(%rsp)
jne    1377 <postfixToX+0x1f7>
mov    %rax,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <clearBrackets@plt>
add    $0x18,%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* @postfixToX(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
store i32 0, i32* %6
br label %19
19: ; preds = %104, %2
%20 = load i32, i32* %6
%21 = load i8*, i8** %4
%22 = call i32 @strlen(i8* %21)
%23 = icmp slt i32 %20, %22
br i1 %23, label %24, label %107
24: ; preds = %19
%25 = load i8*, i8** %4
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
switch i32 %30, label %93 [
i32 94, label %31
i32 47, label %31
i32 42, label %31
i32 43, label %31
i32 45, label %31
]
31: ; preds = %24, %24, %24, %24, %24
%32 = load i8*, i8** %7
%33 = call i32 @strcpy(i8* %32, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%34 = load i8*, i8** %8
%35 = load i8*, i8** %4
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %39)
%41 = call i32 (...) @stackLength()
%42 = icmp slt i32 %41, 2
br i1 %42, label %43, label %44
43: ; preds = %31
store i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %119
44: ; preds = %31
%45 = load i32, i32* %5
%46 = icmp eq i32 %45, 2
br i1 %46, label %47, label %69
47: ; preds = %44
%48 = load i8*, i8** %9
%49 = call i8* (...) @stackPop()
%50 = call i32 @strcpy(i8* %48, i8* %49)
%51 = load i8*, i8** %10
%52 = call i8* (...) @stackPop()
%53 = call i32 @strcpy(i8* %51, i8* %52)
%54 = load i8*, i8** %7
%55 = call i32 @strcat(i8* %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%56 = load i8*, i8** %7
%57 = load i8*, i8** %10
%58 = call i32 @strcat(i8* %56, i8* %57)
%59 = load i8*, i8** %7
%60 = load i8*, i8** %8
%61 = call i32 @strcat(i8* %59, i8* %60)
%62 = load i8*, i8** %7
%63 = load i8*, i8** %9
%64 = call i32 @strcat(i8* %62, i8* %63)
%65 = load i8*, i8** %7
%66 = call i32 @strcat(i8* %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%67 = load i8*, i8** %7
%68 = call i32 @stackPush(i8* %67)
br label %91
69: ; preds = %44
%70 = load i32, i32* %5
%71 = icmp eq i32 %70, 1
br i1 %71, label %72, label %90
72: ; preds = %69
%73 = load i8*, i8** %9
%74 = call i8* (...) @stackPop()
%75 = call i32 @strcpy(i8* %73, i8* %74)
%76 = load i8*, i8** %10
%77 = call i8* (...) @stackPop()
%78 = call i32 @strcpy(i8* %76, i8* %77)
%79 = load i8*, i8** %7
%80 = load i8*, i8** %8
%81 = call i32 @strcat(i8* %79, i8* %80)
%82 = load i8*, i8** %7
%83 = load i8*, i8** %10
%84 = call i32 @strcat(i8* %82, i8* %83)
%85 = load i8*, i8** %7
%86 = load i8*, i8** %9
%87 = call i32 @strcat(i8* %85, i8* %86)
%88 = load i8*, i8** %7
%89 = call i32 @stackPush(i8* %88)
br label %90
90: ; preds = %72, %69
br label %91
91: ; preds = %90, %47
br label %92
92: ; preds = %91
br label %103
93: ; preds = %24
%94 = load i8*, i8** %8
%95 = load i8*, i8** %4
%96 = load i32, i32* %6
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8, i8* %95, i64 %97
%99 = load i8, i8* %98
%100 = call i32 @sprintf(i8* %94, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %99)
%101 = load i8*, i8** %8
%102 = call i32 @stackPush(i8* %101)
br label %103
103: ; preds = %93, %92
br label %104
104: ; preds = %103
%105 = load i32, i32* %6
%106 = add nsw i32 %105, 1
store i32 %106, i32* %6
br label %19
107: ; preds = %19
%108 = call i32 (...) @stackLength()
%109 = icmp sgt i32 %108, 1
br i1 %109, label %110, label %111
110: ; preds = %107
store i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %119
111: ; preds = %107
%112 = load i32, i32* %5
%113 = icmp eq i32 %112, 2
br i1 %113, label %114, label %117
114: ; preds = %111
%115 = call i8* (...) @stackPop()
%116 = call i8* @clearBrackets(i8* %115)
store i8* %116, i8** %3
br label %119
117: ; preds = %111
%118 = call i8* (...) @stackPop()
store i8* %118, i8** %3
br label %119
119: ; preds = %117, %114, %110, %43
%120 = load i8*, i8** %3
ret i8* %120
}

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* @postfixToX(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
br label %15
15: ; preds = %13, %48
%16 = phi i64 [ 0, %13 ], [ %49, %48 ]
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
switch i32 %19, label %46 [
i32 94, label %20
i32 47, label %20
i32 42, label %20
i32 43, label %20
i32 45, label %20
]
20: ; preds = %15, %15, %15, %15, %15
%21 = tail call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%22 = load i8, i8* %17
store i8 %22, i8* %6
store i8 0, i8* %14
%23 = tail call i32 (...) @stackLength()
%24 = icmp slt i32 %23, 2
br i1 %24, label %61, label %25
25: ; preds = %20
switch i32 %1, label %48 [
i32 2, label %26
i32 1, label %37
]
26: ; preds = %25
%27 = tail call i8* (...) @stackPop()
%28 = tail call i32 @strcpy(i8* %8, i8* %27)
%29 = tail call i8* (...) @stackPop()
%30 = tail call i32 @strcpy(i8* %10, i8* %29)
%31 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%32 = tail call i32 @strcat(i8* %4, i8* %10)
%33 = tail call i32 @strcat(i8* %4, i8* %6)
%34 = tail call i32 @strcat(i8* %4, i8* %8)
%35 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%36 = tail call i32 @stackPush(i8* %4)
br label %48
37: ; preds = %25
%38 = tail call i8* (...) @stackPop()
%39 = tail call i32 @strcpy(i8* %8, i8* %38)
%40 = tail call i8* (...) @stackPop()
%41 = tail call i32 @strcpy(i8* %10, i8* %40)
%42 = tail call i32 @strcat(i8* %4, i8* %6)
%43 = tail call i32 @strcat(i8* %4, i8* %10)
%44 = tail call i32 @strcat(i8* %4, i8* %8)
%45 = tail call i32 @stackPush(i8* %4)
br label %48
46: ; preds = %15
store i8 %18, i8* %6
store i8 0, i8* %14
%47 = tail call i32 @stackPush(i8* %6)
br label %48
48: ; preds = %25, %46, %26, %37
%49 = add nuw nsw i64 %16, 1
%50 = tail call i32 @strlen(i8* %0)
%51 = sext i32 %50 to i64
%52 = icmp slt i64 %49, %51
br i1 %52, label %15, label %53
53: ; preds = %48, %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 = %20, %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), %20 ]
ret i8* %62
}