#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 show_stack(unsigned long stack) {
  int i;
  unsigned long addr;
  printf("%-18s %-18s\n", "address", "value");
  for (i = 0; i < 100; i++) {
    addr = stack + i * sizeof(unsigned long);
    printf("0x%016lx 0x%016lx\n", addr, *(unsigned long *)addr);
  }
}


x86 assembly (clang, -O0):
<show_stack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xedd(%rip),%rdi
lea    0xee3(%rip),%rsi
lea    0xee4(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x64,-0xc(%rbp)
jge    1183 <show_stack+0x73>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113f <show_stack+0x2f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_stack>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
lea    0xee1(%rip),%rdi
lea    0xee7(%rip),%rsi
lea    0xee8(%rip),%rdx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee0(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
lea    (%r15,%rbx,1),%rsi
mov    (%r15,%rbx,1),%rdx
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x8,%rbx
cmp    $0x320,%rbx
jne    1140 <show_stack+0x30>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"%-18s %-18s\0A\00"
@.str.1 = [8 x i8] c"address\00"
@.str.2 = [6 x i8] c"value\00"
@.str.3 = [19 x i8] c"0x%016lx 0x%016lx\0A\00"
define void @show_stack(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i64
store i64 %0, i64* %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %6
6: ; preds = %20, %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 100
br i1 %8, label %9, label %23
9: ; preds = %6
%10 = load i64, i64* %2
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 8
%14 = add i64 %10, %13
store i64 %14, i64* %4
%15 = load i64, i64* %4
%16 = load i64, i64* %4
%17 = inttoptr i64 %16 to i64*
%18 = load i64, i64* %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i64 %15, i64 %18)
br label %20
20: ; preds = %9
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
br label %6
23: ; preds = %6
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"%-18s %-18s\0A\00"
@.str.1 = [8 x i8] c"address\00"
@.str.2 = [6 x i8] c"value\00"
@.str.3 = [19 x i8] c"0x%016lx 0x%016lx\0A\00"
define void @show_stack(i64 %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %3
3: ; preds = %1, %3
%4 = phi i64 [ 0, %1 ], [ %10, %3 ]
%5 = shl nuw nsw i64 %4, 3
%6 = add i64 %5, %0
%7 = inttoptr i64 %6 to i64*
%8 = load i64, i64* %7
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i64 %6, i64 %8)
%10 = add nuw nsw i64 %4, 1
%11 = icmp eq i64 %10, 100
br i1 %11, label %12, label %3
12: ; preds = %3
ret void
}