#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;
int O_NONBLOCK;
int fcntl(int, int /*<<< orphan*/, int);
int set_nonblock(int fd, int *old_flags) {
  *old_flags = fcntl(fd, F_GETFL, 0);
  if ((*old_flags) & O_NONBLOCK) {
    return 0;
  } else {
    fcntl(fd, F_SETFL, *old_flags | O_NONBLOCK);
    return 1;
  }
}


x86 assembly (clang, -O0):
<set_nonblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    0x2ea1(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     115e <set_nonblock+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    1185 <set_nonblock+0x75>
mov    -0x8(%rbp),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
mov    0x2e71(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_nonblock>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r14d
mov    0x2eaf(%rip),%rax
mov    (%rax),%esi
xor    %ebp,%ebp
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,(%rbx)
mov    0x2eb3(%rip),%rcx
mov    (%rcx),%edx
test   %eax,%edx
jne    1153 <set_nonblock+0x43>
mov    0x2e96(%rip),%rcx
mov    (%rcx),%esi
or     %eax,%edx
mov    %r14d,%edi
call   1030 <fcntl@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define i32 @set_nonblock(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
store i32 %0, i32* %4
store i32* %1, i32** %5
%6 = load i32, i32* %4
%7 = load i32, i32* @F_GETFL
%8 = call i32 @fcntl(i32 %6, i32 %7, i32 0)
%9 = load i32*, i32** %5
store i32 %8, i32* %9
%10 = load i32*, i32** %5
%11 = load i32, i32* %10
%12 = load i32, i32* @O_NONBLOCK
%13 = and i32 %11, %12
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 0, i32* %3
br label %24
16: ; preds = %2
%17 = load i32, i32* %4
%18 = load i32, i32* @F_SETFL
%19 = load i32*, i32** %5
%20 = load i32, i32* %19
%21 = load i32, i32* @O_NONBLOCK
%22 = or i32 %20, %21
%23 = call i32 @fcntl(i32 %17, i32 %18, i32 %22)
store i32 1, i32* %3
br label %24
24: ; preds = %16, %15
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define i32 @set_nonblock(i32 %0, i32* nocapture writeonly %1) {
%3 = load i32, i32* @F_GETFL
%4 = tail call i32 @fcntl(i32 %0, i32 %3, i32 0)
store i32 %4, i32* %1
%5 = load i32, i32* @O_NONBLOCK
%6 = and i32 %5, %4
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @F_SETFL
%10 = or i32 %5, %4
%11 = tail call i32 @fcntl(i32 %0, i32 %9, i32 %10)
br label %12
12: ; preds = %2, %8
%13 = phi i32 [ 1, %8 ], [ 0, %2 ]
ret i32 %13
}