#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 foo {
  int dummy;
};

/* Variables and functions */
struct foo *foo_find(int);
int /*<<< orphan*/ foo_rele(struct foo *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ pthread_self();
int /*<<< orphan*/ sleep(int);
void *thr_fn(void *arg) {
  printf("thread %lu running\n", pthread_self());
  int id = (int)arg;
  struct foo *fp = foo_find(id);
  sleep(1);
  foo_rele(fp);
  printf("thread %lu exit\n", pthread_self());
  return NULL;
}


x86 assembly (clang, -O0):
<thr_fn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <pthread_self@plt>
mov    %eax,%esi
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <foo_find@plt>
mov    %rax,-0x18(%rbp)
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    -0x18(%rbp),%rdi
call   1060 <foo_rele@plt>
mov    $0x0,%al
call   1040 <pthread_self@plt>
mov    %eax,%esi
lea    0xe6d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thr_fn>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <pthread_self@plt>
lea    0xe9e(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %ebx,%edi
call   1050 <foo_find@plt>
mov    %rax,%rbx
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
call   1060 <foo_rele@plt>
xor    %eax,%eax
call   1040 <pthread_self@plt>
lea    0xe81(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.foo = type { i32 }
@.str = [20 x i8] c"thread %lu running\0A\00"
@.str.1 = [17 x i8] c"thread %lu exit\0A\00"
define i8* @thr_fn(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.foo*
store i8* %0, i8** %2
%5 = call i32 (...) @pthread_self()
%6 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i8*, i8** %2
%8 = ptrtoint i8* %7 to i32
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = call %struct.foo* @foo_find(i32 %9)
store %struct.foo* %10, %struct.foo** %4
%11 = call i32 @sleep(i32 1)
%12 = load %struct.foo*, %struct.foo** %4
%13 = call i32 @foo_rele(%struct.foo* %12)
%14 = call i32 (...) @pthread_self()
%15 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %14)
ret i8* null
}

LLVM IR (-O2):
%struct.foo = type { i32 }
@.str = [20 x i8] c"thread %lu running\0A\00"
@.str.1 = [17 x i8] c"thread %lu exit\0A\00"
define noalias i8* @thr_fn(i8* %0) {
%2 = tail call i32 (...) @pthread_self()
%3 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = ptrtoint i8* %0 to i64
%5 = trunc i64 %4 to i32
%6 = tail call %struct.foo* @foo_find(i32 %5)
%7 = tail call i32 @sleep(i32 1)
%8 = tail call i32 @foo_rele(%struct.foo* %6)
%9 = tail call i32 (...) @pthread_self()
%10 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %9)
ret i8* null
}