#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 /*<<< orphan*/ printPostOrder(int *, int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n;
  printf("Enter the no. of element in the tree");
  printf("\n");
  scanf("%d", &n);
  int in[10000];
  int pre[10000];
  printf("Enter elements of inorder traversal seprated by single space");
  printf("\n");
  for (int x = 0; x < n; x++) {
    scanf("%d", &in[x]);
  }
  printf("Enter elements of preorder traversal by single space");
  printf("\n");
  for (int x = 0; x < n; x++) {
    scanf("%d", &pre[x]);
  }
  printf("Postorder traversal ");
  printf("\n");
  printPostOrder(in, pre, n);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x138a0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
call   1030 <printf@plt>
lea    0xed0(%rip),%rdi
call   1030 <printf@plt>
lea    0xec6(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xeb9(%rip),%rdi
call   1030 <printf@plt>
lea    0xea8(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x13894(%rbp)
mov    -0x13894(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d0 <main+0xa0>
movslq -0x13894(%rbp),%rax
lea    -0x9c50(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe70(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x13894(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13894(%rbp)
jmp    118c <main+0x5c>
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x13898(%rbp)
mov    -0x13898(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1236 <main+0x106>
movslq -0x13898(%rbp),%rax
lea    -0x13890(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe0a(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x13898(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13898(%rbp)
jmp    11f2 <main+0xc2>
lea    0xe5f(%rip),%rdi
call   1030 <printf@plt>
lea    0xddc(%rip),%rdi
call   1030 <printf@plt>
lea    -0x9c50(%rbp),%rdi
lea    -0x13890(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1040 <printPostOrder@plt>
lea    0xdba(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x138a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x13890,%rsp
lea    0xead(%rip),%rdi
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xebc(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
lea    0xeae(%rip),%rdi
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmpl   $0x0,0xc(%rsp)
jle    11cd <main+0x8d>
lea    0x9c50(%rsp),%r15
xor    %ebx,%ebx
lea    0xe84(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     11b0 <main+0x70>
lea    0xe91(%rip),%rdi
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmpl   $0x0,0xc(%rsp)
jle    121d <main+0xdd>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xe2d(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     1200 <main+0xc0>
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%edx
lea    0x9c50(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1050 <printPostOrder@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x13890,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Enter the no. of element in the tree\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [61 x i8] c"Enter elements of inorder traversal seprated by single space\00"
@.str.4 = [53 x i8] c"Enter elements of preorder traversal by single space\00"
@.str.5 = [21 x i8] c"Postorder traversal \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10000 x i32]
%4 = alloca [10000 x i32]
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%10 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %5
br label %12
12: ; preds = %21, %0
%13 = load i32, i32* %5
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [10000 x i32], [10000 x i32]* %3, i64 0, i64 %18
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %19)
br label %21
21: ; preds = %16
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %12
24: ; preds = %12
%25 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %6
br label %27
27: ; preds = %36, %24
%28 = load i32, i32* %6
%29 = load i32, i32* %2
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %39
31: ; preds = %27
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [10000 x i32], [10000 x i32]* %4, i64 0, i64 %33
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %34)
br label %36
36: ; preds = %31
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %27
39: ; preds = %27
%40 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%41 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%42 = getelementptr inbounds [10000 x i32], [10000 x i32]* %3, i64 0, i64 0
%43 = getelementptr inbounds [10000 x i32], [10000 x i32]* %4, i64 0, i64 0
%44 = load i32, i32* %2
%45 = call i32 @printPostOrder(i32* %42, i32* %43, i32 %44)
%46 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [37 x i8] c"Enter the no. of element in the tree\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [61 x i8] c"Enter elements of inorder traversal seprated by single space\00"
@.str.4 = [53 x i8] c"Enter elements of preorder traversal by single space\00"
@.str.5 = [21 x i8] c"Postorder traversal \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10000 x i32]
%3 = alloca [10000 x i32]
%4 = bitcast i32* %1 to i8*
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @putchar(i32 10)
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%8 = bitcast [10000 x i32]* %2 to i8*
%9 = bitcast [10000 x i32]* %3 to i8*
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 @putchar(i32 10)
%12 = load i32, i32* %1
%13 = icmp sgt i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %19, %0
%15 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @putchar(i32 10)
%17 = load i32, i32* %1
%18 = icmp sgt i32 %17, 0
br i1 %18, label %35, label %27
19: ; preds = %0, %19
%20 = phi i64 [ %23, %19 ], [ 0, %0 ]
%21 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 %20
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %21)
%23 = add nuw nsw i64 %20, 1
%24 = load i32, i32* %1
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %23, %25
br i1 %26, label %19, label %14
27: ; preds = %35, %14
%28 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%29 = call i32 @putchar(i32 10)
%30 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 0
%31 = getelementptr inbounds [10000 x i32], [10000 x i32]* %3, i64 0, i64 0
%32 = load i32, i32* %1
%33 = call i32 @printPostOrder(i32* %30, i32* %31, i32 %32)
%34 = call i32 @putchar(i32 10)
ret i32 0
35: ; preds = %14, %35
%36 = phi i64 [ %39, %35 ], [ 0, %14 ]
%37 = getelementptr inbounds [10000 x i32], [10000 x i32]* %3, i64 0, i64 %36
%38 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %37)
%39 = add nuw nsw i64 %36, 1
%40 = load i32, i32* %1
%41 = sext i32 %40 to i64
%42 = icmp slt i64 %39, %41
br i1 %42, label %35, label %27
}