#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 /*<<< orphan*/ perror(char *);
int set_non_blocking(int s) {
  int flag = fcntl(s, F_GETFL, 0);
  if (fcntl(s, F_SETFL, flag | O_NONBLOCK) != 0) {
    perror("fcntl");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_non_blocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e91(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
cmp    $0x0,%eax
je     117f <set_non_blocking+0x5f>
lea    0xe92(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1186 <set_non_blocking+0x66>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_non_blocking>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    0x2e9a(%rip),%rcx
mov    (%rcx),%esi
mov    0x2ea1(%rip),%rcx
or     (%rcx),%eax
mov    %ebp,%edi
mov    %eax,%edx
call   1030 <fcntl@plt>
test   %eax,%eax
jne    115f <set_non_blocking+0x3f>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe9a(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%ebx
jmp    1156 <set_non_blocking+0x36>

LLVM IR (-O0):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str = [6 x i8] c"fcntl\00"
define i32 @set_non_blocking(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 @fcntl(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %4
%8 = load i32, i32* %3
%9 = load i32, i32* @F_SETFL
%10 = load i32, i32* %4
%11 = load i32, i32* @O_NONBLOCK
%12 = or i32 %10, %11
%13 = call i32 @fcntl(i32 %8, i32 %9, i32 %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %18
17: ; preds = %1
store i32 0, i32* %2
br label %18
18: ; preds = %17, %15
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str = [6 x i8] c"fcntl\00"
define i32 @set_non_blocking(i32 %0) {
%2 = load i32, i32* @F_GETFL
%3 = tail call i32 @fcntl(i32 %0, i32 %2, i32 0)
%4 = load i32, i32* @F_SETFL
%5 = load i32, i32* @O_NONBLOCK
%6 = or i32 %5, %3
%7 = tail call i32 @fcntl(i32 %0, i32 %4, i32 %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %1, %9
%12 = phi i32 [ -1, %9 ], [ 0, %1 ]
ret i32 %12
}