#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 */
size_t backtrace(void **, int);
char **backtrace_symbols(void **, size_t);
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ printf(char *, char *);
void pgp_show_stacktrace() {
  void *buffer[10];
  size_t buffer_size;
  char **symbols;
  buffer_size = backtrace(buffer, 10);
  symbols = backtrace_symbols(buffer, buffer_size);
  for (size_t i = 0; i < buffer_size; i++)
    printf("%s\n", symbols[i]);
  free(symbols);
}


x86 assembly (clang, -O0):
<pgp_show_stacktrace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
lea    -0x50(%rbp),%rdi
mov    $0xa,%esi
call   1050 <backtrace@plt>
mov    %rax,-0x58(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%rax
cmp    -0x58(%rbp),%rax
jae    11aa <pgp_show_stacktrace+0x6a>
mov    -0x60(%rbp),%rax
mov    -0x68(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe6c(%rip),%rdi
call   1060 <printf@plt>
mov    -0x68(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
jmp    1173 <pgp_show_stacktrace+0x33>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pgp_show_stacktrace>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <backtrace@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <backtrace_symbols@plt>
mov    %rax,%r12
test   %r14,%r14
je     1195 <pgp_show_stacktrace+0x55>
xor    %ebx,%ebx
lea    0xe86(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    (%r12,%rbx,8),%rsi
mov    %r15,%rdi
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1180 <pgp_show_stacktrace+0x40>
mov    %r12,%rdi
call   1030 <free@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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