#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);
int /*<<< orphan*/ sleep(int);
void *threadfunc(void *c) {
  int id = (int)c;
  int i = 0;
  for (i = 0; i < 12; ++i) {
    printf("thread %d, iteration %d\n", id, i);
    sleep(1000);
  }
  return 0;
}


x86 assembly (clang, -O0):
<threadfunc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0xc,-0x10(%rbp)
jge    1175 <threadfunc+0x55>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xea8(%rip),%rdi
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <sleep@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1141 <threadfunc+0x21>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<threadfunc>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xed2(%rip),%r14
mov    %r14,%rdi
mov    %ebx,%esi
xor    %edx,%edx
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <sleep@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <sleep@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x2,%edx
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <sleep@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x3,%edx
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <sleep@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x4,%edx
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <sleep@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x5,%edx
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <sleep@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x6,%edx
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <sleep@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x7,%edx
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <sleep@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x8,%edx
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <sleep@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x9,%edx
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <sleep@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0xa,%edx
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <sleep@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0xb,%edx
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <sleep@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [25 x i8] c"thread %d, iteration %d\0A\00"
define noalias i8* @threadfunc(i8* %0) {
%2 = ptrtoint i8* %0 to i64
%3 = trunc i64 %2 to i32
%4 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %3, i32 0)
%5 = tail call i32 @sleep(i32 1000)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %3, i32 1)
%7 = tail call i32 @sleep(i32 1000)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %3, i32 2)
%9 = tail call i32 @sleep(i32 1000)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %3, i32 3)
%11 = tail call i32 @sleep(i32 1000)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %3, i32 4)
%13 = tail call i32 @sleep(i32 1000)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %3, i32 5)
%15 = tail call i32 @sleep(i32 1000)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %3, i32 6)
%17 = tail call i32 @sleep(i32 1000)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %3, i32 7)
%19 = tail call i32 @sleep(i32 1000)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %3, i32 8)
%21 = tail call i32 @sleep(i32 1000)
%22 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %3, i32 9)
%23 = tail call i32 @sleep(i32 1000)
%24 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %3, i32 10)
%25 = tail call i32 @sleep(i32 1000)
%26 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %3, i32 11)
%27 = tail call i32 @sleep(i32 1000)
ret i8* null
}