#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 */
typedef int /*<<< orphan*/ OSSL_ASYNC_FD;
typedef int /*<<< orphan*/ ASYNC_WAIT_CTX;
typedef int /*<<< orphan*/ ASYNC_JOB;

/* Variables and functions */
int /*<<< orphan*/ ASYNC_WAIT_CTX_clear_fd(int /*<<< orphan*/ *,
                                           int /*<<< orphan*/ *);
int /*<<< orphan*/ ASYNC_WAIT_CTX_set_wait_fd(int /*<<< orphan*/ *,
                                              int /*<<< orphan*/ *,
                                              int /*<<< orphan*/,
                                              int /*<<< orphan*/ *,
                                              int /*<<< orphan*/ *);
int /*<<< orphan*/ *ASYNC_get_current_job();
int /*<<< orphan*/ *ASYNC_get_wait_ctx(int /*<<< orphan*/ *);
int /*<<< orphan*/ ASYNC_pause_job();
int waitfd(void *args) {
  ASYNC_JOB *job;
  ASYNC_WAIT_CTX *waitctx;
  job = ASYNC_get_current_job();
  if (job == NULL)
    return 0;
  waitctx = ASYNC_get_wait_ctx(job);
  if (waitctx == NULL)
    return 0;
  ASYNC_pause_job();
  if (!ASYNC_WAIT_CTX_set_wait_fd(waitctx, waitctx, ((OSSL_ASYNC_FD)99), NULL,
                                  NULL))
    return 0;
  ASYNC_pause_job();
  if (!ASYNC_WAIT_CTX_clear_fd(waitctx, waitctx))
    return 0;
  ASYNC_pause_job();
  if (!ASYNC_WAIT_CTX_set_wait_fd(waitctx, waitctx, ((OSSL_ASYNC_FD)99), NULL,
                                  NULL))
    return 0;
  if (!ASYNC_WAIT_CTX_clear_fd(waitctx, waitctx))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<waitfd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <ASYNC_get_current_job@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117e <waitfd+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    1260 <waitfd+0x110>
mov    -0x18(%rbp),%rdi
call   1040 <ASYNC_get_wait_ctx@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a2 <waitfd+0x52>
movl   $0x0,-0x4(%rbp)
jmp    1260 <waitfd+0x110>
mov    $0x0,%al
call   1060 <ASYNC_pause_job@plt>
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x63,%edx
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rcx
call   1050 <ASYNC_WAIT_CTX_set_wait_fd@plt>
cmp    $0x0,%eax
jne    11d8 <waitfd+0x88>
movl   $0x0,-0x4(%rbp)
jmp    1260 <waitfd+0x110>
mov    $0x0,%al
call   1060 <ASYNC_pause_job@plt>
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <ASYNC_WAIT_CTX_clear_fd@plt>
cmp    $0x0,%eax
jne    1201 <waitfd+0xb1>
movl   $0x0,-0x4(%rbp)
jmp    1260 <waitfd+0x110>
mov    $0x0,%al
call   1060 <ASYNC_pause_job@plt>
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x63,%edx
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rcx
call   1050 <ASYNC_WAIT_CTX_set_wait_fd@plt>
cmp    $0x0,%eax
jne    1237 <waitfd+0xe7>
movl   $0x0,-0x4(%rbp)
jmp    1260 <waitfd+0x110>
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <ASYNC_WAIT_CTX_clear_fd@plt>
cmp    $0x0,%eax
jne    1259 <waitfd+0x109>
movl   $0x0,-0x4(%rbp)
jmp    1260 <waitfd+0x110>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waitfd>:
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <ASYNC_get_current_job@plt>
test   %rax,%rax
je     11ea <waitfd+0x9a>
mov    %rax,%rdi
call   1040 <ASYNC_get_wait_ctx@plt>
test   %rax,%rax
je     11ea <waitfd+0x9a>
mov    %rax,%rbx
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <ASYNC_pause_job@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <ASYNC_WAIT_CTX_set_wait_fd@plt>
test   %eax,%eax
je     11ea <waitfd+0x9a>
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <ASYNC_pause_job@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1030 <ASYNC_WAIT_CTX_clear_fd@plt>
test   %eax,%eax
je     11ea <waitfd+0x9a>
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <ASYNC_pause_job@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <ASYNC_WAIT_CTX_set_wait_fd@plt>
test   %eax,%eax
je     11ea <waitfd+0x9a>
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1030 <ASYNC_WAIT_CTX_clear_fd@plt>
xor    %r14d,%r14d
test   %eax,%eax
setne  %r14b
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @waitfd(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
store i8* %0, i8** %3
%6 = call i32* (...) @ASYNC_get_current_job()
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %44
10: ; preds = %1
%11 = load i32*, i32** %4
%12 = call i32* @ASYNC_get_wait_ctx(i32* %11)
store i32* %12, i32** %5
%13 = load i32*, i32** %5
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %10
store i32 0, i32* %2
br label %44
16: ; preds = %10
%17 = call i32 (...) @ASYNC_pause_job()
%18 = load i32*, i32** %5
%19 = load i32*, i32** %5
%20 = call i32 @ASYNC_WAIT_CTX_set_wait_fd(i32* %18, i32* %19, i32 99, i32* null, i32* null)
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %16
store i32 0, i32* %2
br label %44
23: ; preds = %16
%24 = call i32 (...) @ASYNC_pause_job()
%25 = load i32*, i32** %5
%26 = load i32*, i32** %5
%27 = call i32 @ASYNC_WAIT_CTX_clear_fd(i32* %25, i32* %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %23
store i32 0, i32* %2
br label %44
30: ; preds = %23
%31 = call i32 (...) @ASYNC_pause_job()
%32 = load i32*, i32** %5
%33 = load i32*, i32** %5
%34 = call i32 @ASYNC_WAIT_CTX_set_wait_fd(i32* %32, i32* %33, i32 99, i32* null, i32* null)
%35 = icmp ne i32 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %30
store i32 0, i32* %2
br label %44
37: ; preds = %30
%38 = load i32*, i32** %5
%39 = load i32*, i32** %5
%40 = call i32 @ASYNC_WAIT_CTX_clear_fd(i32* %38, i32* %39)
%41 = icmp ne i32 %40, 0
br i1 %41, label %43, label %42
42: ; preds = %37
store i32 0, i32* %2
br label %44
43: ; preds = %37
store i32 1, i32* %2
br label %44
44: ; preds = %43, %42, %36, %29, %22, %15, %9
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
define i32 @waitfd(i8* nocapture readnone %0) {
%2 = tail call i32* (...) @ASYNC_get_current_job()
%3 = icmp eq i32* %2, null
br i1 %3, label %23, label %4
4: ; preds = %1
%5 = tail call i32* @ASYNC_get_wait_ctx(i32* %2)
%6 = icmp eq i32* %5, null
br i1 %6, label %23, label %7
7: ; preds = %4
%8 = tail call i32 (...) @ASYNC_pause_job()
%9 = tail call i32 @ASYNC_WAIT_CTX_set_wait_fd(i32* %5, i32* %5, i32 99, i32* null, i32* null)
%10 = icmp eq i32 %9, 0
br i1 %10, label %23, label %11
11: ; preds = %7
%12 = tail call i32 (...) @ASYNC_pause_job()
%13 = tail call i32 @ASYNC_WAIT_CTX_clear_fd(i32* %5, i32* %5)
%14 = icmp eq i32 %13, 0
br i1 %14, label %23, label %15
15: ; preds = %11
%16 = tail call i32 (...) @ASYNC_pause_job()
%17 = tail call i32 @ASYNC_WAIT_CTX_set_wait_fd(i32* %5, i32* %5, i32 99, i32* null, i32* null)
%18 = icmp eq i32 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = tail call i32 @ASYNC_WAIT_CTX_clear_fd(i32* %5, i32* %5)
%21 = icmp ne i32 %20, 0
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %19, %15, %11, %7, %4, %1
%24 = phi i32 [ 0, %1 ], [ 0, %4 ], [ 0, %7 ], [ 0, %11 ], [ 0, %15 ], [ %22, %19 ]
ret i32 %24
}