#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 pop();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ push(int);
int main() {
  int arr[] = {1, 2, 3, 4};
  for (int i = 0; i < 4; i++) {
    push(arr[i]);
  }
  for (int i = 0; i < 4; i++) {
    printf("%d\n", pop());
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    1181 <main+0x51>
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%edi
call   1050 <push@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115c <main+0x2c>
movl   $0x0,-0x28(%rbp)
cmpl   $0x4,-0x28(%rbp)
jge    11b5 <main+0x85>
mov    $0x0,%al
call   1040 <pop@plt>
mov    %eax,%esi
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1188 <main+0x58>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x1,%edi
call   1050 <push@plt>
mov    $0x2,%edi
call   1050 <push@plt>
mov    $0x3,%edi
call   1050 <push@plt>
mov    $0x4,%edi
call   1050 <push@plt>
xor    %eax,%eax
call   1040 <pop@plt>
lea    0xe99(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <pop@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <pop@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <pop@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.arr = [4 x i32] [i32 1, i32 2, i32 3, i32 4]
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [4 x i32]* %2 to i8*
store i32 0, i32* %3
br label %6
6: ; preds = %15, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 4
br i1 %8, label %9, label %18
9: ; preds = %6
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = call i32 @push(i32 %13)
br label %15
15: ; preds = %9
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %6
18: ; preds = %6
store i32 0, i32* %4
br label %19
19: ; preds = %25, %18
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 4
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = call i32 (...) @pop()
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %19
28: ; preds = %19
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = tail call i32 @push(i32 1)
%2 = tail call i32 @push(i32 2)
%3 = tail call i32 @push(i32 3)
%4 = tail call i32 @push(i32 4)
%5 = tail call i32 (...) @pop()
%6 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = tail call i32 (...) @pop()
%8 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i32 (...) @pop()
%10 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = tail call i32 (...) @pop()
%12 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %11)
ret i32 0
}