#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 dump(int signo) {
  void *buffer[30] = {0};
  size_t size = 0;
  size_t i = 0;
  char **strings = NULL;
  size = backtrace(buffer, 30);
  strings = backtrace_symbols(buffer, size);
  if (strings == NULL) {
    return;
  }
  for (i = 0; i < size; i++) {
    printf("%s\n", strings[i]);
  }
  free(strings);
}


x86 assembly (clang, -O0):
<dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x100(%rbp),%rdi
xor    %esi,%esi
mov    $0xf0,%edx
call   1070 <memset@plt>
movq   $0x0,-0x108(%rbp)
movq   $0x0,-0x110(%rbp)
movq   $0x0,-0x118(%rbp)
lea    -0x100(%rbp),%rdi
mov    $0x1e,%esi
call   1050 <backtrace@plt>
mov    %rax,-0x108(%rbp)
lea    -0x100(%rbp),%rdi
mov    -0x108(%rbp),%rsi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
jne    11d7 <dump+0x87>
jmp    1237 <dump+0xe7>
movq   $0x0,-0x110(%rbp)
mov    -0x110(%rbp),%rax
cmp    -0x108(%rbp),%rax
jae    122b <dump+0xdb>
mov    -0x118(%rbp),%rax
mov    -0x110(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdf1(%rip),%rdi
call   1060 <printf@plt>
mov    -0x110(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x110(%rbp)
jmp    11e2 <dump+0x92>
mov    -0x118(%rbp),%rdi
call   1030 <free@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xf8,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1e,%esi
call   1050 <backtrace@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <backtrace_symbols@plt>
test   %rax,%rax
je     120d <dump+0xcd>
mov    %rax,%r12
test   %r14,%r14
je     1205 <dump+0xc5>
xor    %ebx,%ebx
lea    0xe1c(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12,%rbx,8),%rsi
mov    %r15,%rdi
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11f0 <dump+0xb0>
mov    %r12,%rdi
call   1030 <free@plt>
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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