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

/* Variables and functions */
scalar_t__ EAGAIN;
int O_NONBLOCK;
scalar_t__ errno;
int open(char const *, int, int /*<<< orphan*/);
int /*<<< orphan*/ task_yield();
int sys_open(const char *pathname, int flags, mode_t mode) {
  int ret;
RETRY:
  ret = open(pathname, flags | O_NONBLOCK, mode);
  if (ret == -1 && errno == EAGAIN) {
    task_yield();
    goto RETRY;
  }
  return ret;
}


x86 assembly (clang, -O0):
<sys_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2ea8(%rip),%rax
or     (%rax),%esi
mov    -0x10(%rbp),%edx
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    117d <sys_open+0x5d>
mov    0x2e7a(%rip),%rax
mov    (%rax),%rax
mov    0x2e60(%rip),%rcx
cmp    (%rcx),%rax
jne    117d <sys_open+0x5d>
mov    $0x0,%al
call   1030 <task_yield@plt>
jmp    1132 <sys_open+0x12>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_open>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
mov    0x2eae(%rip),%r15
mov    (%r15),%esi
or     %ebp,%esi
call   1040 <open@plt>
cmp    $0xffffffff,%eax
jne    118d <sys_open+0x6d>
mov    0x2e88(%rip),%r12
mov    0x2e71(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    (%r12),%rax
cmp    0x0(%r13),%rax
jne    1188 <sys_open+0x68>
xor    %eax,%eax
call   1030 <task_yield@plt>
mov    (%r15),%esi
or     %ebp,%esi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1040 <open@plt>
cmp    $0xffffffff,%eax
je     1160 <sys_open+0x40>
jmp    118d <sys_open+0x6d>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_NONBLOCK = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
define i32 @sys_open(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
br label %8
8: ; preds = %21, %3
%9 = load i8*, i8** %4
%10 = load i32, i32* %5
%11 = load i32, i32* @O_NONBLOCK
%12 = or i32 %10, %11
%13 = load i32, i32* %6
%14 = call i32 @open(i8* %9, i32 %12, i32 %13)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %23
17: ; preds = %8
%18 = load i64, i64* @errno
%19 = load i64, i64* @EAGAIN
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 (...) @task_yield()
br label %8
23: ; preds = %17, %8
%24 = load i32, i32* %7
ret i32 %24
}

LLVM IR (-O2):
@O_NONBLOCK = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
define i32 @sys_open(i8* nocapture %0, i32 %1, i32 %2) {
%4 = load i32, i32* @O_NONBLOCK
%5 = or i32 %4, %1
%6 = tail call i32 @open(i8* %0, i32 %5, i32 %2)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %18
8: ; preds = %3, %12
%9 = load i64, i64* @errno
%10 = load i64, i64* @EAGAIN
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %18
12: ; preds = %8
%13 = tail call i32 (...) @task_yield()
%14 = load i32, i32* @O_NONBLOCK
%15 = or i32 %14, %1
%16 = tail call i32 @open(i8* %0, i32 %15, i32 %2)
%17 = icmp eq i32 %16, -1
br i1 %17, label %8, label %18
18: ; preds = %12, %8, %3
%19 = phi i32 [ %6, %3 ], [ -1, %8 ], [ %16, %12 ]
ret i32 %19
}