#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 sock_enable_blocking(int sfd, int enable) {
  int flags, s;
  flags = fcntl(sfd, F_GETFL, 0);
  if (flags == -1) {
    perror("fcntl");
    return -1;
  }
  if (enable)
    flags &= ~O_NONBLOCK;
  else
    flags |= O_NONBLOCK;
  s = fcntl(sfd, F_SETFL, flags);
  if (s == -1) {
    perror("fcntl");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<sock_enable_blocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1166 <sock_enable_blocking+0x46>
lea    0xeab(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d6 <sock_enable_blocking+0xb6>
cmpl   $0x0,-0xc(%rbp)
je     1187 <sock_enable_blocking+0x67>
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1196 <sock_enable_blocking+0x76>
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
call   1030 <fcntl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11cf <sock_enable_blocking+0xaf>
lea    0xe42(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d6 <sock_enable_blocking+0xb6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_enable_blocking>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%ebp
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
xor    %r14d,%r14d
xor    %edx,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1173 <sock_enable_blocking+0x53>
mov    0x2ea1(%rip),%rcx
mov    (%rcx),%edx
mov    %edx,%ecx
not    %ecx
and    %eax,%ecx
or     %eax,%edx
test   %ebx,%ebx
cmovne %ecx,%edx
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1173 <sock_enable_blocking+0x53>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe86(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%r14d
jmp    116b <sock_enable_blocking+0x4b>

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 @sock_enable_blocking(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = load i32, i32* @F_GETFL
%10 = call i32 @fcntl(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %37
15: ; preds = %2
%16 = load i32, i32* %5
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = load i32, i32* @O_NONBLOCK
%20 = xor i32 %19, -1
%21 = load i32, i32* %6
%22 = and i32 %21, %20
store i32 %22, i32* %6
br label %27
23: ; preds = %15
%24 = load i32, i32* @O_NONBLOCK
%25 = load i32, i32* %6
%26 = or i32 %25, %24
store i32 %26, i32* %6
br label %27
27: ; preds = %23, %18
%28 = load i32, i32* %4
%29 = load i32, i32* @F_SETFL
%30 = load i32, i32* %6
%31 = call i32 @fcntl(i32 %28, i32 %29, i32 %30)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %37
36: ; preds = %27
store i32 0, i32* %3
br label %37
37: ; preds = %36, %34, %13
%38 = load i32, i32* %3
ret i32 %38
}

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 @sock_enable_blocking(i32 %0, i32 %1) {
%3 = load i32, i32* @F_GETFL
%4 = tail call i32 @fcntl(i32 %0, i32 %3, i32 0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %16, label %6
6: ; preds = %2
%7 = icmp eq i32 %1, 0
%8 = load i32, i32* @O_NONBLOCK
%9 = xor i32 %8, -1
%10 = and i32 %4, %9
%11 = or i32 %8, %4
%12 = select i1 %7, i32 %11, i32 %10
%13 = load i32, i32* @F_SETFL
%14 = tail call i32 @fcntl(i32 %0, i32 %13, i32 %12)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %6, %2
%17 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %6
%19 = phi i32 [ 0, %6 ], [ -1, %16 ]
ret i32 %19
}