#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 print_stack_debug(void *stack, const size_t *count) {
  printf("STACK INFO START\n");
  printf("Address pointed to by stackinfo:\t%p\n", stack);
  printf("Address of stackinfo:\t%p\n", &stack);
  printf("COUNT:\t%d\n", *count);
  printf("VALUES: ");
  int *arr = (int *)stack;
  for (size_t i = 0; i < *count; ++i) {
    printf("%d ", arr[i]);
  }
  printf("\n");
  printf("STACK INFO END\n");
}


x86 assembly (clang, -O0):
<print_stack_debug>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rsi
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef0(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xef1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jae    11c0 <print_stack_debug+0xb0>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1185 <print_stack_debug+0x75>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_stack_debug>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rdi,(%rsp)
lea    0xf0e(%rip),%rdi
call   1040 <puts@plt>
lea    0xeab(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xebf(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%rsi
lea    0xec5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpq   $0x0,(%r15)
je     11c7 <print_stack_debug+0x97>
mov    (%rsp),%r12
lea    0xeb3(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    (%r15),%rbx
jb     11b0 <print_stack_debug+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe90(%rip),%rdi
call   1040 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"STACK INFO START\0A\00"
@.str.1 = [37 x i8] c"Address pointed to by stackinfo:\09%p\0A\00"
@.str.2 = [26 x i8] c"Address of stackinfo:\09%p\0A\00"
@.str.3 = [11 x i8] c"COUNT:\09%d\0A\00"
@.str.4 = [9 x i8] c"VALUES: \00"
@.str.5 = [4 x i8] c"%d \00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [16 x i8] c"STACK INFO END\0A\00"
define void @print_stack_debug(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca i32*
%6 = alloca i64
store i8* %0, i8** %3
store i64* %1, i64** %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8** %3)
%11 = load i64*, i64** %4
%12 = load i64, i64* %11
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i64 %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%15 = load i8*, i8** %3
%16 = bitcast i8* %15 to i32*
store i32* %16, i32** %5
store i64 0, i64* %6
br label %17
17: ; preds = %28, %2
%18 = load i64, i64* %6
%19 = load i64*, i64** %4
%20 = load i64, i64* %19
%21 = icmp ult i64 %18, %20
br i1 %21, label %22, label %31
22: ; preds = %17
%23 = load i32*, i32** %5
%24 = load i64, i64* %6
%25 = getelementptr inbounds i32, i32* %23, i64 %24
%26 = load i32, i32* %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %22
%29 = load i64, i64* %6
%30 = add i64 %29, 1
store i64 %30, i64* %6
br label %17
31: ; preds = %17
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [37 x i8] c"Address pointed to by stackinfo:\09%p\0A\00"
@.str.2 = [26 x i8] c"Address of stackinfo:\09%p\0A\00"
@.str.3 = [11 x i8] c"COUNT:\09%d\0A\00"
@.str.4 = [9 x i8] c"VALUES: \00"
@.str.5 = [4 x i8] c"%d \00"
@str = [17 x i8] c"STACK INFO START\00"
@str.8 = [15 x i8] c"STACK INFO END\00"
define void @print_stack_debug(i8* %0, i64* nocapture %1) {
%3 = alloca i8*
store i8* %0, i8** %3
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8** %3)
%7 = load i64, i64* %1
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i64 %7)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%10 = bitcast i8** %3 to i32**
%11 = load i32*, i32** %10
%12 = load i64, i64* %1
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %17, %2
%15 = call i32 @putchar(i32 10)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.8, i64 0, i64 0))
ret void
17: ; preds = %2, %17
%18 = phi i64 [ %22, %17 ], [ 0, %2 ]
%19 = getelementptr inbounds i32, i32* %11, i64 %18
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %20)
%22 = add nuw i64 %18, 1
%23 = load i64, i64* %1
%24 = icmp ult i64 %22, %23
br i1 %24, label %17, label %14
}