#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 */
int /*<<< orphan*/ printf(char *, long, int, int);
int rand();
int /*<<< orphan*/ usleep(int);
void *printMessages(void *arg) {
  long tid;
  tid = (long)arg;
  int sleepValue;
  for (int m = 1; m <= 5; m++) {
    sleepValue = 3 + rand() % 10;
    printf("I'm in thread number %3ld - message num %2d - sleep for %2d\n", tid,
           m, sleepValue);
    usleep(sleepValue * 1000 * 1000);
  }
}


x86 assembly (clang, -O0):
<printMessages>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x20(%rbp)
cmpl   $0x5,-0x20(%rbp)
jg     11a0 <printMessages+0x70>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x3,%edx
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
imul   $0x3e8,-0x1c(%rbp),%eax
imul   $0x3e8,%eax,%edi
call   1050 <usleep@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    114b <printMessages+0x1b>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printMessages>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%ebp
add    $0x3,%ebp
lea    0xe98(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    %ebp,%ecx
call   1030 <printf@plt>
imul   $0xf4240,%ebp,%edi
call   1050 <usleep@plt>
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%ebp
add    $0x3,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
mov    %ebp,%ecx
call   1030 <printf@plt>
imul   $0xf4240,%ebp,%edi
call   1050 <usleep@plt>
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%ebp
add    $0x3,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x3,%edx
mov    %ebp,%ecx
call   1030 <printf@plt>
imul   $0xf4240,%ebp,%edi
call   1050 <usleep@plt>
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%ebp
add    $0x3,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
mov    %ebp,%ecx
call   1030 <printf@plt>
imul   $0xf4240,%ebp,%edi
call   1050 <usleep@plt>
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%ebp
add    $0x3,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x5,%edx
mov    %ebp,%ecx
call   1030 <printf@plt>
imul   $0xf4240,%ebp,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <usleep@plt>

LLVM IR (-O0):
@.str = [61 x i8] c"I'm in thread number %3ld - message num %2d - sleep for %2d\0A\00"
define i8* @printMessages(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = ptrtoint i8* %7 to i64
store i64 %8, i64* %4
store i32 1, i32* %6
br label %9
9: ; preds = %24, %1
%10 = load i32, i32* %6
%11 = icmp sle i32 %10, 5
br i1 %11, label %12, label %27
12: ; preds = %9
%13 = call i32 (...) @rand()
%14 = srem i32 %13, 10
%15 = add nsw i32 3, %14
store i32 %15, i32* %5
%16 = load i64, i64* %4
%17 = load i32, i32* %6
%18 = load i32, i32* %5
%19 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i64 %16, i32 %17, i32 %18)
%20 = load i32, i32* %5
%21 = mul nsw i32 %20, 1000
%22 = mul nsw i32 %21, 1000
%23 = call i32 @usleep(i32 %22)
br label %24
24: ; preds = %12
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %9
27: ; preds = %9
%28 = load i8*, i8** %2
ret i8* %28
}

LLVM IR (-O2):
@.str = [61 x i8] c"I'm in thread number %3ld - message num %2d - sleep for %2d\0A\00"
define noalias i8* @printMessages(i8* %0) {
%2 = ptrtoint i8* %0 to i64
%3 = tail call i32 (...) @rand()
%4 = srem i32 %3, 10
%5 = add nsw i32 %4, 3
%6 = tail call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i64 %2, i32 1, i32 %5)
%7 = mul nsw i32 %5, 1000000
%8 = tail call i32 @usleep(i32 %7)
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 10
%11 = add nsw i32 %10, 3
%12 = tail call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i64 %2, i32 2, i32 %11)
%13 = mul nsw i32 %11, 1000000
%14 = tail call i32 @usleep(i32 %13)
%15 = tail call i32 (...) @rand()
%16 = srem i32 %15, 10
%17 = add nsw i32 %16, 3
%18 = tail call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i64 %2, i32 3, i32 %17)
%19 = mul nsw i32 %17, 1000000
%20 = tail call i32 @usleep(i32 %19)
%21 = tail call i32 (...) @rand()
%22 = srem i32 %21, 10
%23 = add nsw i32 %22, 3
%24 = tail call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i64 %2, i32 4, i32 %23)
%25 = mul nsw i32 %23, 1000000
%26 = tail call i32 @usleep(i32 %25)
%27 = tail call i32 (...) @rand()
%28 = srem i32 %27, 10
%29 = add nsw i32 %28, 3
%30 = tail call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i64 %2, i32 5, i32 %29)
%31 = mul nsw i32 %29, 1000000
%32 = tail call i32 @usleep(i32 %31)
ret i8* undef
}