#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 */
unsigned int factorial(unsigned int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, void *, ...);
int /*<<< orphan*/ stdout;
void *thread_func(void *arg) {
  fprintf(stdout, "thread_func(%p) - Start\n", arg);
  unsigned int val = arg ? *(unsigned int *)arg : 100;
  unsigned int res = factorial(val);
  fprintf(stdout, "thread_func(%p) -> %u\n", arg, res);
  return 0;
}


x86 assembly (clang, -O0):
<thread_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xec0(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
cmpq   $0x0,-0x8(%rbp)
je     1160 <thread_func+0x40>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    116d <thread_func+0x4d>
mov    $0x64,%eax
mov    %eax,-0x14(%rbp)
jmp    116d <thread_func+0x4d>
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <factorial@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%ecx
lea    0xe84(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_func>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2eb2(%rip),%r14
mov    (%r14),%edi
lea    0xec8(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %rbx,%rbx
je     114b <thread_func+0x2b>
mov    (%rbx),%edi
jmp    1150 <thread_func+0x30>
mov    $0x64,%edi
call   1030 <factorial@plt>
mov    (%r14),%edi
lea    0xeba(%rip),%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [25 x i8] c"thread_func(%p) - Start\0A\00"
@.str.1 = [23 x i8] c"thread_func(%p) -> %u\0A\00"
define i8* @thread_func(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i32, i32* @stdout
%6 = load i8*, i8** %2
%7 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i8*, i8** %2
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = bitcast i8* %11 to i32*
%13 = load i32, i32* %12
br label %15
14: ; preds = %1
br label %15
15: ; preds = %14, %10
%16 = phi i32 [ %13, %10 ], [ 100, %14 ]
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = call i32 @factorial(i32 %17)
store i32 %18, i32* %4
%19 = load i32, i32* @stdout
%20 = load i8*, i8** %2
%21 = load i32, i32* %4
%22 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %20, i32 %21)
ret i8* null
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [25 x i8] c"thread_func(%p) - Start\0A\00"
@.str.1 = [23 x i8] c"thread_func(%p) -> %u\0A\00"
define noalias i8* @thread_func(i8* %0) {
%2 = load i32, i32* @stdout
%3 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %2, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = icmp eq i8* %0, null
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = bitcast i8* %0 to i32*
%7 = load i32, i32* %6
br label %8
8: ; preds = %1, %5
%9 = phi i32 [ %7, %5 ], [ 100, %1 ]
%10 = tail call i32 @factorial(i32 %9)
%11 = load i32, i32* @stdout
%12 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %10)
ret i8* null
}