#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 */
struct task_struct {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ show_trace(unsigned long *);
scalar_t__ thread_saved_fp(struct task_struct *);
void show_stack(struct task_struct *task, unsigned long *stack) {
  if (!stack) {
    if (task)
      stack = (unsigned long *)thread_saved_fp(task);
    else
      stack = (unsigned long *)&stack;
  }
  show_trace(stack);
}


x86 assembly (clang, -O0):
<show_stack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1165 <show_stack+0x45>
cmpq   $0x0,-0x8(%rbp)
je     1158 <show_stack+0x38>
mov    -0x8(%rbp),%rdi
call   1030 <thread_saved_fp@plt>
mov    %rax,-0x10(%rbp)
jmp    1160 <show_stack+0x40>
lea    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1165 <show_stack+0x45>
mov    -0x10(%rbp),%rdi
call   1040 <show_trace@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_stack>:
push   %rax
mov    %rsi,(%rsp)
test   %rsi,%rsi
jne    1144 <show_stack+0x24>
test   %rdi,%rdi
je     113d <show_stack+0x1d>
call   1030 <thread_saved_fp@plt>
mov    %rax,%rsi
mov    %rax,(%rsp)
jmp    1144 <show_stack+0x24>
mov    %rsp,%rsi
mov    %rsi,(%rsp)
mov    %rsi,%rdi
call   1040 <show_trace@plt>
pop    %rax
ret

LLVM IR (-O0):
%struct.task_struct = type { i32 }
define void @show_stack(%struct.task_struct* %0, i64* %1) {
%3 = alloca %struct.task_struct*
%4 = alloca i64*
store %struct.task_struct* %0, %struct.task_struct** %3
store i64* %1, i64** %4
%5 = load i64*, i64** %4
%6 = icmp ne i64* %5, null
br i1 %6, label %17, label %7
7: ; preds = %2
%8 = load %struct.task_struct*, %struct.task_struct** %3
%9 = icmp ne %struct.task_struct* %8, null
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load %struct.task_struct*, %struct.task_struct** %3
%12 = call i64 @thread_saved_fp(%struct.task_struct* %11)
%13 = inttoptr i64 %12 to i64*
store i64* %13, i64** %4
br label %16
14: ; preds = %7
%15 = bitcast i64** %4 to i64*
store i64* %15, i64** %4
br label %16
16: ; preds = %14, %10
br label %17
17: ; preds = %16, %2
%18 = load i64*, i64** %4
%19 = call i32 @show_trace(i64* %18)
ret void
}

LLVM IR (-O2):
%struct.task_struct = type { i32 }
define void @show_stack(%struct.task_struct* %0, i64* %1) {
%3 = alloca i64*
store i64* %1, i64** %3
%4 = icmp eq i64* %1, null
br i1 %4, label %5, label %13
5: ; preds = %2
%6 = icmp eq %struct.task_struct* %0, null
br i1 %6, label %10, label %7
7: ; preds = %5
%8 = tail call i64 @thread_saved_fp(%struct.task_struct* %0)
%9 = inttoptr i64 %8 to i64*
store i64* %9, i64** %3
br label %13
10: ; preds = %5
%11 = bitcast i64** %3 to i64***
store i64** %3, i64*** %11
%12 = bitcast i64** %3 to i64*
br label %13
13: ; preds = %7, %10, %2
%14 = phi i64* [ %9, %7 ], [ %12, %10 ], [ %1, %2 ]
%15 = call i32 @show_trace(i64* %14)
ret void
}