#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 *, void *);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/ *);
int random();
int /*<<< orphan*/ usleep(int);
void *printHello(void *threadID) {
  int i;
  for (i = 0; i < 5; ++i) {
    printf("Thread %d says: Hello!\n", threadID);
    usleep(random() & 0x0000FFFF);
  }
  printf("Thread %d says: Goodbye!\n", threadID);
  pthread_exit(NULL);
}


x86 assembly (clang, -O0):
<printHello>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    118f <printHello+0x4f>
mov    -0x10(%rbp),%rsi
lea    0xe98(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <random@plt>
mov    %eax,%edi
and    $0xffff,%edi
call   1060 <usleep@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1153 <printHello+0x13>
mov    -0x10(%rbp),%rsi
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printHello>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xeb2(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <random@plt>
movzwl %ax,%edi
call   1060 <usleep@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <random@plt>
movzwl %ax,%edi
call   1060 <usleep@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <random@plt>
movzwl %ax,%edi
call   1060 <usleep@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <random@plt>
movzwl %ax,%edi
call   1060 <usleep@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <random@plt>
movzwl %ax,%edi
call   1060 <usleep@plt>
lea    0xe41(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <pthread_exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Thread %d says: Hello!\0A\00"
@.str.1 = [26 x i8] c"Thread %d says: Goodbye!\0A\00"
define i8* @printHello(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
br label %5
5: ; preds = %14, %1
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 5
br i1 %7, label %8, label %17
8: ; preds = %5
%9 = load i8*, i8** %3
%10 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = call i32 (...) @random()
%12 = and i32 %11, 65535
%13 = call i32 @usleep(i32 %12)
br label %14
14: ; preds = %8
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
br label %5
17: ; preds = %5
%18 = load i8*, i8** %3
%19 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = call i32 @pthread_exit(i32* null)
%21 = load i8*, i8** %2
ret i8* %21
}

LLVM IR (-O2):
@.str = [24 x i8] c"Thread %d says: Hello!\0A\00"
@.str.1 = [26 x i8] c"Thread %d says: Goodbye!\0A\00"
define noalias i8* @printHello(i8* %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = tail call i32 (...) @random()
%4 = and i32 %3, 65535
%5 = tail call i32 @usleep(i32 %4)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = tail call i32 (...) @random()
%8 = and i32 %7, 65535
%9 = tail call i32 @usleep(i32 %8)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
%11 = tail call i32 (...) @random()
%12 = and i32 %11, 65535
%13 = tail call i32 @usleep(i32 %12)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
%15 = tail call i32 (...) @random()
%16 = and i32 %15, 65535
%17 = tail call i32 @usleep(i32 %16)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
%19 = tail call i32 (...) @random()
%20 = and i32 %19, 65535
%21 = tail call i32 @usleep(i32 %20)
%22 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%23 = tail call i32 @pthread_exit(i32* null)
ret i8* undef
}