#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*/ f1();
int get_backtrace(void **, int);
int /*<<< orphan*/ print_backtrace(void **, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  int len;
  void *arr[32];
  printf("++get_backtrace\n");
  len = get_backtrace(arr, 32);
  printf("--get_backtrace %d\n", len);
  printf("++print_backtrace\n");
  print_backtrace(arr, len);
  printf("--print_backtrace\n");
  f1();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x120(%rbp),%rdi
mov    $0x20,%esi
call   1050 <get_backtrace@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x120(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <print_backtrace@plt>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <f1@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
lea    0xeb4(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1060 <get_backtrace@plt>
mov    %eax,%ebp
lea    0xe82(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <print_backtrace@plt>
lea    0xe92(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <f1@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"++get_backtrace\0A\00"
@.str.1 = [20 x i8] c"--get_backtrace %d\0A\00"
@.str.2 = [19 x i8] c"++print_backtrace\0A\00"
@.str.3 = [19 x i8] c"--print_backtrace\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [32 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [32 x i8*], [32 x i8*]* %7, i64 0, i64 0
%10 = call i32 @get_backtrace(i8** %9, i32 32)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%14 = getelementptr inbounds [32 x i8*], [32 x i8*]* %7, i64 0, i64 0
%15 = load i32, i32* %6
%16 = call i32 @print_backtrace(i8** %14, i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 (...) @f1()
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [20 x i8] c"--get_backtrace %d\0A\00"
@str = [16 x i8] c"++get_backtrace\00"
@str.4 = [18 x i8] c"++print_backtrace\00"
@str.5 = [18 x i8] c"--print_backtrace\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [32 x i8*]
%4 = bitcast [32 x i8*]* %3 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%6 = getelementptr inbounds [32 x i8*], [32 x i8*]* %3, i64 0, i64 0
%7 = call i32 @get_backtrace(i8** %6, i32 32)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.4, i64 0, i64 0))
%10 = call i32 @print_backtrace(i8** %6, i32 %7)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.5, i64 0, i64 0))
%12 = call i32 (...) @f1()
ret i32 0
}