#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 */
struct stack {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ initStack(struct stack **);
scalar_t__ isEmpty(struct stack **);
scalar_t__ isOperand(char);
char peek(struct stack **);
int pop(struct stack **);
scalar_t__ precedence(char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ push(struct stack **, char);
void convertToPostfix(char *source) {
  int i = 0;
  struct stack *s;
  initStack(&s);
  while (*source != '\0') {
    if (isOperand(*source)) {
      printf("%c", *source);
    } else if (*source == '(') {
      push(&s, '(');
    } else if (*source == ')') {
      while (peek(&s) != '(') {
        printf("%c", pop(&s));
      }
      pop(&s);
    } else {
      if (isEmpty(&s) || (precedence(*source) > precedence(peek(&s)))) {
        push(&s, *source);
      } else {
        while (precedence(*source) < precedence(peek(&s))) {
          printf("%c", pop(&s));
        }
        push(&s, *source);
      }
    }
    source++;
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<convertToPostfix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <initStack@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1332 <convertToPostfix+0x1b2>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1080 <isOperand@plt>
cmp    $0x0,%rax
je     11dc <convertToPostfix+0x5c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1321 <convertToPostfix+0x1a1>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x28,%eax
jne    11ff <convertToPostfix+0x7f>
lea    -0x18(%rbp),%rdi
mov    $0x28,%esi
call   10a0 <push@plt>
jmp    131c <convertToPostfix+0x19c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x29,%eax
jne    1255 <convertToPostfix+0xd5>
jmp    1214 <convertToPostfix+0x94>
lea    -0x18(%rbp),%rdi
call   1040 <peek@plt>
movsbl %al,%eax
cmp    $0x28,%eax
je     1247 <convertToPostfix+0xc7>
lea    -0x18(%rbp),%rdi
call   1070 <pop@plt>
mov    %eax,%esi
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1214 <convertToPostfix+0x94>
lea    -0x18(%rbp),%rdi
call   1070 <pop@plt>
jmp    1317 <convertToPostfix+0x197>
lea    -0x18(%rbp),%rdi
call   1090 <isEmpty@plt>
cmp    $0x0,%rax
jne    1299 <convertToPostfix+0x119>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <precedence@plt>
mov    %rax,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <peek@plt>
movsbl %al,%edi
call   1030 <precedence@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jle    12ae <convertToPostfix+0x12e>
mov    -0x8(%rbp),%rax
lea    -0x18(%rbp),%rdi
movsbl (%rax),%esi
call   10a0 <push@plt>
jmp    1312 <convertToPostfix+0x192>
jmp    12b3 <convertToPostfix+0x133>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <precedence@plt>
mov    %rax,-0x28(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <peek@plt>
movsbl %al,%edi
call   1030 <precedence@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jge    1302 <convertToPostfix+0x182>
lea    -0x18(%rbp),%rdi
call   1070 <pop@plt>
mov    %eax,%esi
lea    0xd0a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12b3 <convertToPostfix+0x133>
mov    -0x8(%rbp),%rax
lea    -0x18(%rbp),%rdi
movsbl (%rax),%esi
call   10a0 <push@plt>
jmp    1317 <convertToPostfix+0x197>
jmp    131c <convertToPostfix+0x19c>
jmp    1321 <convertToPostfix+0x1a1>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    119c <convertToPostfix+0x1c>
lea    0xcca(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convertToPostfix>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
call   1060 <initStack@plt>
mov    (%rbx),%al
test   %al,%al
je     1281 <convertToPostfix+0x101>
lea    0x8(%rsp),%r14
jmp    11c4 <convertToPostfix+0x44>
nopw   0x0(%rax,%rax,1)
call   1050 <putchar@plt>
mov    0x1(%rbx),%al
add    $0x1,%rbx
test   %al,%al
je     1281 <convertToPostfix+0x101>
movsbl %al,%edi
call   1080 <isOperand@plt>
movsbl (%rbx),%edi
test   %rax,%rax
jne    11b0 <convertToPostfix+0x30>
cmp    $0x28,%dil
je     11fd <convertToPostfix+0x7d>
cmp    $0x29,%dil
jne    120e <convertToPostfix+0x8e>
mov    %r14,%rdi
call   1040 <peek@plt>
mov    %r14,%rdi
cmp    $0x28,%al
je     1207 <convertToPostfix+0x87>
call   1070 <pop@plt>
mov    %eax,%edi
call   1050 <putchar@plt>
jmp    11e0 <convertToPostfix+0x60>
mov    %r14,%rdi
mov    $0x28,%esi
jmp    1241 <convertToPostfix+0xc1>
call   1070 <pop@plt>
jmp    11b5 <convertToPostfix+0x35>
mov    %r14,%rdi
call   1090 <isEmpty@plt>
test   %rax,%rax
jne    123b <convertToPostfix+0xbb>
movsbl (%rbx),%edi
call   1030 <precedence@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <peek@plt>
movsbl %al,%edi
call   1030 <precedence@plt>
cmp    %rax,%r15
jle    1250 <convertToPostfix+0xd0>
movsbl (%rbx),%esi
mov    %r14,%rdi
call   10a0 <push@plt>
jmp    11b5 <convertToPostfix+0x35>
nopl   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1030 <precedence@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <peek@plt>
movsbl %al,%edi
call   1030 <precedence@plt>
cmp    %rax,%r15
jge    123b <convertToPostfix+0xbb>
mov    %r14,%rdi
call   1070 <pop@plt>
mov    %eax,%edi
call   1050 <putchar@plt>
jmp    1250 <convertToPostfix+0xd0>
mov    $0xa,%edi
call   1050 <putchar@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stack = type { i32 }
@.str = [3 x i8] c"%c\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @convertToPostfix(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.stack*
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = call i32 @initStack(%struct.stack** %4)
br label %6
6: ; preds = %75, %1
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %78
11: ; preds = %6
%12 = load i8*, i8** %2
%13 = load i8, i8* %12
%14 = call i64 @isOperand(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i8*, i8** %2
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %75
21: ; preds = %11
%22 = load i8*, i8** %2
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 40
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @push(%struct.stack** %4, i8 signext 40)
br label %74
28: ; preds = %21
%29 = load i8*, i8** %2
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 41
br i1 %32, label %33, label %43
33: ; preds = %28
br label %34
34: ; preds = %38, %33
%35 = call signext i8 @peek(%struct.stack** %4)
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 40
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = call i32 @pop(%struct.stack** %4)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %39)
br label %34
41: ; preds = %34
%42 = call i32 @pop(%struct.stack** %4)
br label %73
43: ; preds = %28
%44 = call i64 @isEmpty(%struct.stack** %4)
%45 = icmp ne i64 %44, 0
br i1 %45, label %53, label %46
46: ; preds = %43
%47 = load i8*, i8** %2
%48 = load i8, i8* %47
%49 = call i64 @precedence(i8 signext %48)
%50 = call signext i8 @peek(%struct.stack** %4)
%51 = call i64 @precedence(i8 signext %50)
%52 = icmp sgt i64 %49, %51
br i1 %52, label %53, label %57
53: ; preds = %46, %43
%54 = load i8*, i8** %2
%55 = load i8, i8* %54
%56 = call i32 @push(%struct.stack** %4, i8 signext %55)
br label %72
57: ; preds = %46
br label %58
58: ; preds = %65, %57
%59 = load i8*, i8** %2
%60 = load i8, i8* %59
%61 = call i64 @precedence(i8 signext %60)
%62 = call signext i8 @peek(%struct.stack** %4)
%63 = call i64 @precedence(i8 signext %62)
%64 = icmp slt i64 %61, %63
br i1 %64, label %65, label %68
65: ; preds = %58
%66 = call i32 @pop(%struct.stack** %4)
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %66)
br label %58
68: ; preds = %58
%69 = load i8*, i8** %2
%70 = load i8, i8* %69
%71 = call i32 @push(%struct.stack** %4, i8 signext %70)
br label %72
72: ; preds = %68, %53
br label %73
73: ; preds = %72, %41
br label %74
74: ; preds = %73, %26
br label %75
75: ; preds = %74, %16
%76 = load i8*, i8** %2
%77 = getelementptr inbounds i8, i8* %76, i32 1
store i8* %77, i8** %2
br label %6
78: ; preds = %6
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.stack = type { i32 }
define void @convertToPostfix(i8* nocapture %0) {
%2 = alloca %struct.stack*
%3 = bitcast %struct.stack** %2 to i8*
%4 = call i32 @initStack(%struct.stack** %2)
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %62, label %7
7: ; preds = %1, %58
%8 = phi i8 [ %60, %58 ], [ %5, %1 ]
%9 = phi i8* [ %59, %58 ], [ %0, %1 ]
%10 = call i64 @isOperand(i8 signext %8)
%11 = icmp eq i64 %10, 0
%12 = load i8, i8* %9
br i1 %11, label %16, label %13
13: ; preds = %7
%14 = sext i8 %12 to i32
%15 = call i32 @putchar(i32 %14)
br label %58
16: ; preds = %7
switch i8 %12, label %29 [
i8 40, label %20
i8 41, label %17
]
17: ; preds = %16
%18 = call signext i8 @peek(%struct.stack** %2)
%19 = icmp eq i8 %18, 40
br i1 %19, label %27, label %22
20: ; preds = %16
%21 = call i32 @push(%struct.stack** %2, i8 signext 40)
br label %58
22: ; preds = %17, %22
%23 = call i32 @pop(%struct.stack** %2)
%24 = call i32 @putchar(i32 %23)
%25 = call signext i8 @peek(%struct.stack** %2)
%26 = icmp eq i8 %25, 40
br i1 %26, label %27, label %22
27: ; preds = %22, %17
%28 = call i32 @pop(%struct.stack** %2)
br label %58
29: ; preds = %16
%30 = call i64 @isEmpty(%struct.stack** %2)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %44
32: ; preds = %29
%33 = load i8, i8* %9
%34 = call i64 @precedence(i8 signext %33)
%35 = call signext i8 @peek(%struct.stack** %2)
%36 = call i64 @precedence(i8 signext %35)
%37 = icmp sgt i64 %34, %36
br i1 %37, label %44, label %38
38: ; preds = %32
%39 = load i8, i8* %9
%40 = call i64 @precedence(i8 signext %39)
%41 = call signext i8 @peek(%struct.stack** %2)
%42 = call i64 @precedence(i8 signext %41)
%43 = icmp slt i64 %40, %42
br i1 %43, label %47, label %55
44: ; preds = %32, %29
%45 = load i8, i8* %9
%46 = call i32 @push(%struct.stack** %2, i8 signext %45)
br label %58
47: ; preds = %38, %47
%48 = call i32 @pop(%struct.stack** %2)
%49 = call i32 @putchar(i32 %48)
%50 = load i8, i8* %9
%51 = call i64 @precedence(i8 signext %50)
%52 = call signext i8 @peek(%struct.stack** %2)
%53 = call i64 @precedence(i8 signext %52)
%54 = icmp slt i64 %51, %53
br i1 %54, label %47, label %55
55: ; preds = %47, %38
%56 = load i8, i8* %9
%57 = call i32 @push(%struct.stack** %2, i8 signext %56)
br label %58
58: ; preds = %20, %44, %55, %27, %13
%59 = getelementptr inbounds i8, i8* %9, i64 1
%60 = load i8, i8* %59
%61 = icmp eq i8 %60, 0
br i1 %61, label %62, label %7
62: ; preds = %58, %1
%63 = call i32 @putchar(i32 10)
ret void
}