#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*/ closeYAUThread();
int getYAUThreadid();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sleep(int);
void testthread() {
  int i;
  for (i = getYAUThreadid(); i > -4; i--) {
    printf("Hello from thread %d \n", getYAUThreadid());
    sleep(1);
  }
  printf("Goodbye from thread %d\n", getYAUThreadid());
  closeYAUThread();
}


x86 assembly (clang, -O0):
<testthread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <getYAUThreadid@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xfffffffc,-0x4(%rbp)
jle    1189 <testthread+0x49>
mov    $0x0,%al
call   1030 <getYAUThreadid@plt>
mov    %eax,%esi
lea    0xe94(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    1152 <testthread+0x12>
mov    $0x0,%al
call   1030 <getYAUThreadid@plt>
mov    %eax,%esi
lea    0xe7e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <closeYAUThread@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testthread>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <getYAUThreadid@plt>
cmp    $0xfffffffd,%eax
jl     1183 <testthread+0x43>
mov    %eax,%ebx
add    $0x1,%ebx
lea    0xea4(%rip),%r14
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <getYAUThreadid@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
add    $0xffffffff,%ebx
cmp    $0xfffffffd,%ebx
jg     1160 <testthread+0x20>
xor    %eax,%eax
call   1030 <getYAUThreadid@plt>
lea    0xe86(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <closeYAUThread@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"Hello from thread %d \0A\00"
@.str.1 = [24 x i8] c"Goodbye from thread %d\0A\00"
define void @testthread() {
%1 = alloca i32
%2 = call i32 (...) @getYAUThreadid()
store i32 %2, i32* %1
br label %3
3: ; preds = %10, %0
%4 = load i32, i32* %1
%5 = icmp sgt i32 %4, -4
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = call i32 (...) @getYAUThreadid()
%8 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = call i32 @sleep(i32 1)
br label %10
10: ; preds = %6
%11 = load i32, i32* %1
%12 = add nsw i32 %11, -1
store i32 %12, i32* %1
br label %3
13: ; preds = %3
%14 = call i32 (...) @getYAUThreadid()
%15 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = call i32 (...) @closeYAUThread()
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"Hello from thread %d \0A\00"
@.str.1 = [24 x i8] c"Goodbye from thread %d\0A\00"
define void @testthread() {
%1 = tail call i32 (...) @getYAUThreadid()
%2 = icmp sgt i32 %1, -4
br i1 %2, label %3, label %10
3: ; preds = %0, %3
%4 = phi i32 [ %8, %3 ], [ %1, %0 ]
%5 = tail call i32 (...) @getYAUThreadid()
%6 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = tail call i32 @sleep(i32 1)
%8 = add nsw i32 %4, -1
%9 = icmp sgt i32 %4, -3
br i1 %9, label %3, label %10
10: ; preds = %3, %0
%11 = tail call i32 (...) @getYAUThreadid()
%12 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = tail call i32 (...) @closeYAUThread()
ret void
}