#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 make_socket_non_blocking(int sfd) {
  int flags, s;
  flags = fcntl(sfd, F_GETFL, 0);
  if (flags == -1)
    do {
      perror("fcntl");
      return -1;
    } while (0);
  flags |= O_NONBLOCK;
  s = fcntl(sfd, F_SETFL, flags);
  if (s == -1)
    do {
      perror("fcntl");
      return -1;
    } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<make_socket_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)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1168 <make_socket_non_blocking+0x48>
jmp    1150 <make_socket_non_blocking+0x30>
lea    0xea9(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bc <make_socket_non_blocking+0x9c>
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
call   1030 <fcntl@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11b5 <make_socket_non_blocking+0x95>
jmp    119d <make_socket_non_blocking+0x7d>
lea    0xe5c(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bc <make_socket_non_blocking+0x9c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_socket_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>
cmp    $0xffffffff,%eax
je     1165 <make_socket_non_blocking+0x45>
mov    0x2ea5(%rip),%rcx
or     (%rcx),%eax
mov    0x2e8c(%rip),%rcx
mov    (%rcx),%esi
mov    %ebp,%edi
mov    %eax,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1165 <make_socket_non_blocking+0x45>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe94(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%ebx
jmp    115c <make_socket_non_blocking+0x3c>

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [6 x i8] c"fcntl\00"
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define i32 @make_socket_non_blocking(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = load i32, i32* @F_GETFL
%8 = call i32 @fcntl(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %15
11: ; preds = %1
br label %12
12: ; preds = %11
%13 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %30
14: ; No predecessors!
br label %15
15: ; preds = %14, %1
%16 = load i32, i32* @O_NONBLOCK
%17 = load i32, i32* %4
%18 = or i32 %17, %16
store i32 %18, i32* %4
%19 = load i32, i32* %3
%20 = load i32, i32* @F_SETFL
%21 = load i32, i32* %4
%22 = call i32 @fcntl(i32 %19, i32 %20, i32 %21)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %29
25: ; preds = %15
br label %26
26: ; preds = %25
%27 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %30
28: ; No predecessors!
br label %29
29: ; preds = %28, %15
store i32 0, i32* %2
br label %30
30: ; preds = %29, %26, %12
%31 = load i32, i32* %2
ret i32 %31
}

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