#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*/ uint32_t;

/* Variables and functions */
int EAGAIN;
int /*<<< orphan*/ printf(char *, char *, int);
int sys_futex(int /*<<< orphan*/ *, int /*<<< orphan*/, int,
              int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
int test_futex(void) {
  uint32_t x = 0;
  int r;
  r = sys_futex(&x, 0, 2, NULL, 0, 0);
  do {
    if (!(r == -EAGAIN)) {
      printf("expression '%s' untrue at %d\n", "r == -EAGAIN", 55);
      return 0;
    }
  } while (0);
  r = sys_futex(&x, 0, 1, NULL, 0, 0);
  do {
    if (!(r == -EAGAIN)) {
      printf("expression '%s' untrue at %d\n", "r == -EAGAIN", 58);
      return 0;
    }
  } while (0);
  return 1;
}


x86 assembly (clang, -O0):
<test_futex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
lea    -0x8(%rbp),%rdi
xor    %r9d,%r9d
mov    $0x2,%edx
xor    %eax,%eax
mov    %eax,%ecx
mov    %r9d,%esi
mov    %r9d,%r8d
call   1040 <sys_futex@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
xor    %ecx,%ecx
mov    0x2e7f(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
je     1187 <test_futex+0x67>
lea    0xe96(%rip),%rdi
lea    0xead(%rip),%rsi
mov    $0x37,%edx
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f0 <test_futex+0xd0>
jmp    118c <test_futex+0x6c>
lea    -0x8(%rbp),%rdi
xor    %r9d,%r9d
mov    $0x1,%edx
xor    %eax,%eax
mov    %eax,%ecx
mov    %r9d,%esi
mov    %r9d,%r8d
call   1040 <sys_futex@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
xor    %ecx,%ecx
mov    0x2e22(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
je     11e4 <test_futex+0xc4>
lea    0xe39(%rip),%rdi
lea    0xe50(%rip),%rsi
mov    $0x3a,%edx
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f0 <test_futex+0xd0>
jmp    11e9 <test_futex+0xc9>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_futex>:
push   %r14
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1040 <sys_futex@plt>
mov    0x2e8c(%rip),%r14
mov    $0x37,%edx
add    (%r14),%eax
jne    117e <test_futex+0x5e>
lea    0x4(%rsp),%rdi
mov    $0x1,%ebx
xor    %esi,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1040 <sys_futex@plt>
mov    $0x3a,%edx
add    (%r14),%eax
je     1193 <test_futex+0x73>
lea    0xe7b(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1030 <printf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EAGAIN = global i32 0
@.str = [30 x i8] c"expression '%s' untrue at %d\0A\00"
@.str.1 = [13 x i8] c"r == -EAGAIN\00"
define i32 @test_futex() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %2
%4 = call i32 @sys_futex(i32* %2, i32 0, i32 2, i32* null, i32 0, i32 0)
store i32 %4, i32* %3
br label %5
5: ; preds = %0
%6 = load i32, i32* %3
%7 = load i32, i32* @EAGAIN
%8 = sub nsw i32 0, %7
%9 = icmp eq i32 %6, %8
br i1 %9, label %12, label %10
10: ; preds = %5
%11 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 55)
store i32 0, i32* %1
br label %24
12: ; preds = %5
br label %13
13: ; preds = %12
%14 = call i32 @sys_futex(i32* %2, i32 0, i32 1, i32* null, i32 0, i32 0)
store i32 %14, i32* %3
br label %15
15: ; preds = %13
%16 = load i32, i32* %3
%17 = load i32, i32* @EAGAIN
%18 = sub nsw i32 0, %17
%19 = icmp eq i32 %16, %18
br i1 %19, label %22, label %20
20: ; preds = %15
%21 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 58)
store i32 0, i32* %1
br label %24
22: ; preds = %15
br label %23
23: ; preds = %22
store i32 1, i32* %1
br label %24
24: ; preds = %23, %20, %10
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@EAGAIN = global i32 0
@.str = [30 x i8] c"expression '%s' untrue at %d\0A\00"
@.str.1 = [13 x i8] c"r == -EAGAIN\00"
define i32 @test_futex() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = call i32 @sys_futex(i32* %1, i32 0, i32 2, i32* null, i32 0, i32 0)
%4 = load i32, i32* @EAGAIN
%5 = sub nsw i32 0, %4
%6 = icmp eq i32 %3, %5
br i1 %6, label %7, label %12
7: ; preds = %0
%8 = call i32 @sys_futex(i32* %1, i32 0, i32 1, i32* null, i32 0, i32 0)
%9 = load i32, i32* @EAGAIN
%10 = sub nsw i32 0, %9
%11 = icmp eq i32 %8, %10
br i1 %11, label %15, label %12
12: ; preds = %7, %0
%13 = phi i32 [ 55, %0 ], [ 58, %7 ]
%14 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %12, %7
%16 = phi i32 [ 1, %7 ], [ 0, %12 ]
ret i32 %16
}