#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 */
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ STDERR_FILENO;
int backtrace(void **, int);
scalar_t__ backtrace_symbols(void **, int);
int /*<<< orphan*/ free(char **);
int snprintf(char *, int, char *, int, char *);
int sprintf(char *, char *, int, char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
void sig_btdump() {
  char buff[1024] = {'\0'};
  int size, i;
  char **strings = NULL;
  void *buffer[64] = {NULL};
  int len;
  size = backtrace(buffer, (sizeof(buffer) / sizeof(buffer[0])));
  strings = (char **)backtrace_symbols(buffer, size);
  len = sprintf(buff, "\nBacktrace:%d\t%s\n", size,
                strings == NULL ? "strings:NULL" : "");
  write(STDERR_FILENO, buff, len);
  if (strings) {
    for (i = 0; i < size; i++) {
      len = snprintf(buff, sizeof(buff), "\t%d: %s\n", i, strings[i]);
      write(STDERR_FILENO, buff, len);
    }
    free(strings);
  }
  return;
}


x86 assembly (clang, -O0):
<sig_btdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x620,%rsp
lea    -0x400(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
movq   $0x0,-0x410(%rbp)
lea    -0x610(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1080 <memset@plt>
lea    -0x610(%rbp),%rdi
mov    $0x40,%esi
call   1060 <backtrace@plt>
mov    %eax,-0x404(%rbp)
lea    -0x610(%rbp),%rdi
mov    -0x404(%rbp),%esi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x410(%rbp)
lea    -0x400(%rbp),%rdi
mov    -0x404(%rbp),%edx
mov    -0x410(%rbp),%rsi
lea    0xe1a(%rip),%rcx
lea    0xe14(%rip),%rax
cmp    $0x0,%rsi
cmove  %rax,%rcx
lea    0xdf3(%rip),%rsi
call   1090 <sprintf@plt>
mov    %eax,-0x614(%rbp)
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
lea    -0x400(%rbp),%rsi
mov    -0x614(%rbp),%edx
call   1050 <write@plt>
cmpq   $0x0,-0x410(%rbp)
je     12ce <sig_btdump+0x15e>
movl   $0x0,-0x408(%rbp)
mov    -0x408(%rbp),%eax
cmp    -0x404(%rbp),%eax
jge    12c2 <sig_btdump+0x152>
lea    -0x400(%rbp),%rdi
mov    -0x408(%rbp),%ecx
mov    -0x410(%rbp),%rax
movslq -0x408(%rbp),%rdx
mov    (%rax,%rdx,8),%r8
mov    $0x400,%esi
lea    0xd97(%rip),%rdx
call   1070 <snprintf@plt>
mov    %eax,-0x614(%rbp)
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
lea    -0x400(%rbp),%rsi
mov    -0x614(%rbp),%edx
call   1050 <write@plt>
mov    -0x408(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x408(%rbp)
jmp    124b <sig_btdump+0xdb>
mov    -0x410(%rbp),%rdi
call   1030 <free@plt>
add    $0x620,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sig_btdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x608,%rsp
lea    0x200(%rsp),%r14
mov    $0x400,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
mov    %rsp,%rbx
mov    $0x200,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
mov    %rbx,%rdi
mov    $0x40,%esi
call   1060 <backtrace@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <backtrace_symbols@plt>
mov    %rax,%r15
test   %rax,%rax
lea    0xe42(%rip),%rax
lea    0xe3a(%rip),%rcx
cmove  %rax,%rcx
lea    0xe1e(%rip),%rsi
mov    %r14,%rdi
mov    %ebp,%edx
call   1090 <sprintf@plt>
mov    0x2ded(%rip),%r12
mov    (%r12),%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <write@plt>
test   %r15,%r15
je     1255 <sig_btdump+0xe5>
test   %ebp,%ebp
jle    124d <sig_btdump+0xdd>
mov    %ebp,%r13d
xor    %ebp,%ebp
lea    0xe09(%rip),%r14
lea    0x200(%rsp),%rbx
xchg   %ax,%ax
mov    (%r15,%rbp,8),%r8
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1070 <snprintf@plt>
mov    (%r12),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1220 <sig_btdump+0xb0>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x608,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"\0ABacktrace:%d\09%s\0A\00"
@.str.1 = [13 x i8] c"strings:NULL\00"
@.str.2 = [1 x i8] zeroinitializer
@STDERR_FILENO = global i32 0
@.str.3 = [9 x i8] c"\09%d: %s\0A\00"
define void @sig_btdump() {
%1 = alloca [1024 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [64 x i8*]
%6 = alloca i32
%7 = bitcast [1024 x i8]* %1 to i8*
store i8** null, i8*** %4
%8 = bitcast [64 x i8*]* %5 to i8*
%9 = getelementptr inbounds [64 x i8*], [64 x i8*]* %5, i64 0, i64 0
%10 = call i32 @backtrace(i8** %9, i32 64)
store i32 %10, i32* %2
%11 = getelementptr inbounds [64 x i8*], [64 x i8*]* %5, i64 0, i64 0
%12 = load i32, i32* %2
%13 = call i64 @backtrace_symbols(i8** %11, i32 %12)
%14 = inttoptr i64 %13 to i8**
store i8** %14, i8*** %4
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%16 = load i32, i32* %2
%17 = load i8**, i8*** %4
%18 = icmp eq i8** %17, null
%19 = zext i1 %18 to i64
%20 = select i1 %18, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%21 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %16, i8* %20)
store i32 %21, i32* %6
%22 = load i32, i32* @STDERR_FILENO
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%24 = load i32, i32* %6
%25 = call i32 @write(i32 %22, i8* %23, i32 %24)
%26 = load i8**, i8*** %4
%27 = icmp ne i8** %26, null
br i1 %27, label %28, label %52
28: ; preds = %0
store i32 0, i32* %3
br label %29
29: ; preds = %46, %28
%30 = load i32, i32* %3
%31 = load i32, i32* %2
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %49
33: ; preds = %29
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%35 = load i32, i32* %3
%36 = load i8**, i8*** %4
%37 = load i32, i32* %3
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
%41 = call i32 @snprintf(i8* %34, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %35, i8* %40)
store i32 %41, i32* %6
%42 = load i32, i32* @STDERR_FILENO
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%44 = load i32, i32* %6
%45 = call i32 @write(i32 %42, i8* %43, i32 %44)
br label %46
46: ; preds = %33
%47 = load i32, i32* %3
%48 = add nsw i32 %47, 1
store i32 %48, i32* %3
br label %29
49: ; preds = %29
%50 = load i8**, i8*** %4
%51 = call i32 @free(i8** %50)
br label %52
52: ; preds = %49, %0
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"\0ABacktrace:%d\09%s\0A\00"
@.str.1 = [13 x i8] c"strings:NULL\00"
@.str.2 = [1 x i8] zeroinitializer
@STDERR_FILENO = global i32 0
@.str.3 = [9 x i8] c"\09%d: %s\0A\00"
define void @sig_btdump() {
%1 = alloca [1024 x i8]
%2 = alloca [64 x i8*]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%4 = bitcast [64 x i8*]* %2 to i8*
%5 = getelementptr inbounds [64 x i8*], [64 x i8*]* %2, i64 0, i64 0
%6 = call i32 @backtrace(i8** %5, i32 64)
%7 = call i64 @backtrace_symbols(i8** %5, i32 %6)
%8 = inttoptr i64 %7 to i8**
%9 = icmp eq i64 %7, 0
%10 = select i1 %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%11 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %6, i8* %10)
%12 = load i32, i32* @STDERR_FILENO
%13 = call i32 @write(i32 %12, i8* %3, i32 %11)
br i1 %9, label %30, label %14
14: ; preds = %0
%15 = icmp sgt i32 %6, 0
br i1 %15, label %16, label %28
16: ; preds = %14
%17 = zext i32 %6 to i64
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ 0, %16 ], [ %26, %18 ]
%20 = getelementptr inbounds i8*, i8** %8, i64 %19
%21 = load i8*, i8** %20
%22 = trunc i64 %19 to i32
%23 = call i32 @snprintf(i8* %3, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %22, i8* %21)
%24 = load i32, i32* @STDERR_FILENO
%25 = call i32 @write(i32 %24, i8* %3, i32 %23)
%26 = add nuw nsw i64 %19, 1
%27 = icmp eq i64 %26, %17
br i1 %27, label %28, label %18
28: ; preds = %18, %14
%29 = call i32 @free(i8** %8)
br label %30
30: ; preds = %28, %0
ret void
}