#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*/ event_wait(int /*<<< orphan*/, int, int, int *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ pthread_detach(int /*<<< orphan*/);
int /*<<< orphan*/ pthread_self();
void *test_body() {
  int want = 6;
  int timeout = 2 * 1000 * 1000;
  int events;
  pthread_detach(pthread_self());
  event_wait(0, want, timeout, &events);
  if (events) {
    printf("have events:%d\n", events);
  } else {
    printf("no events:%d\n", events);
  }
}


x86 assembly (clang, -O0):
<test_body>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x6,-0xc(%rbp)
movl   $0x1e8480,-0x10(%rbp)
mov    $0x0,%al
call   1060 <pthread_self@plt>
mov    %eax,%edi
call   1050 <pthread_detach@plt>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
xor    %edi,%edi
lea    -0x14(%rbp),%rcx
call   1040 <event_wait@plt>
cmpl   $0x0,-0x14(%rbp)
je     1193 <test_body+0x53>
mov    -0x14(%rbp),%esi
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
jmp    11a2 <test_body+0x62>
mov    -0x14(%rbp),%esi
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_body>:
push   %rax
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %eax,%edi
call   1050 <pthread_detach@plt>
lea    0x4(%rsp),%rcx
xor    %edi,%edi
mov    $0x6,%esi
mov    $0x1e8480,%edx
call   1040 <event_wait@plt>
mov    0x4(%rsp),%esi
test   %esi,%esi
je     1176 <test_body+0x36>
lea    0xe8c(%rip),%rdi
jmp    117f <test_body+0x3f>
lea    0xe93(%rip),%rdi
xor    %esi,%esi
call   1030 <printf@plt>
pop    %rcx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"have events:%d\0A\00"
@.str.1 = [14 x i8] c"no events:%d\0A\00"
define i8* @test_body() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 6, i32* %2
store i32 2000000, i32* %3
%5 = call i32 (...) @pthread_self()
%6 = call i32 @pthread_detach(i32 %5)
%7 = load i32, i32* %2
%8 = load i32, i32* %3
%9 = call i32 @event_wait(i32 0, i32 %7, i32 %8, i32* %4)
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = load i32, i32* %4
%14 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %18
15: ; preds = %0
%16 = load i32, i32* %4
%17 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %15, %12
%19 = load i8*, i8** %1
ret i8* %19
}

LLVM IR (-O2):
@.str = [16 x i8] c"have events:%d\0A\00"
@.str.1 = [14 x i8] c"no events:%d\0A\00"
define noalias i8* @test_body() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @pthread_self()
%4 = tail call i32 @pthread_detach(i32 %3)
%5 = call i32 @event_wait(i32 0, i32 6, i32 2000000, i32* %1)
%6 = load i32, i32* %1
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %12
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 0)
br label %12
12: ; preds = %10, %8
ret i8* undef
}