#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*/ stack_addr;

/* Variables and functions */
int backtrace(void **, int);
char **backtrace_symbols(void **, int);
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ get_ebp(unsigned long *);
int /*<<< orphan*/ memset(void **, int /*<<< orphan*/, int);
int my_backtrace(void **, int, unsigned long);
int /*<<< orphan*/ printf(char *, ...);
int func_3(int a, int b, int c) {
  void *stack_addr[10];
  int layer;
  int i;
  char **ppstack_funcs;
  layer = backtrace(stack_addr, 10);
  ppstack_funcs = backtrace_symbols(stack_addr, layer);
  for (i = 0; i < layer; i++)
    printf("\n%s:%p\n", ppstack_funcs[i], stack_addr[i]);
  printf("argv[0]=%d,addr=%p\n", (stack_addr[0] + 4), stack_addr[0] + 4);
  printf("------------\n");
  unsigned long ebp = 0;
  get_ebp(&ebp);
  memset(stack_addr, 0, sizeof(stack_addr));
  layer = my_backtrace(stack_addr, 10, ebp);
  for (i = 0; i < layer; i++)
    printf("\nmy: %p\n", stack_addr[i]);
  free(ppstack_funcs);
  return 3;
}


x86 assembly (clang, -O0):
<func_3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0xa,%esi
call   1050 <backtrace@plt>
mov    %eax,-0x64(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x64(%rbp),%esi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x70(%rbp)
movl   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x64(%rbp),%eax
jge    11e9 <func_3+0x79>
mov    -0x70(%rbp),%rax
movslq -0x68(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
movslq -0x68(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rdx
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    11ac <func_3+0x3c>
mov    -0x60(%rbp),%rsi
add    $0x4,%rsi
mov    -0x60(%rbp),%rdx
add    $0x4,%rdx
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movq   $0x0,-0x78(%rbp)
lea    -0x78(%rbp),%rdi
call   1080 <get_ebp@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1090 <memset@plt>
lea    -0x60(%rbp),%rdi
mov    -0x78(%rbp),%rdx
mov    $0xa,%esi
call   1070 <my_backtrace@plt>
mov    %eax,-0x64(%rbp)
movl   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x64(%rbp),%eax
jge    1283 <func_3+0x113>
movslq -0x68(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rsi
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    1252 <func_3+0xe2>
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
mov    $0x3,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<func_3>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0xa,%esi
call   1060 <backtrace@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <backtrace_symbols@plt>
mov    %rax,%r14
test   %ebx,%ebx
jle    11dc <func_3+0x5c>
mov    %ebx,%r12d
lea    0xe46(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r14,%rbx,8),%rsi
mov    0x10(%rsp,%rbx,8),%rdx
mov    %r15,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11c0 <func_3+0x40>
mov    0x10(%rsp),%rdx
add    $0x4,%rdx
lea    0xe1c(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe28(%rip),%rdi
call   1040 <puts@plt>
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1090 <get_ebp@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   10a0 <memset@plt>
mov    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1080 <my_backtrace@plt>
test   %eax,%eax
jle    1268 <func_3+0xe8>
mov    %eax,%r12d
lea    0xdd3(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp,%rbx,8),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1250 <func_3+0xd0>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x3,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"\0A%s:%p\0A\00"
@.str.1 = [20 x i8] c"argv[0]=%d,addr=%p\0A\00"
@.str.2 = [14 x i8] c"------------\0A\00"
@.str.3 = [9 x i8] c"\0Amy: %p\0A\00"
define i32 @func_3(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [10 x i8*]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8**
%11 = alloca i64
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 0
%13 = call i32 @backtrace(i8** %12, i32 10)
store i32 %13, i32* %8
%14 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 0
%15 = load i32, i32* %8
%16 = call i8** @backtrace_symbols(i8** %14, i32 %15)
store i8** %16, i8*** %10
store i32 0, i32* %9
br label %17
17: ; preds = %32, %3
%18 = load i32, i32* %9
%19 = load i32, i32* %8
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %35
21: ; preds = %17
%22 = load i8**, i8*** %10
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 %28
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %26, i8* %30)
br label %32
32: ; preds = %21
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %17
35: ; preds = %17
%36 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 0
%37 = load i8*, i8** %36
%38 = getelementptr i8, i8* %37, i64 4
%39 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 0
%40 = load i8*, i8** %39
%41 = getelementptr i8, i8* %40, i64 4
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %38, i8* %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i64 0, i64* %11
%44 = call i32 @get_ebp(i64* %11)
%45 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 0
%46 = call i32 @memset(i8** %45, i32 0, i32 80)
%47 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 0
%48 = load i64, i64* %11
%49 = call i32 @my_backtrace(i8** %47, i32 10, i64 %48)
store i32 %49, i32* %8
store i32 0, i32* %9
br label %50
50: ; preds = %60, %35
%51 = load i32, i32* %9
%52 = load i32, i32* %8
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %63
54: ; preds = %50
%55 = load i32, i32* %9
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 %56
%58 = load i8*, i8** %57
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %58)
br label %60
60: ; preds = %54
%61 = load i32, i32* %9
%62 = add nsw i32 %61, 1
store i32 %62, i32* %9
br label %50
63: ; preds = %50
%64 = load i8**, i8*** %10
%65 = call i32 @free(i8** %64)
ret i32 3
}

LLVM IR (-O2):
@.str = [8 x i8] c"\0A%s:%p\0A\00"
@.str.1 = [20 x i8] c"argv[0]=%d,addr=%p\0A\00"
@.str.3 = [9 x i8] c"\0Amy: %p\0A\00"
@str = [13 x i8] c"------------\00"
define i32 @func_3(i32 %0, i32 %1, i32 %2) {
%4 = alloca [10 x i8*]
%5 = alloca i64
%6 = bitcast [10 x i8*]* %4 to i8*
%7 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 0
%8 = call i32 @backtrace(i8** %7, i32 10)
%9 = call i8** @backtrace_symbols(i8** %7, i32 %8)
%10 = icmp sgt i32 %8, 0
br i1 %10, label %11, label %22
11: ; preds = %3
%12 = zext i32 %8 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %20, %13 ]
%15 = getelementptr inbounds i8*, i8** %9, i64 %14
%16 = load i8*, i8** %15
%17 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 %14
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %18)
%20 = add nuw nsw i64 %14, 1
%21 = icmp eq i64 %20, %12
br i1 %21, label %22, label %13
22: ; preds = %13, %3
%23 = load i8*, i8** %7
%24 = getelementptr i8, i8* %23, i64 4
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %24, i8* %24)
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%27 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%28 = call i32 @get_ebp(i64* %5)
%29 = call i32 @memset(i8** %7, i32 0, i32 80)
%30 = load i64, i64* %5
%31 = call i32 @my_backtrace(i8** %7, i32 10, i64 %30)
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %22
%34 = zext i32 %31 to i64
br label %35
35: ; preds = %33, %35
%36 = phi i64 [ 0, %33 ], [ %40, %35 ]
%37 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %38)
%40 = add nuw nsw i64 %36, 1
%41 = icmp eq i64 %40, %34
br i1 %41, label %42, label %35
42: ; preds = %35, %22
%43 = call i32 @free(i8** %9)
ret i32 3
}