#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 */
typedef int /*<<< orphan*/ pthread_t;

/* Variables and functions */
int labs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, ...);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_self();
int /*<<< orphan*/ random();
void *thread_job(void *no_argument) {
  pthread_t my_task_id = pthread_self();
  int i = 0, iter = labs(random()) / 10;
  printf("Thread %p : Start processing, %d iterations\n", my_task_id, iter);
  while (i < iter)
    i++;
  printf("Thread %p : End of processing\n", my_task_id);
  pthread_exit(NULL);
}


x86 assembly (clang, -O0):
<thread_job>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <pthread_self@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1050 <random@plt>
mov    %eax,%edi
call   1030 <labs@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11b4 <thread_job+0x64>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119a <thread_job+0x4a>
mov    -0x14(%rbp),%esi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_job>:
push   %rbx
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <random@plt>
mov    %eax,%ecx
neg    %ecx
cmovs  %eax,%ecx
mov    $0xcccccccd,%edx
imul   %rcx,%rdx
shr    $0x23,%rdx
lea    0xe94(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeb1(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
pop    %rbx
jmp    1050 <pthread_exit@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"Thread %p : Start processing, %d iterations\0A\00"
@.str.1 = [31 x i8] c"Thread %p : End of processing\0A\00"
define i8* @thread_job(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = call i32 (...) @pthread_self()
store i32 %7, i32* %4
store i32 0, i32* %5
%8 = call i32 (...) @random()
%9 = call i32 @labs(i32 %8)
%10 = sdiv i32 %9, 10
store i32 %10, i32* %6
%11 = load i32, i32* %4
%12 = load i32, i32* %6
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12)
br label %14
14: ; preds = %18, %1
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
store i32 %20, i32* %5
br label %14
21: ; preds = %14
%22 = load i32, i32* %4
%23 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = call i32 @pthread_exit(i32* null)
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
@.str = [45 x i8] c"Thread %p : Start processing, %d iterations\0A\00"
@.str.1 = [31 x i8] c"Thread %p : End of processing\0A\00"
define noalias i8* @thread_job(i8* nocapture readnone %0) {
%2 = tail call i32 (...) @pthread_self()
%3 = tail call i32 (...) @random()
%4 = tail call i32 @llvm.abs.i32(i32 %3, i1 true)
%5 = udiv i32 %4, 10
%6 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %5)
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%8 = tail call i32 @pthread_exit(i32* null)
ret i8* undef
}