#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 */
double RAND_MAX;
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/ *);
double rand();
int /*<<< orphan*/ sleep(int);
void *thread_function(void *arg) {
  int my_number = (int)arg;
  int rand_num;
  printf("thread_function is running. Argument was %d\n", my_number);
  rand_num = 1 + (int)(9.0 * rand() / (RAND_MAX + 1.0));
  sleep(rand_num);
  printf("Bye from %d\n", my_number);
  pthread_exit(NULL);
}


x86 assembly (clang, -O0):
<thread_function>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <rand@plt>
movaps %xmm0,%xmm1
movsd  0xe94(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe80(%rip),%xmm1
mov    0x2e61(%rip),%rax
addsd  (%rax),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <sleep@plt>
mov    -0x14(%rbp),%esi
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_function>:
push   %rbx
mov    %rdi,%rbx
lea    0xec5(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1060 <rand@plt>
mulsd  0xe9f(%rip),%xmm0
mov    0x2e80(%rip),%rax
movsd  (%rax),%xmm1
addsd  0xe94(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
add    $0x1,%edi
call   1050 <sleep@plt>
lea    0xeb2(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %edi,%edi
pop    %rbx
jmp    1040 <pthread_exit@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"thread_function is running. Argument was %d\0A\00"
@RAND_MAX = global double 0.000000e+00
@.str.1 = [13 x i8] c"Bye from %d\0A\00"
define i8* @thread_function(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = ptrtoint i8* %6 to i32
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call double (...) @rand()
%11 = fmul double 9.000000e+00, %10
%12 = load double, double* @RAND_MAX
%13 = fadd double %12, 1.000000e+00
%14 = fdiv double %11, %13
%15 = fptosi double %14 to i32
%16 = add nsw i32 1, %15
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = call i32 @sleep(i32 %17)
%19 = load i32, i32* %4
%20 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = call i32 @pthread_exit(i32* null)
%22 = load i8*, i8** %2
ret i8* %22
}

LLVM IR (-O2):
@.str = [45 x i8] c"thread_function is running. Argument was %d\0A\00"
@RAND_MAX = global double 0.000000e+00
@.str.1 = [13 x i8] c"Bye from %d\0A\00"
define noalias i8* @thread_function(i8* %0) {
%2 = ptrtoint i8* %0 to i64
%3 = trunc i64 %2 to i32
%4 = tail call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call double (...) @rand()
%6 = fmul double %5, 9.000000e+00
%7 = load double, double* @RAND_MAX
%8 = fadd double %7, 1.000000e+00
%9 = fdiv double %6, %8
%10 = fptosi double %9 to i32
%11 = add nsw i32 %10, 1
%12 = tail call i32 @sleep(i32 %11)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%14 = tail call i32 @pthread_exit(i32* null)
ret i8* undef
}