#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*/ FUTEX_WAKE;
int /*<<< orphan*/ SYS_futex;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int syscall(int /*<<< orphan*/, void *, int /*<<< orphan*/, int,
            int /*<<< orphan*/ *, int /*<<< orphan*/ *, int /*<<< orphan*/);
void futex_wakeup_one(void *futex) {
  int r = syscall(SYS_futex, futex, FUTEX_WAKE, 1, NULL, NULL, 0);
  if (!(r == 0 || r == 1)) {
    fprintf(stderr, "futex: futex_wakeup_one failed");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<futex_wakeup_one>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
mov    0x2e78(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%ecx
xor    %eax,%eax
mov    %eax,%r9d
xor    %eax,%eax
mov    %r9,%r8
movl   $0x0,(%rsp)
call   1040 <syscall@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11a3 <futex_wakeup_one+0x73>
cmpl   $0x1,-0xc(%rbp)
je     11a3 <futex_wakeup_one+0x73>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<futex_wakeup_one>:
push   %rax
mov    %rdi,%rsi
mov    0x2e9d(%rip),%rax
mov    (%rax),%edi
mov    0x2e84(%rip),%rax
mov    (%rax),%edx
movl   $0x0,(%rsp)
mov    $0x1,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1040 <syscall@plt>
cmp    $0x2,%eax
jae    1164 <futex_wakeup_one+0x34>
pop    %rax
ret
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
lea    0xe8c(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@SYS_futex = global i32 0
@FUTEX_WAKE = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"futex: futex_wakeup_one failed\00"
define void @futex_wakeup_one(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i32, i32* @SYS_futex
%5 = load i8*, i8** %2
%6 = load i32, i32* @FUTEX_WAKE
%7 = call i32 @syscall(i32 %4, i8* %5, i32 %6, i32 1, i32* null, i32* null, i32 0)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %1
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 1
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %10, %1
ret void
}

LLVM IR (-O2):
@SYS_futex = global i32 0
@FUTEX_WAKE = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"futex: futex_wakeup_one failed\00"
define void @futex_wakeup_one(i8* %0) {
%2 = load i32, i32* @SYS_futex
%3 = load i32, i32* @FUTEX_WAKE
%4 = tail call i32 @syscall(i32 %2, i8* %0, i32 %3, i32 1, i32* null, i32* null, i32 0)
%5 = icmp ult i32 %4, 2
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %1
ret void
}