#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*/ printf(char *, ...);
void display(int *a, int x) {
  if (x == -1) {
    printf("\nStack is empty");
  } else {
    printf("\nStack is ");
    while (x != -1) {
      printf("\n\t%d", *(a + x));
      x--;
    }
  }
}


x86 assembly (clang, -O0):
<display>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    113c <display+0x2c>
lea    0xed0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1180 <display+0x70>
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0xffffffff,-0xc(%rbp)
je     117b <display+0x6b>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    114a <display+0x3a>
jmp    1180 <display+0x70>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display>:
cmp    $0xffffffff,%esi
je     1158 <display+0x48>
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xeeb(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movslq %ebp,%rbp
lea    0xee5(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    (%rbx,%rbp,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0xffffffffffffffff,%rbp
jb     1140 <display+0x30>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xea1(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"\0AStack is empty\00"
@.str.1 = [11 x i8] c"\0AStack is \00"
@.str.2 = [5 x i8] c"\0A\09%d\00"
define void @display(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %24
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %14, %9
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %23
14: ; preds = %11
%15 = load i32*, i32** %3
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %4
%22 = add nsw i32 %21, -1
store i32 %22, i32* %4
br label %11
23: ; preds = %11
br label %24
24: ; preds = %23, %7
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"\0AStack is empty\00"
@.str.1 = [11 x i8] c"\0AStack is \00"
@.str.2 = [5 x i8] c"\0A\09%d\00"
define void @display(i32* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, -1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %16
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%8 = sext i32 %1 to i64
br label %9
9: ; preds = %6, %9
%10 = phi i64 [ %8, %6 ], [ %14, %9 ]
%11 = getelementptr inbounds i32, i32* %0, i64 %10
%12 = load i32, i32* %11
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = add nsw i64 %10, -1
%15 = icmp eq i64 %10, 0
br i1 %15, label %16, label %9
16: ; preds = %9, %4
ret void
}