#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*/ exit(int);
int futex(int *, int /*<<< orphan*/, int, int /*<<< orphan*/ *,
          int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
void wake_futex_blocking(int *futex_addr) {
  while (1) {
    int futex_rc = futex(futex_addr, FUTEX_WAKE, 1, NULL, NULL, 0);
    if (futex_rc == -1) {
      perror("futex wake");
      exit(1);
    } else if (futex_rc > 0) {
      return;
    }
  }
}


x86 assembly (clang, -O0):
<wake_futex_blocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
xor    %eax,%eax
mov    %eax,%r8d
xor    %r9d,%r9d
mov    %r8,%rcx
call   1030 <futex@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1181 <wake_futex_blocking+0x51>
lea    0xe8e(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cmpl   $0x0,-0xc(%rbp)
jle    1191 <wake_futex_blocking+0x61>
add    $0x10,%rsp
pop    %rbp
ret
jmp    1196 <wake_futex_blocking+0x66>
jmp    113c <wake_futex_blocking+0xc>

x86 assembly (clang, -O2):
<wake_futex_blocking>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e9a(%rip),%r14
xchg   %ax,%ax
mov    (%r14),%esi
mov    %rbx,%rdi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <futex@plt>
cmp    $0xffffffff,%eax
je     1169 <wake_futex_blocking+0x39>
test   %eax,%eax
jle    1140 <wake_futex_blocking+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe90(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@FUTEX_WAKE = global i32 0
@.str = [11 x i8] c"futex wake\00"
define void @wake_futex_blocking(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
br label %4
4: ; preds = %1, %18
%5 = load i32*, i32** %2
%6 = load i32, i32* @FUTEX_WAKE
%7 = call i32 @futex(i32* %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, -1
br i1 %9, label %10, label %13
10: ; preds = %4
%11 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %4
%14 = load i32, i32* %3
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %13
ret void
17: ; preds = %13
br label %18
18: ; preds = %17
br label %4
}

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