#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 *, char *, int);
int /*<<< orphan*/ pthread_exit(int);
void *thr_fun(void *arg) {
  char *no = (char *)arg;
  int i = 0;
  for (; i < 10; i++) {
    printf("%s thread, i:%d\n", no, i);
    if (i == 5) {
      pthread_exit(2);
    }
  }
}


x86 assembly (clang, -O0):
<thr_fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    117f <thr_fun+0x5f>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xead(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x5,-0x1c(%rbp)
jne    116c <thr_fun+0x4c>
mov    $0x2,%edi
call   1040 <pthread_exit@plt>
jmp    1171 <thr_fun+0x51>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113b <thr_fun+0x1b>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thr_fun>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xed2(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x3,%edx
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x5,%edx
call   1030 <printf@plt>
mov    $0x2,%edi
call   1040 <pthread_exit@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x6,%edx
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x7,%edx
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x9,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"%s thread, i:%d\0A\00"
define i8* @thr_fun(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
store i8* %6, i8** %4
store i32 0, i32* %5
br label %7
7: ; preds = %19, %1
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 10
br i1 %9, label %10, label %22
10: ; preds = %7
%11 = load i8*, i8** %4
%12 = load i32, i32* %5
%13 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %12)
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 5
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @pthread_exit(i32 2)
br label %18
18: ; preds = %16, %10
br label %19
19: ; preds = %18
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %7
22: ; preds = %7
%23 = load i8*, i8** %2
ret i8* %23
}

LLVM IR (-O2):
@.str = [17 x i8] c"%s thread, i:%d\0A\00"
define noalias i8* @thr_fun(i8* %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0, i32 0)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0, i32 1)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0, i32 2)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0, i32 3)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0, i32 4)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0, i32 5)
%8 = tail call i32 @pthread_exit(i32 2)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0, i32 6)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0, i32 7)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0, i32 8)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0, i32 9)
ret i8* undef
}