#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    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xeb1(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <rand@plt>
movaps %xmm0,%xmm1
movsd  0xe92(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe7e(%rip),%xmm1
mov    0x2e5f(%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    0xe90(%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),%ebx
lea    0xec6(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1060 <rand@plt>
mulsd  0xea0(%rip),%xmm0
mov    0x2e81(%rip),%rax
movsd  (%rax),%xmm1
addsd  0xe95(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
add    $0x1,%edi
call   1050 <sleep@plt>
lea    0xeb3(%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 = bitcast i8* %6 to i32*
%8 = load i32, i32* %7
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call double (...) @rand()
%12 = fmul double 9.000000e+00, %11
%13 = load double, double* @RAND_MAX
%14 = fadd double %13, 1.000000e+00
%15 = fdiv double %12, %14
%16 = fptosi double %15 to i32
%17 = add nsw i32 1, %16
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = call i32 @sleep(i32 %18)
%20 = load i32, i32* %4
%21 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = call i32 @pthread_exit(i32* null)
%23 = load i8*, i8** %2
ret i8* %23
}

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* nocapture %0) {
%2 = bitcast i8* %0 to i32*
%3 = load i32, i32* %2
%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
}