#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ pe_active(int);
int /*<<< orphan*/ pe_exit(int);
int /*<<< orphan*/ pe_idle(int);
int pe_init();
int /*<<< orphan*/ pthread_exit(void *);
int /*<<< orphan*/ stderr;
void *pe_thread(void *param) {
  int pe;
  if ((pe = pe_init()) < 0) {
    fprintf(stderr, "Thread failed to initialize PE!\n");
    pthread_exit((void *)~0UL);
  }
  pe_active(pe);
  pe_idle(pe);
  pe_exit(pe);
  return NULL;
}


x86 assembly (clang, -O0):
<pe_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1060 <pe_init@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11a0 <pe_thread+0x40>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffffffffffff,%rdi
call   1050 <pthread_exit@plt>
mov    -0xc(%rbp),%edi
call   1070 <pe_active@plt>
mov    -0xc(%rbp),%edi
call   1030 <pe_idle@plt>
mov    -0xc(%rbp),%edi
call   1080 <pe_exit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pe_thread>:
push   %rbx
xor    %eax,%eax
call   1060 <pe_init@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    118f <pe_thread+0x2f>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffffffffffff,%rdi
call   1050 <pthread_exit@plt>
mov    %ebx,%edi
call   1070 <pe_active@plt>
mov    %ebx,%edi
call   1030 <pe_idle@plt>
mov    %ebx,%edi
call   1080 <pe_exit@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"Thread failed to initialize PE!\0A\00"
define i8* @pe_thread(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = call i32 (...) @pe_init()
store i32 %4, i32* %3
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %10
10: ; preds = %6, %1
%11 = load i32, i32* %3
%12 = call i32 @pe_active(i32 %11)
%13 = load i32, i32* %3
%14 = call i32 @pe_idle(i32 %13)
%15 = load i32, i32* %3
%16 = call i32 @pe_exit(i32 %15)
ret i8* null
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"Thread failed to initialize PE!\0A\00"
define noalias i8* @pe_thread(i8* nocapture readnone %0) {
%2 = tail call i32 (...) @pe_init()
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %8
8: ; preds = %4, %1
%9 = tail call i32 @pe_active(i32 %2)
%10 = tail call i32 @pe_idle(i32 %2)
%11 = tail call i32 @pe_exit(i32 %2)
ret i8* null
}