#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*/ EXIT_FAILURE;
int backtrace(void **, int);
char **backtrace_symbols(void **, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int fn2() {
  int i;
  int nsyms;
  char **symbols;
  void *buffer[100];
  nsyms = backtrace(buffer, 100);
  symbols = backtrace_symbols(buffer, nsyms);
  if (symbols == NULL) {
    perror("backtrace_symbols");
    exit(EXIT_FAILURE);
  }
  for (i = 0; i < nsyms; i++) {
    printf("%s\n", symbols[i]);
  }
  free(symbols);
  return 0;
}


x86 assembly (clang, -O0):
<fn2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x330,%rsp
lea    -0x330(%rbp),%rdi
mov    $0x64,%esi
call   1050 <backtrace@plt>
mov    %eax,-0x8(%rbp)
lea    -0x330(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b7 <fn2+0x57>
lea    0xe5c(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f0 <fn2+0x90>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe35(%rip),%rdi
call   1060 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11be <fn2+0x5e>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x330,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fn2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x328,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1050 <backtrace@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <backtrace_symbols@plt>
test   %rax,%rax
je     11cd <fn2+0x6d>
mov    %rax,%r15
test   %ebp,%ebp
jle    11b5 <fn2+0x55>
mov    %ebp,%ebp
xor    %ebx,%ebx
lea    0xe72(%rip),%r14
mov    (%r15,%rbx,8),%rsi
mov    %r14,%rdi
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11a0 <fn2+0x40>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x328,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe2c(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

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

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