#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 debugDumpStack(unsigned int *sp) {
  printf("~~~ Stack dump~~~~");
  unsigned int i;
  for (i = 0; i < 40; i++) {
    printf("0x%h ", *(sp + i));
    if (i % 10 == 0) {
      printf("\n");
    }
  }
}


x86 assembly (clang, -O0):
<debugDumpStack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xedd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x28,-0xc(%rbp)
jae    1189 <debugDumpStack+0x79>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    (%rax,%rcx,4),%esi
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
cmp    $0x0,%edx
jne    1176 <debugDumpStack+0x66>
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    117b <debugDumpStack+0x6b>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1131 <debugDumpStack+0x21>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debugDumpStack>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
lea    0xece(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed3(%rip),%r14
xor    %r12d,%r12d
xor    %ebx,%ebx
jmp    115e <debugDumpStack+0x3e>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
add    $0xff,%r12b
cmp    $0x28,%rbx
je     118f <debugDumpStack+0x6f>
movzbl %bl,%eax
imul   $0xcd,%eax,%eax
shr    $0xa,%eax
and    $0xfffffffe,%eax
lea    (%rax,%rax,4),%ebp
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    %r12b,%bpl
jne    1150 <debugDumpStack+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1150 <debugDumpStack+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [19 x i8] c"~~~ Stack dump~~~~\00"
@.str.1 = [6 x i8] c"0x%h \00"
define void @debugDumpStack(i32* nocapture %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %3
3: ; preds = %1, %13
%4 = phi i64 [ 0, %1 ], [ %14, %13 ]
%5 = getelementptr inbounds i32, i32* %0, i64 %4
%6 = load i32, i32* %5
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = trunc i64 %4 to i8
%9 = urem i8 %8, 10
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = tail call i32 @putchar(i32 10)
br label %13
13: ; preds = %3, %11
%14 = add nuw nsw i64 %4, 1
%15 = icmp eq i64 %14, 40
br i1 %15, label %16, label %3
16: ; preds = %13
ret void
}