#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 *, ...);
int /*<<< orphan*/ scanf(char *, int *);
void push(int *stack, int *top, int lim) {
  int i;
  if ((*top) == lim - 1) {
    printf("\nstack overflow");
    return;
  }
  (*top)++;
  printf("\nEnter element to be pushed:");
  scanf("%d", &stack[(*top)]);
  for (i = 0; i <= (*top); i++)
    printf(" %d", stack[i]);
  return;
}


x86 assembly (clang, -O0):
<push>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    115a <push+0x3a>
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d3 <push+0xb3>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xea2(%rip),%rdi
call   1040 <scanf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jg     11ce <push+0xae>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1198 <push+0x78>
jmp    11d3 <push+0xb3>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<push>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    (%rsi),%eax
add    $0xffffffff,%edx
cmp    %edx,%eax
jne    114a <push+0x2a>
lea    0xec8(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <printf@plt>
mov    %rsi,%r12
mov    %rdi,%r14
add    $0x1,%eax
mov    %eax,(%rsi)
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movslq (%r12),%rax
lea    (%r14,%rax,4),%rsi
lea    0xebc(%rip),%rdi
call   1040 <scanf@plt>
cmpl   $0x0,(%r12)
js     11ac <push+0x8c>
mov    $0xffffffffffffffff,%rbx
lea    0xea1(%rip),%r15
nopl   0x0(%rax)
mov    0x4(%r14,%rbx,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movslq (%r12),%rax
add    $0x1,%rbx
cmp    %rax,%rbx
jl     1190 <push+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [16 x i8] c"\0Astack overflow\00"
@.str.1 = [29 x i8] c"\0AEnter element to be pushed:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c" %d\00"
define void @push(i32* %0, i32* nocapture %1, i32 %2) {
%4 = load i32, i32* %1
%5 = add nsw i32 %2, -1
%6 = icmp eq i32 %4, %5
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %27
9: ; preds = %3
%10 = add nsw i32 %4, 1
store i32 %10, i32* %1
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* %1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %14)
%16 = load i32, i32* %1
%17 = icmp slt i32 %16, 0
br i1 %17, label %27, label %18
18: ; preds = %9, %18
%19 = phi i64 [ %23, %18 ], [ 0, %9 ]
%20 = getelementptr inbounds i32, i32* %0, i64 %19
%21 = load i32, i32* %20
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = add nuw nsw i64 %19, 1
%24 = load i32, i32* %1
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %19, %25
br i1 %26, label %18, label %27
27: ; preds = %18, %9, %7
ret void
}