#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__ checkIsPopOrder(int *, int *, int);
char getchar();
int /*<<< orphan*/ printf(char *);
int main(int argc, const char *argv[]) {
  int pushLength = 0, popLength = 0;
  int pushSequence[100];
  int popSequence[100];
  printf("Input the push sequence, end with #:\n");
  while (pushLength < 100) {
    char tmp = getchar();
    getchar();
    if (tmp == '#') {
      break;
    } else if (tmp < '0' || tmp > '9') {
      return 0;
    } else {
      pushSequence[pushLength] = tmp - '0';
      ++pushLength;
    }
  }
  printf("Input the pop sequence, end with #:\n");
  while (popLength < 100) {
    char tmp = getchar();
    getchar();
    if (tmp == '#') {
      break;
    } else if (tmp < '0' || tmp > '9') {
      return 0;
    } else {
      popSequence[popLength] = tmp - '0';
      ++popLength;
    }
  }
  if (pushLength != popLength) {
    printf("error length");
    return 0;
  }
  if (checkIsPopOrder(pushSequence, popSequence, pushLength)) {
    printf("It's pop order\n");
  } else {
    printf("It's not pop order\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xea2(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x64,-0x14(%rbp)
jge    11ea <main+0xba>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x341(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
movsbl -0x341(%rbp),%eax
cmp    $0x23,%eax
jne    1196 <main+0x66>
jmp    11ea <main+0xba>
movsbl -0x341(%rbp),%eax
cmp    $0x30,%eax
jl     11b6 <main+0x86>
movsbl -0x341(%rbp),%eax
cmp    $0x39,%eax
jle    11c2 <main+0x92>
movl   $0x0,-0x4(%rbp)
jmp    12e5 <main+0x1b5>
movsbl -0x341(%rbp),%ecx
sub    $0x30,%ecx
movslq -0x14(%rbp),%rax
mov    %ecx,-0x1b0(%rbp,%rax,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e5 <main+0xb5>
jmp    1163 <main+0x33>
lea    0xe35(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x64,-0x18(%rbp)
jge    127d <main+0x14d>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x342(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
movsbl -0x342(%rbp),%eax
cmp    $0x23,%eax
jne    1229 <main+0xf9>
jmp    127d <main+0x14d>
movsbl -0x342(%rbp),%eax
cmp    $0x30,%eax
jl     1249 <main+0x119>
movsbl -0x342(%rbp),%eax
cmp    $0x39,%eax
jle    1255 <main+0x125>
movl   $0x0,-0x4(%rbp)
jmp    12e5 <main+0x1b5>
movsbl -0x342(%rbp),%ecx
sub    $0x30,%ecx
movslq -0x18(%rbp),%rax
mov    %ecx,-0x340(%rbp,%rax,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1278 <main+0x148>
jmp    11f6 <main+0xc6>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     12a1 <main+0x171>
lea    0xdbb(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e5 <main+0x1b5>
lea    -0x1b0(%rbp),%rdi
lea    -0x340(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <checkIsPopOrder@plt>
cmp    $0x0,%rax
je     12d2 <main+0x1a2>
lea    0xd90(%rip),%rdi
call   1040 <printf@plt>
jmp    12de <main+0x1ae>
lea    0xd8f(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x320,%rsp
lea    0xeba(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0x23,%bl
je     119e <main+0x5e>
lea    -0x3a(%rbx),%eax
cmp    $0xf6,%al
jb     1226 <main+0xe6>
movsbl %bl,%eax
add    $0xffffffd0,%eax
mov    %eax,0x190(%rsp,%r14,4)
add    $0x1,%r14
cmp    $0x64,%r14
jne    1160 <main+0x20>
mov    $0x64,%r14d
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
xor    %r15d,%r15d
nopl   (%rax)
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0x23,%bl
je     11e6 <main+0xa6>
lea    -0x3a(%rbx),%eax
cmp    $0xf6,%al
jb     1226 <main+0xe6>
movsbl %bl,%eax
add    $0xffffffd0,%eax
mov    %eax,(%rsp,%r15,4)
add    $0x1,%r15
cmp    $0x64,%r15
jne    11b0 <main+0x70>
mov    $0x64,%r15d
cmp    %r15d,%r14d
jne    120c <main+0xcc>
lea    0x190(%rsp),%rdi
mov    %rsp,%rsi
mov    %r14d,%edx
call   1040 <checkIsPopOrder@plt>
test   %rax,%rax
je     121a <main+0xda>
lea    0xe5f(%rip),%rdi
jmp    1221 <main+0xe1>
lea    0xded(%rip),%rdi
call   1050 <printf@plt>
jmp    1226 <main+0xe6>
lea    0xe35(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x320,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Input the push sequence, end with #:\0A\00"
@.str.1 = [37 x i8] c"Input the pop sequence, end with #:\0A\00"
@.str.2 = [13 x i8] c"error length\00"
@.str.3 = [16 x i8] c"It's pop order\0A\00"
@.str.4 = [20 x i8] c"It's not pop order\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 [100 x i32]
%9 = alloca [100 x i32]
%10 = alloca i8
%11 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
%12 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %42, %2
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 100
br i1 %15, label %16, label %43
16: ; preds = %13
%17 = call signext i8 (...) @getchar()
store i8 %17, i8* %10
%18 = call signext i8 (...) @getchar()
%19 = load i8, i8* %10
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 35
br i1 %21, label %22, label %23
22: ; preds = %16
br label %43
23: ; preds = %16
%24 = load i8, i8* %10
%25 = sext i8 %24 to i32
%26 = icmp slt i32 %25, 48
br i1 %26, label %31, label %27
27: ; preds = %23
%28 = load i8, i8* %10
%29 = sext i8 %28 to i32
%30 = icmp sgt i32 %29, 57
br i1 %30, label %31, label %32
31: ; preds = %27, %23
store i32 0, i32* %3
br label %92
32: ; preds = %27
%33 = load i8, i8* %10
%34 = sext i8 %33 to i32
%35 = sub nsw i32 %34, 48
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [100 x i32], [100 x i32]* %8, i64 0, i64 %37
store i32 %35, i32* %38
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %41
41: ; preds = %32
br label %42
42: ; preds = %41
br label %13
43: ; preds = %22, %13
%44 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %45
45: ; preds = %74, %43
%46 = load i32, i32* %7
%47 = icmp slt i32 %46, 100
br i1 %47, label %48, label %75
48: ; preds = %45
%49 = call signext i8 (...) @getchar()
store i8 %49, i8* %11
%50 = call signext i8 (...) @getchar()
%51 = load i8, i8* %11
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 35
br i1 %53, label %54, label %55
54: ; preds = %48
br label %75
55: ; preds = %48
%56 = load i8, i8* %11
%57 = sext i8 %56 to i32
%58 = icmp slt i32 %57, 48
br i1 %58, label %63, label %59
59: ; preds = %55
%60 = load i8, i8* %11
%61 = sext i8 %60 to i32
%62 = icmp sgt i32 %61, 57
br i1 %62, label %63, label %64
63: ; preds = %59, %55
store i32 0, i32* %3
br label %92
64: ; preds = %59
%65 = load i8, i8* %11
%66 = sext i8 %65 to i32
%67 = sub nsw i32 %66, 48
%68 = load i32, i32* %7
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [100 x i32], [100 x i32]* %9, i64 0, i64 %69
store i32 %67, i32* %70
%71 = load i32, i32* %7
%72 = add nsw i32 %71, 1
store i32 %72, i32* %7
br label %73
73: ; preds = %64
br label %74
74: ; preds = %73
br label %45
75: ; preds = %54, %45
%76 = load i32, i32* %6
%77 = load i32, i32* %7
%78 = icmp ne i32 %76, %77
br i1 %78, label %79, label %81
79: ; preds = %75
%80 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %92
81: ; preds = %75
%82 = getelementptr inbounds [100 x i32], [100 x i32]* %8, i64 0, i64 0
%83 = getelementptr inbounds [100 x i32], [100 x i32]* %9, i64 0, i64 0
%84 = load i32, i32* %6
%85 = call i64 @checkIsPopOrder(i32* %82, i32* %83, i32 %84)
%86 = icmp ne i64 %85, 0
br i1 %86, label %87, label %89
87: ; preds = %81
%88 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %91
89: ; preds = %81
%90 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %91
91: ; preds = %89, %87
store i32 0, i32* %3
br label %92
92: ; preds = %91, %79, %63, %31
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
@.str.2 = [13 x i8] c"error length\00"
@str = [37 x i8] c"Input the push sequence, end with #:\00"
@str.5 = [36 x i8] c"Input the pop sequence, end with #:\00"
@str.6 = [19 x i8] c"It's not pop order\00"
@str.7 = [15 x i8] c"It's pop order\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [100 x i32]
%4 = alloca [100 x i32]
%5 = bitcast [100 x i32]* %3 to i8*
%6 = bitcast [100 x i32]* %4 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
br label %8
8: ; preds = %2, %17
%9 = phi i64 [ 0, %2 ], [ %20, %17 ]
%10 = tail call signext i8 (...) @getchar()
%11 = tail call signext i8 (...) @getchar()
%12 = sext i8 %10 to i32
%13 = icmp eq i8 %10, 35
br i1 %13, label %22, label %14
14: ; preds = %8
%15 = add i8 %10, -58
%16 = icmp ult i8 %15, -10
br i1 %16, label %57, label %17
17: ; preds = %14
%18 = add nsw i32 %12, -48
%19 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %9
store i32 %18, i32* %19
%20 = add nuw nsw i64 %9, 1
%21 = icmp eq i64 %20, 100
br i1 %21, label %24, label %8
22: ; preds = %8
%23 = trunc i64 %9 to i32
br label %24
24: ; preds = %17, %22
%25 = phi i32 [ %23, %22 ], [ 100, %17 ]
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.5, i64 0, i64 0))
br label %27
27: ; preds = %24, %36
%28 = phi i64 [ 0, %24 ], [ %39, %36 ]
%29 = tail call signext i8 (...) @getchar()
%30 = tail call signext i8 (...) @getchar()
%31 = sext i8 %29 to i32
%32 = icmp eq i8 %29, 35
br i1 %32, label %41, label %33
33: ; preds = %27
%34 = add i8 %29, -58
%35 = icmp ult i8 %34, -10
br i1 %35, label %57, label %36
36: ; preds = %33
%37 = add nsw i32 %31, -48
%38 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %28
store i32 %37, i32* %38
%39 = add nuw nsw i64 %28, 1
%40 = icmp eq i64 %39, 100
br i1 %40, label %43, label %27
41: ; preds = %27
%42 = trunc i64 %28 to i32
br label %43
43: ; preds = %36, %41
%44 = phi i32 [ %42, %41 ], [ 100, %36 ]
%45 = icmp eq i32 %25, %44
br i1 %45, label %48, label %46
46: ; preds = %43
%47 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %57
48: ; preds = %43
%49 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%50 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 0
%51 = call i64 @checkIsPopOrder(i32* %49, i32* %50, i32 %25)
%52 = icmp eq i64 %51, 0
br i1 %52, label %55, label %53
53: ; preds = %48
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.7, i64 0, i64 0))
br label %57
55: ; preds = %48
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.6, i64 0, i64 0))
br label %57
57: ; preds = %14, %33, %53, %55, %46
ret i32 0
}