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


x86 assembly (clang, -O0):
<futex_wakeup_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
mov    0x2e8f(%rip),%rax
mov    (%rax),%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)
jge    119d <futex_wakeup_all+0x6d>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%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_all>:
push   %rax
mov    %rdi,%rsi
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
mov    0x2e7c(%rip),%rax
mov    (%rax),%edx
mov    0x2e9b(%rip),%rax
mov    (%rax),%ecx
movl   $0x0,(%rsp)
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1040 <syscall@plt>
test   %eax,%eax
js     1167 <futex_wakeup_all+0x37>
pop    %rax
ret
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%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
@INT_MAX = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"futex: futex_wakeup_all failed\00"
define void @futex_wakeup_all(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 = load i32, i32* @INT_MAX
%8 = call i32 @syscall(i32 %4, i8* %5, i32 %6, i32 %7, i32* null, i32* null, i32 0)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %1
ret void
}

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