#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 getYAKThreadid();
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ sleep(int);
void testthread_2() {
  int i;
  for (i = 0; i < 2; i++) {
    printf("Hello from Other thread[type 2] %d, now i = %d \n",
           getYAKThreadid(), i);
    sleep(1);
  }
  printf("Thread %d exitting\n", getYAKThreadid());
}


x86 assembly (clang, -O0):
<testthread_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0x2,-0x4(%rbp)
jge    117b <testthread_2+0x4b>
mov    $0x0,%al
call   1040 <getYAKThreadid@plt>
mov    %eax,%esi
mov    -0x4(%rbp),%edx
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    113f <testthread_2+0xf>
mov    $0x0,%al
call   1040 <getYAKThreadid@plt>
mov    %eax,%esi
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testthread_2>:
push   %rbx
xor    %eax,%eax
call   1040 <getYAKThreadid@plt>
lea    0xec1(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %eax,%eax
call   1040 <getYAKThreadid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %eax,%eax
call   1040 <getYAKThreadid@plt>
lea    0xeaa(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [49 x i8] c"Hello from Other thread[type 2] %d, now i = %d \0A\00"
@.str.1 = [20 x i8] c"Thread %d exitting\0A\00"
define void @testthread_2() {
%1 = alloca i32
store i32 0, i32* %1
br label %2
2: ; preds = %10, %0
%3 = load i32, i32* %1
%4 = icmp slt i32 %3, 2
br i1 %4, label %5, label %13
5: ; preds = %2
%6 = call i32 (...) @getYAKThreadid()
%7 = load i32, i32* %1
%8 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %7)
%9 = call i32 @sleep(i32 1)
br label %10
10: ; preds = %5
%11 = load i32, i32* %1
%12 = add nsw i32 %11, 1
store i32 %12, i32* %1
br label %2
13: ; preds = %2
%14 = call i32 (...) @getYAKThreadid()
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %14)
ret void
}

LLVM IR (-O2):
@.str = [49 x i8] c"Hello from Other thread[type 2] %d, now i = %d \0A\00"
@.str.1 = [20 x i8] c"Thread %d exitting\0A\00"
define void @testthread_2() {
%1 = tail call i32 (...) @getYAKThreadid()
%2 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %1, i32 0)
%3 = tail call i32 @sleep(i32 1)
%4 = tail call i32 (...) @getYAKThreadid()
%5 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %4, i32 1)
%6 = tail call i32 @sleep(i32 1)
%7 = tail call i32 (...) @getYAKThreadid()
%8 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %7)
ret void
}