#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
void printStack(FILE *fout, int cur_bp, int prev_bp, int *data, int pipe) {
  if (cur_bp == 0)
    return;
  if (cur_bp > 1) {
    printStack(fout, data[cur_bp], cur_bp - 1, data, 1);
  }
  while (cur_bp <= prev_bp) {
    fprintf(fout, "%d ", data[cur_bp - 1]);
    cur_bp++;
  }
  if (pipe)
    fputs("| ", fout);
}


x86 assembly (clang, -O0):
<printStack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1159 <printStack+0x29>
jmp    11e0 <printStack+0xb0>
cmpl   $0x1,-0xc(%rbp)
jle    1187 <printStack+0x57>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%r8d
call   1050 <printStack@plt>
jmp    118c <printStack+0x5c>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11c6 <printStack+0x96>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe4d(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118c <printStack+0x5c>
cmpl   $0x0,-0x1c(%rbp)
je     11e0 <printStack+0xb0>
mov    -0x8(%rbp),%rsi
lea    0xe29(%rip),%rdi
call   1030 <fputs@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printStack>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     11e5 <printStack+0xb5>
mov    %rcx,%r15
mov    %edx,%r14d
mov    %esi,%r12d
mov    %rdi,%r13
mov    %r8d,0x4(%rsp)
cmp    $0x2,%esi
jl     1176 <printStack+0x46>
mov    %r12d,%eax
mov    (%r15,%rax,4),%esi
lea    -0x1(%r12),%edx
mov    %r13,%rdi
mov    %r15,%rcx
mov    $0x1,%r8d
call   1040 <printStack@plt>
cmp    %r14d,%r12d
jg     11b7 <printStack+0x87>
movslq %r12d,%rax
lea    (%r15,%rax,4),%rbx
sub    %r12d,%r14d
mov    $0xffffffffffffffff,%rbp
lea    0xe6d(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rbx,%rbp,4),%edx
mov    %r13,%rdi
mov    %r15,%rsi
call   1030 <fprintf@plt>
add    $0x1,%rbp
cmp    %ebp,%r14d
jne    11a0 <printStack+0x70>
cmpl   $0x0,0x4(%rsp)
je     11e5 <printStack+0xb5>
lea    0xe3f(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r13,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fwrite@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d \00"
@.str.1 = [3 x i8] c"| \00"
define void @printStack(i32* %0, i32 %1, i32 %2, i32* %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32 %4, i32* %10
%11 = load i32, i32* %7
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %5
br label %49
14: ; preds = %5
%15 = load i32, i32* %7
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %27
17: ; preds = %14
%18 = load i32*, i32** %6
%19 = load i32*, i32** %9
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
%24 = load i32, i32* %7
%25 = sub nsw i32 %24, 1
%26 = load i32*, i32** %9
br label %27
27: ; preds = %17, %14
br label %28
28: ; preds = %32, %27
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = icmp sle i32 %29, %30
br i1 %31, label %32, label %43
32: ; preds = %28
%33 = load i32*, i32** %6
%34 = load i32*, i32** %9
%35 = load i32, i32* %7
%36 = sub nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %34, i64 %37
%39 = load i32, i32* %38
%40 = call i32 @fprintf(i32* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %28
43: ; preds = %28
%44 = load i32, i32* %10
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i32*, i32** %6
%48 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %47)
br label %49
49: ; preds = %13, %46, %43
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
@.str.1 = [3 x i8] c"| \00"
define void @printStack(i32* nocapture %0, i32 %1, i32 %2, i32* nocapture %3, i32 %4) {
%6 = icmp eq i32 %1, 0
br i1 %6, label %32, label %7
7: ; preds = %5
%8 = icmp sgt i32 %1, 1
br i1 %8, label %9, label %14
9: ; preds = %7
%10 = zext i32 %1 to i64
%11 = getelementptr inbounds i32, i32* %3, i64 %10
%12 = load i32, i32* %11
%13 = add nsw i32 %1, -1
tail call void @printStack(i32* %0, i32 %12, i32 %13, i32* %3, i32 1)
br label %14
14: ; preds = %9, %7
%15 = icmp sgt i32 %1, %2
br i1 %15, label %28, label %16
16: ; preds = %14
%17 = sext i32 %1 to i64
%18 = add i32 %2, 1
br label %19
19: ; preds = %16, %19
%20 = phi i64 [ %17, %16 ], [ %25, %19 ]
%21 = add nsw i64 %20, -1
%22 = getelementptr inbounds i32, i32* %3, i64 %21
%23 = load i32, i32* %22
%24 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = add nsw i64 %20, 1
%26 = trunc i64 %25 to i32
%27 = icmp eq i32 %18, %26
br i1 %27, label %28, label %19
28: ; preds = %19, %14
%29 = icmp eq i32 %4, 0
br i1 %29, label %32, label %30
30: ; preds = %28
%31 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %32
32: ; preds = %5, %30, %28
ret void
}