#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*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
long O_NONBLOCK;
int errno;
int fcntl(int, int /*<<< orphan*/, ...);
__attribute__((warn_unused_result)) int mark_fd_nonblocking(int fd) {
  int flags = fcntl(fd, F_GETFL);
  if (flags < 0)
    return -((errno) | (1 << 30));
  flags = fcntl(fd, F_SETFL, ((long)flags) | O_NONBLOCK);
  if (flags < 0)
    return -((errno) | (1 << 30));
  return 1;
}


x86 assembly (clang, -O0):
<mark_fd_nonblocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1156 <mark_fd_nonblocking+0x46>
mov    0x2e8e(%rip),%rax
mov    (%rax),%ecx
or     $0x40000000,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11a6 <mark_fd_nonblocking+0x96>
mov    -0x8(%rbp),%edi
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
movslq -0xc(%rbp),%rdx
mov    0x2e7b(%rip),%rax
or     (%rax),%rdx
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    119f <mark_fd_nonblocking+0x8f>
mov    0x2e45(%rip),%rax
mov    (%rax),%ecx
or     $0x40000000,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11a6 <mark_fd_nonblocking+0x96>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mark_fd_nonblocking>:
push   %rbx
mov    %edi,%ebx
mov    0x2eae(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %eax,%eax
js     1152 <mark_fd_nonblocking+0x42>
mov    0x2eaa(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edx
mov    0x2eaf(%rip),%rax
or     (%rax),%rdx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    %eax,%ecx
mov    $0x1,%eax
test   %ecx,%ecx
js     1152 <mark_fd_nonblocking+0x42>
pop    %rbx
ret
mov    0x2e77(%rip),%rcx
mov    $0x40000000,%eax
or     (%rcx),%eax
neg    %eax
pop    %rbx
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@errno = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i64 0
define i32 @mark_fd_nonblocking(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = load i32, i32* @F_GETFL
%7 = call i32 (i32, i32, ...) @fcntl(i32 %5, i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32, i32* @errno
%12 = or i32 %11, 1073741824
%13 = sub nsw i32 0, %12
store i32 %13, i32* %2
br label %29
14: ; preds = %1
%15 = load i32, i32* %3
%16 = load i32, i32* @F_SETFL
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = load i64, i64* @O_NONBLOCK
%20 = or i64 %18, %19
%21 = call i32 (i32, i32, ...) @fcntl(i32 %15, i32 %16, i64 %20)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %14
%25 = load i32, i32* @errno
%26 = or i32 %25, 1073741824
%27 = sub nsw i32 0, %26
store i32 %27, i32* %2
br label %29
28: ; preds = %14
store i32 1, i32* %2
br label %29
29: ; preds = %28, %24, %10
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@errno = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i64 0
define i32 @mark_fd_nonblocking(i32 %0) {
%2 = load i32, i32* @F_GETFL
%3 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = load i32, i32* @errno
%7 = or i32 %6, 1073741824
%8 = sub nsw i32 0, %7
br label %20
9: ; preds = %1
%10 = load i32, i32* @F_SETFL
%11 = zext i32 %3 to i64
%12 = load i64, i64* @O_NONBLOCK
%13 = or i64 %12, %11
%14 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %10, i64 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %9
%17 = load i32, i32* @errno
%18 = or i32 %17, 1073741824
%19 = sub nsw i32 0, %18
br label %20
20: ; preds = %9, %16, %5
%21 = phi i32 [ %8, %5 ], [ %19, %16 ], [ 1, %9 ]
ret i32 %21
}