#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 *, int);
int /*<<< orphan*/ usleep(int);
void *work(void *arg) {
  int i = 0;
  for (i = 0; i < 5; i++) {
    printf("Thread %d works\n", (int)arg);
    usleep(10);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<work>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jge    116e <work+0x4e>
mov    -0x8(%rbp),%rax
mov    %eax,%esi
lea    0xeaf(%rip),%rdi
call   1030 <printf@plt>
mov    $0xa,%edi
call   1040 <usleep@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113a <work+0x1a>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<work>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xed2(%rip),%r14
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    $0xa,%edi
call   1040 <usleep@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    $0xa,%edi
call   1040 <usleep@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    $0xa,%edi
call   1040 <usleep@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    $0xa,%edi
call   1040 <usleep@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    $0xa,%edi
call   1040 <usleep@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Thread %d works\0A\00"
define i8* @work(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %3
br label %4
4: ; preds = %12, %1
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 5
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = load i8*, i8** %2
%9 = ptrtoint i8* %8 to i32
%10 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 @usleep(i32 10)
br label %12
12: ; preds = %7
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
br label %4
15: ; preds = %4
ret i8* null
}

LLVM IR (-O2):
@.str = [17 x i8] c"Thread %d works\0A\00"
define noalias i8* @work(i8* %0) {
%2 = ptrtoint i8* %0 to i64
%3 = trunc i64 %2 to i32
%4 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 @usleep(i32 10)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %3)
%7 = tail call i32 @usleep(i32 10)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %3)
%9 = tail call i32 @usleep(i32 10)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %3)
%11 = tail call i32 @usleep(i32 10)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %3)
%13 = tail call i32 @usleep(i32 10)
ret i8* null
}