#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 */
struct timespec {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ FUTEX_BITSET_MATCH_ANY;
int FUTEX_CLOCK_REALTIME;
int FUTEX_WAIT_BITSET;
int FUTEX_WAIT_BITSET_PRIVATE;
int __futex(void volatile *, int, int, struct timespec const *,
            int /*<<< orphan*/);
int __futex_wait_ex(volatile void *ftx, bool shared, int value,
                    bool use_realtime_clock,
                    const struct timespec *abs_timeout) {
  return __futex(ftx,
                 (shared ? FUTEX_WAIT_BITSET : FUTEX_WAIT_BITSET_PRIVATE) |
                     (use_realtime_clock ? FUTEX_CLOCK_REALTIME : 0),
                 value, abs_timeout, FUTEX_BITSET_MATCH_ANY);
}


x86 assembly (clang, -O0):
<__futex_wait_ex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     114c <__futex_wait_ex+0x3c>
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    1158 <__futex_wait_ex+0x48>
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1179 <__futex_wait_ex+0x69>
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    1183 <__futex_wait_ex+0x73>
xor    %eax,%eax
mov    %eax,-0x34(%rbp)
jmp    1183 <__futex_wait_ex+0x73>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%eax
or     %eax,%esi
mov    -0x10(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    0x2e3b(%rip),%rax
mov    (%rax),%r8d
call   1030 <__futex@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__futex_wait_ex>:
mov    %r8,%rax
test   %esi,%esi
jne    1124 <__futex_wait_ex+0x14>
mov    0x2eca(%rip),%rsi
test   %ecx,%ecx
jne    112f <__futex_wait_ex+0x1f>
jmp    1138 <__futex_wait_ex+0x28>
mov    0x2e9d(%rip),%rsi
test   %ecx,%ecx
je     1138 <__futex_wait_ex+0x28>
mov    0x2eaa(%rip),%rcx
mov    (%rcx),%ecx
or     (%rsi),%ecx
mov    0x2e97(%rip),%rsi
mov    (%rsi),%r8d
mov    %ecx,%esi
mov    %rax,%rcx
jmp    1030 <__futex@plt>

LLVM IR (-O0):
%struct.timespec = type { i32 }
@FUTEX_WAIT_BITSET = global i32 0
@FUTEX_WAIT_BITSET_PRIVATE = global i32 0
@FUTEX_CLOCK_REALTIME = global i32 0
@FUTEX_BITSET_MATCH_ANY = global i32 0
define i32 @__futex_wait_ex(i8* %0, i32 %1, i32 %2, i32 %3, %struct.timespec* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.timespec*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store %struct.timespec* %4, %struct.timespec** %10
%11 = load i8*, i8** %6
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %5
%15 = load i32, i32* @FUTEX_WAIT_BITSET
br label %18
16: ; preds = %5
%17 = load i32, i32* @FUTEX_WAIT_BITSET_PRIVATE
br label %18
18: ; preds = %16, %14
%19 = phi i32 [ %15, %14 ], [ %17, %16 ]
%20 = load i32, i32* %9
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = load i32, i32* @FUTEX_CLOCK_REALTIME
br label %25
24: ; preds = %18
br label %25
25: ; preds = %24, %22
%26 = phi i32 [ %23, %22 ], [ 0, %24 ]
%27 = or i32 %19, %26
%28 = load i32, i32* %8
%29 = load %struct.timespec*, %struct.timespec** %10
%30 = load i32, i32* @FUTEX_BITSET_MATCH_ANY
%31 = call i32 @__futex(i8* %11, i32 %27, i32 %28, %struct.timespec* %29, i32 %30)
ret i32 %31
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@FUTEX_WAIT_BITSET = global i32 0
@FUTEX_WAIT_BITSET_PRIVATE = global i32 0
@FUTEX_CLOCK_REALTIME = global i32 0
@FUTEX_BITSET_MATCH_ANY = global i32 0
define i32 @__futex_wait_ex(i8* %0, i32 %1, i32 %2, i32 %3, %struct.timespec* %4) {
%6 = icmp eq i32 %1, 0
%7 = load i32, i32* @FUTEX_WAIT_BITSET
%8 = load i32, i32* @FUTEX_WAIT_BITSET_PRIVATE
%9 = select i1 %6, i32 %8, i32 %7
%10 = icmp eq i32 %3, 0
%11 = load i32, i32* @FUTEX_CLOCK_REALTIME
%12 = select i1 %10, i32 0, i32 %11
%13 = or i32 %12, %9
%14 = load i32, i32* @FUTEX_BITSET_MATCH_ANY
%15 = tail call i32 @__futex(i8* %0, i32 %13, i32 %2, %struct.timespec* %4, i32 %14)
ret i32 %15
}