#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 backtrace(void **, int);
char **backtrace_symbols(void **, int);
int /*<<< orphan*/ printf(char *, int, char *);
void print_stack(void) {
  void *array[20];
  int size;
  char **strings;
  int i;
  size = backtrace(array, 20);
  strings = backtrace_symbols(array, size);
  for (i = 0; i < size; i++) {
    printf("%d : %s\n", i, strings[i]);
  }
}


x86 assembly (clang, -O0):
<print_stack>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
lea    -0xa0(%rbp),%rdi
mov    $0x14,%esi
call   1040 <backtrace@plt>
mov    %eax,-0xa4(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0xa4(%rbp),%esi
call   1030 <backtrace_symbols@plt>
mov    %rax,-0xb0(%rbp)
movl   $0x0,-0xb4(%rbp)
mov    -0xb4(%rbp),%eax
cmp    -0xa4(%rbp),%eax
jge    11bf <print_stack+0x8f>
mov    -0xb4(%rbp),%esi
mov    -0xb0(%rbp),%rax
movslq -0xb4(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe5a(%rip),%rdi
call   1050 <printf@plt>
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    1175 <print_stack+0x45>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_stack>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x14,%esi
call   1040 <backtrace@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <backtrace_symbols@plt>
test   %ebx,%ebx
jle    1187 <print_stack+0x57>
mov    %rax,%r14
mov    %ebx,%r12d
xor    %ebx,%ebx
lea    0xe93(%rip),%r15
nopl   (%rax)
mov    (%r14,%rbx,8),%rdx
mov    %r15,%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1170 <print_stack+0x40>
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [9 x i8] c"%d : %s\0A\00"
define void @print_stack() {
%1 = alloca [20 x i8*]
%2 = bitcast [20 x i8*]* %1 to i8*
%3 = getelementptr inbounds [20 x i8*], [20 x i8*]* %1, i64 0, i64 0
%4 = call i32 @backtrace(i8** %3, i32 20)
%5 = call i8** @backtrace_symbols(i8** %3, i32 %4)
%6 = icmp sgt i32 %4, 0
br i1 %6, label %7, label %17
7: ; preds = %0
%8 = zext i32 %4 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %15, %9 ]
%11 = getelementptr inbounds i8*, i8** %5, i64 %10
%12 = load i8*, i8** %11
%13 = trunc i64 %10 to i32
%14 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %13, i8* %12)
%15 = add nuw nsw i64 %10, 1
%16 = icmp eq i64 %15, %8
br i1 %16, label %17, label %9
17: ; preds = %9, %0
ret void
}