#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 /*<<< orphan*/ event_warn(char *);
int fcntl(int, int /*<<< orphan*/, ...);
int evutil_make_socket_nonblocking(int fd) {
  long flags = fcntl(fd, F_GETFL);
  if (flags < 0) {
    event_warn("fcntl(get O_NONBLOCK)");
    return -1;
  }
  if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
    event_warn("fcntl(O_NONBLOCK)");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<evutil_make_socket_nonblocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
cltq
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1167 <evutil_make_socket_nonblocking+0x47>
lea    0xeaa(%rip),%rdi
call   1040 <event_warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b0 <evutil_make_socket_nonblocking+0x90>
mov    -0x8(%rbp),%edi
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
mov    0x2e6a(%rip),%rax
or     (%rax),%rdx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11a9 <evutil_make_socket_nonblocking+0x89>
lea    0xe7e(%rip),%rdi
call   1040 <event_warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b0 <evutil_make_socket_nonblocking+0x90>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<evutil_make_socket_nonblocking>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %eax,%eax
js     1167 <evutil_make_socket_nonblocking+0x47>
mov    %eax,%edx
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
mov    0x2e9b(%rip),%rax
or     (%rax),%rdx
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    1178 <evutil_make_socket_nonblocking+0x58>
lea    0xeb1(%rip),%rdi
jmp    116e <evutil_make_socket_nonblocking+0x4e>
lea    0xe92(%rip),%rdi
call   1040 <event_warn@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [22 x i8] c"fcntl(get O_NONBLOCK)\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i64 0
@.str.1 = [18 x i8] c"fcntl(O_NONBLOCK)\00"
define i32 @evutil_make_socket_nonblocking(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
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)
%8 = sext i32 %7 to i64
store i64 %8, i64* %4
%9 = load i64, i64* %4
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @event_warn(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %24
13: ; preds = %1
%14 = load i32, i32* %3
%15 = load i32, i32* @F_SETFL
%16 = load i64, i64* %4
%17 = load i64, i64* @O_NONBLOCK
%18 = or i64 %16, %17
%19 = call i32 (i32, i32, ...) @fcntl(i32 %14, i32 %15, i64 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %13
%22 = call i32 @event_warn(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %24
23: ; preds = %13
store i32 0, i32* %2
br label %24
24: ; preds = %23, %21, %11
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@.str = [22 x i8] c"fcntl(get O_NONBLOCK)\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i64 0
@.str.1 = [18 x i8] c"fcntl(O_NONBLOCK)\00"
define i32 @evutil_make_socket_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 %12, label %5
5: ; preds = %1
%6 = zext i32 %3 to i64
%7 = load i32, i32* @F_SETFL
%8 = load i64, i64* @O_NONBLOCK
%9 = or i64 %8, %6
%10 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %7, i64 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %5, %1
%13 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %5 ]
%14 = tail call i32 @event_warn(i8* %13)
br label %15
15: ; preds = %12, %5
%16 = phi i32 [ 0, %5 ], [ -1, %12 ]
ret i32 %16
}