#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 */
int /*<<< orphan*/ foo_hold(struct foo *);
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());
  struct foo *fp = (struct foo *)arg;
  foo_hold(fp);
  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    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <pthread_self@plt>
mov    %eax,%esi
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <foo_hold@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    -0x10(%rbp),%rdi
call   1060 <foo_rele@plt>
mov    $0x0,%al
call   1050 <pthread_self@plt>
mov    %eax,%esi
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thr_fn>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <pthread_self@plt>
lea    0xe9e(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1040 <foo_hold@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
call   1060 <foo_rele@plt>
xor    %eax,%eax
call   1050 <pthread_self@plt>
lea    0xe83(%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 %struct.foo*
store i8* %0, i8** %2
%4 = call i32 (...) @pthread_self()
%5 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i8*, i8** %2
%7 = bitcast i8* %6 to %struct.foo*
store %struct.foo* %7, %struct.foo** %3
%8 = load %struct.foo*, %struct.foo** %3
%9 = call i32 @foo_hold(%struct.foo* %8)
%10 = call i32 @sleep(i32 1)
%11 = load %struct.foo*, %struct.foo** %3
%12 = call i32 @foo_rele(%struct.foo* %11)
%13 = call i32 (...) @pthread_self()
%14 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %13)
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 = bitcast i8* %0 to %struct.foo*
%5 = tail call i32 @foo_hold(%struct.foo* %4)
%6 = tail call i32 @sleep(i32 1)
%7 = tail call i32 @foo_rele(%struct.foo* %4)
%8 = tail call i32 (...) @pthread_self()
%9 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %8)
ret i8* null
}