#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 /*<<< orphan*/, int);
int /*<<< orphan*/ pthread_self();
int /*<<< orphan*/ spin_lock();
int /*<<< orphan*/ spin_unlock();
void *thread_func1(void *arg) {
  int i = 0;
  spin_lock();
  for (; i < 10; i++) {
    printf("thread%p = %d\n", pthread_self(), i);
  }
  spin_unlock();
  return NULL;
}


x86 assembly (clang, -O0):
<thread_func1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1040 <spin_lock@plt>
cmpl   $0xa,-0xc(%rbp)
jge    118a <thread_func1+0x4a>
mov    $0x0,%al
call   1060 <pthread_self@plt>
mov    %eax,%esi
mov    -0xc(%rbp),%edx
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115a <thread_func1+0x1a>
mov    $0x0,%al
call   1050 <spin_unlock@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_func1>:
push   %rbx
xor    %eax,%eax
call   1040 <spin_lock@plt>
xor    %eax,%eax
call   1060 <pthread_self@plt>
lea    0xeaa(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %edx,%edx
call   1030 <printf@plt>
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   1030 <printf@plt>
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x2,%edx
call   1030 <printf@plt>
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x3,%edx
call   1030 <printf@plt>
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x4,%edx
call   1030 <printf@plt>
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x5,%edx
call   1030 <printf@plt>
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x6,%edx
call   1030 <printf@plt>
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x7,%edx
call   1030 <printf@plt>
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x8,%edx
call   1030 <printf@plt>
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x9,%edx
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <spin_unlock@plt>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [15 x i8] c"thread%p = %d\0A\00"
define noalias i8* @thread_func1(i8* nocapture readnone %0) {
%2 = tail call i32 (...) @spin_lock()
%3 = tail call i32 (...) @pthread_self()
%4 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %3, i32 0)
%5 = tail call i32 (...) @pthread_self()
%6 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %5, i32 1)
%7 = tail call i32 (...) @pthread_self()
%8 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %7, i32 2)
%9 = tail call i32 (...) @pthread_self()
%10 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %9, i32 3)
%11 = tail call i32 (...) @pthread_self()
%12 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %11, i32 4)
%13 = tail call i32 (...) @pthread_self()
%14 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %13, i32 5)
%15 = tail call i32 (...) @pthread_self()
%16 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %15, i32 6)
%17 = tail call i32 (...) @pthread_self()
%18 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %17, i32 7)
%19 = tail call i32 (...) @pthread_self()
%20 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %19, i32 8)
%21 = tail call i32 (...) @pthread_self()
%22 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %21, i32 9)
%23 = tail call i32 (...) @spin_unlock()
ret i8* null
}