#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*/ sleep(int);
void *work(void *arg) {
  int j;
  for (j = 0; j < 10; ++j) {
    sleep(2);
    *((int *)arg + j) = j + 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<work>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    1156 <work+0x46>
mov    $0x2,%edi
call   1030 <sleep@plt>
mov    -0xc(%rbp),%edx
add    $0x1,%edx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <work+0x13>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<work>:
push   %rbx
mov    %rdi,%rbx
mov    $0x2,%edi
call   1030 <sleep@plt>
movl   $0x1,(%rbx)
mov    $0x2,%edi
call   1030 <sleep@plt>
movl   $0x2,0x4(%rbx)
mov    $0x2,%edi
call   1030 <sleep@plt>
movl   $0x3,0x8(%rbx)
mov    $0x2,%edi
call   1030 <sleep@plt>
movl   $0x4,0xc(%rbx)
mov    $0x2,%edi
call   1030 <sleep@plt>
movl   $0x5,0x10(%rbx)
mov    $0x2,%edi
call   1030 <sleep@plt>
movl   $0x6,0x14(%rbx)
mov    $0x2,%edi
call   1030 <sleep@plt>
movl   $0x7,0x18(%rbx)
mov    $0x2,%edi
call   1030 <sleep@plt>
movl   $0x8,0x1c(%rbx)
mov    $0x2,%edi
call   1030 <sleep@plt>
movl   $0x9,0x20(%rbx)
mov    $0x2,%edi
call   1030 <sleep@plt>
movl   $0xa,0x24(%rbx)
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @work(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
br label %4
4: ; preds = %16, %1
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 10
br i1 %6, label %7, label %19
7: ; preds = %4
%8 = call i32 @sleep(i32 2)
%9 = load i32, i32* %3
%10 = add nsw i32 %9, 1
%11 = load i8*, i8** %2
%12 = bitcast i8* %11 to i32*
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %12, i64 %14
store i32 %10, i32* %15
br label %16
16: ; preds = %7
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %4
19: ; preds = %4
ret i8* null
}

LLVM IR (-O2):
define noalias i8* @work(i8* nocapture writeonly %0) {
%2 = bitcast i8* %0 to i32*
%3 = tail call i32 @sleep(i32 2)
store i32 1, i32* %2
%4 = tail call i32 @sleep(i32 2)
%5 = getelementptr inbounds i8, i8* %0, i64 4
%6 = bitcast i8* %5 to i32*
store i32 2, i32* %6
%7 = tail call i32 @sleep(i32 2)
%8 = getelementptr inbounds i8, i8* %0, i64 8
%9 = bitcast i8* %8 to i32*
store i32 3, i32* %9
%10 = tail call i32 @sleep(i32 2)
%11 = getelementptr inbounds i8, i8* %0, i64 12
%12 = bitcast i8* %11 to i32*
store i32 4, i32* %12
%13 = tail call i32 @sleep(i32 2)
%14 = getelementptr inbounds i8, i8* %0, i64 16
%15 = bitcast i8* %14 to i32*
store i32 5, i32* %15
%16 = tail call i32 @sleep(i32 2)
%17 = getelementptr inbounds i8, i8* %0, i64 20
%18 = bitcast i8* %17 to i32*
store i32 6, i32* %18
%19 = tail call i32 @sleep(i32 2)
%20 = getelementptr inbounds i8, i8* %0, i64 24
%21 = bitcast i8* %20 to i32*
store i32 7, i32* %21
%22 = tail call i32 @sleep(i32 2)
%23 = getelementptr inbounds i8, i8* %0, i64 28
%24 = bitcast i8* %23 to i32*
store i32 8, i32* %24
%25 = tail call i32 @sleep(i32 2)
%26 = getelementptr inbounds i8, i8* %0, i64 32
%27 = bitcast i8* %26 to i32*
store i32 9, i32* %27
%28 = tail call i32 @sleep(i32 2)
%29 = getelementptr inbounds i8, i8* %0, i64 36
%30 = bitcast i8* %29 to i32*
store i32 10, i32* %30
ret i8* null
}