void dump_stack(void *p) {
  unsigned int *k, i;
  printf("Stack:\n");
  for (k = (unsigned int *)&p - 1, i = 0; i < 16; k++, i++) {
    printf("0x%8X: 0x%8X \n", k, *k);
  }
}


x86 assembly (clang, -O0):
<dump_stack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xedd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x8(%rbp),%rax
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jae    1179 <dump_stack+0x69>
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113d <dump_stack+0x2d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_stack>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,0x8(%rsp)
lea    0xede(%rip),%rdi
call   1030 <puts@plt>
lea    0x4(%rsp),%rsi
lea    0xebe(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%edx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%rsi
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x10(%rsp),%rsi
mov    0x10(%rsp),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x14(%rsp),%rsi
mov    0x14(%rsp),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x18(%rsp),%rsi
mov    0x18(%rsp),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x1c(%rsp),%rsi
mov    0x1c(%rsp),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x20(%rsp),%rsi
mov    0x20(%rsp),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x24(%rsp),%rsi
mov    0x24(%rsp),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x28(%rsp),%rsi
mov    0x28(%rsp),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x2c(%rsp),%rsi
mov    0x2c(%rsp),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x30(%rsp),%rsi
mov    0x30(%rsp),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x34(%rsp),%rsi
mov    0x34(%rsp),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x38(%rsp),%rsi
mov    0x38(%rsp),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x3c(%rsp),%rsi
mov    0x3c(%rsp),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x40(%rsp),%rsi
mov    0x40(%rsp),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"Stack:\0A\00"
@.str.1 = [15 x i8] c"0x%8X: 0x%8X \0A\00"
define void @dump_stack(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = bitcast i8** %2 to i32*
%7 = getelementptr inbounds i32, i32* %6, i64 -1
store i32* %7, i32** %3
store i32 0, i32* %4
br label %8
8: ; preds = %16, %1
%9 = load i32, i32* %4
%10 = icmp ult i32 %9, 16
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = load i32*, i32** %3
%13 = load i32*, i32** %3
%14 = load i32, i32* %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32* %12, i32 %14)
br label %16
16: ; preds = %11
%17 = load i32*, i32** %3
%18 = getelementptr inbounds i32, i32* %17, i32 1
store i32* %18, i32** %3
%19 = load i32, i32* %4
%20 = add i32 %19, 1
store i32 %20, i32* %4
br label %8
21: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str.1 = [15 x i8] c"0x%8X: 0x%8X \0A\00"
@str = [7 x i8] c"Stack:\00"
define void @dump_stack(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%4 = bitcast i8** %2 to i32*
%5 = getelementptr inbounds i32, i32* %4, i64 -1
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32* %5, i32 undef)
%7 = load i32, i32* %4
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %2, i32 %7)
%9 = getelementptr inbounds i32, i32* %4, i64 1
%10 = load i32, i32* %9
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32* %9, i32 %10)
%12 = getelementptr inbounds i8*, i8** %2, i64 1
%13 = bitcast i8** %12 to i32*
%14 = load i32, i32* %13
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %12, i32 %14)
%16 = getelementptr inbounds i32, i32* %13, i64 1
%17 = load i32, i32* %16
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32* %16, i32 %17)
%19 = getelementptr inbounds i8*, i8** %2, i64 2
%20 = bitcast i8** %19 to i32*
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %19, i32 %21)
%23 = getelementptr inbounds i32, i32* %20, i64 1
%24 = load i32, i32* %23
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32* %23, i32 %24)
%26 = getelementptr inbounds i8*, i8** %2, i64 3
%27 = bitcast i8** %26 to i32*
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %26, i32 %28)
%30 = getelementptr inbounds i32, i32* %27, i64 1
%31 = load i32, i32* %30
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32* %30, i32 %31)
%33 = getelementptr inbounds i8*, i8** %2, i64 4
%34 = bitcast i8** %33 to i32*
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %33, i32 %35)
%37 = getelementptr inbounds i32, i32* %34, i64 1
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32* %37, i32 %38)
%40 = getelementptr inbounds i8*, i8** %2, i64 5
%41 = bitcast i8** %40 to i32*
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %40, i32 %42)
%44 = getelementptr inbounds i32, i32* %41, i64 1
%45 = load i32, i32* %44
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32* %44, i32 %45)
%47 = getelementptr inbounds i8*, i8** %2, i64 6
%48 = bitcast i8** %47 to i32*
%49 = load i32, i32* %48
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %47, i32 %49)
%51 = getelementptr inbounds i32, i32* %48, i64 1
%52 = load i32, i32* %51
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32* %51, i32 %52)
%54 = getelementptr inbounds i8*, i8** %2, i64 7
%55 = bitcast i8** %54 to i32*
%56 = load i32, i32* %55
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %54, i32 %56)
ret void
}