#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 */
scalar_t__ checkIsPostOrder(int *, int /*<<< orphan*/, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, const char *argv[]) {
  int *nums;
  int length;
  int num;
  int i;
  printf("Input amount of numbers:");
  scanf("%d", &length);
  if (length < 1) {
    printf("Length invalid\n");
    return 0;
  }
  nums = (int *)malloc(length * sizeof(int));
  printf("Input the sequence:");
  for (i = 0; i < length; ++i) {
    scanf("%d", nums + i);
  }
  if (checkIsPostOrder(nums, 0, length - 1)) {
    printf("It's the post order traverse sequence of a binary search tree\n");
  } else {
    printf(
        "It's not the post order traverse sequence of a binary search tree\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb0(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1060 <scanf@plt>
cmpl   $0x1,-0x1c(%rbp)
jge    1194 <main+0x54>
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    122e <main+0xee>
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ef <main+0xaf>
mov    -0x18(%rbp),%rsi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe3d(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ba <main+0x7a>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1040 <checkIsPostOrder@plt>
cmp    $0x0,%rax
je     121b <main+0xdb>
lea    0xe2f(%rip),%rdi
call   1030 <printf@plt>
jmp    1227 <main+0xe7>
lea    0xe5d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xea1(%rip),%rdi
call   1040 <printf@plt>
lea    0xeae(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%edi
test   %edi,%edi
jle    11f1 <main+0xa1>
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
lea    0xe8d(%rip),%rdi
call   1040 <printf@plt>
mov    0x4(%rsp),%edx
test   %edx,%edx
jle    11cd <main+0x7d>
xor    %r12d,%r12d
lea    0xe73(%rip),%r15
mov    %r14,%rbx
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
add    $0x1,%r12
movslq 0x4(%rsp),%rdx
add    $0x4,%rbx
cmp    %rdx,%r12
jl     11b0 <main+0x60>
add    $0xffffffff,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <checkIsPostOrder@plt>
test   %rax,%rax
lea    0xe4c(%rip),%rax
lea    0xe87(%rip),%rdi
cmove  %rax,%rdi
jmp    11f8 <main+0xa8>
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Input amount of numbers:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"Length invalid\0A\00"
@.str.3 = [20 x i8] c"Input the sequence:\00"
@.str.4 = [63 x i8] c"It's the post order traverse sequence of a binary search tree\0A\00"
@.str.5 = [67 x i8] c"It's not the post order traverse sequence of a binary search tree\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %48
16: ; preds = %2
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 4
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i32*
store i32* %22, i32** %6
%23 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %9
br label %24
24: ; preds = %34, %16
%25 = load i32, i32* %9
%26 = load i32, i32* %7
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %37
28: ; preds = %24
%29 = load i32*, i32** %6
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %32)
br label %34
34: ; preds = %28
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %9
br label %24
37: ; preds = %24
%38 = load i32*, i32** %6
%39 = load i32, i32* %7
%40 = sub nsw i32 %39, 1
%41 = call i64 @checkIsPostOrder(i32* %38, i32 0, i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.4, i64 0, i64 0))
br label %47
45: ; preds = %37
%46 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.5, i64 0, i64 0))
br label %47
47: ; preds = %45, %43
store i32 0, i32* %3
br label %48
48: ; preds = %47, %14
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@.str = [25 x i8] c"Input amount of numbers:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [20 x i8] c"Input the sequence:\00"
@str = [66 x i8] c"It's not the post order traverse sequence of a binary search tree\00"
@str.6 = [62 x i8] c"It's the post order traverse sequence of a binary search tree\00"
@str.7 = [15 x i8] c"Length invalid\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 1
br i1 %8, label %30, label %9
9: ; preds = %2
%10 = shl i32 %7, 2
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32*
%13 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%14 = load i32, i32* %3
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %9, %16
%17 = phi i64 [ %20, %16 ], [ 0, %9 ]
%18 = getelementptr inbounds i32, i32* %12, i64 %17
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %18)
%20 = add nuw nsw i64 %17, 1
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %16, label %24
24: ; preds = %16, %9
%25 = phi i32 [ %14, %9 ], [ %21, %16 ]
%26 = add nsw i32 %25, -1
%27 = call i64 @checkIsPostOrder(i32* %12, i32 0, i32 %26)
%28 = icmp eq i64 %27, 0
%29 = select i1 %28, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([62 x i8], [62 x i8]* @str.6, i64 0, i64 0)
br label %30
30: ; preds = %24, %2
%31 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.7, i64 0, i64 0), %2 ], [ %29, %24 ]
%32 = call i32 @puts(i8* dereferenceable(1) %31)
ret i32 0
}