#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 /*<<< orphan*/ O_NONBLOCK;
int /*<<< orphan*/ d_log(char *);
int /*<<< orphan*/ exit(int);
int fcntl(int, int /*<<< orphan*/, int);
int SetUnsetBlocking(int s) {
  int opts;
  opts = fcntl(s, F_GETFL, 0);
  if (opts == -1) {
    d_log("fcntl(sock,GETFL)");
    exit(-1);
  }
  if (fcntl(s, F_SETFL, opts & !O_NONBLOCK) == -1) {
    d_log("fcntl(sock,SETFL,opts)");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<SetUnsetBlocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1171 <SetUnsetBlocking+0x41>
lea    0xe9e(%rip),%rdi
call   1040 <d_log@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x4(%rbp),%edi
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    0x2e61(%rip),%rax
cmpl   $0x0,(%rax)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
and    %eax,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11ba <SetUnsetBlocking+0x8a>
lea    0xe67(%rip),%rdi
call   1040 <d_log@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetUnsetBlocking>:
push   %rbx
mov    %edi,%ebx
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1174 <SetUnsetBlocking+0x44>
mov    0x2e89(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e90(%rip),%rcx
xor    %edx,%edx
cmpl   $0x0,(%rcx)
sete   %dl
and    %edx,%eax
mov    %ebx,%edi
mov    %eax,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     118a <SetUnsetBlocking+0x5a>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe85(%rip),%rdi
call   1040 <d_log@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
lea    0xe81(%rip),%rdi
call   1040 <d_log@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [18 x i8] c"fcntl(sock,GETFL)\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [23 x i8] c"fcntl(sock,SETFL,opts)\00"
define i32 @SetUnsetBlocking(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = load i32, i32* @F_GETFL
%6 = call i32 @fcntl(i32 %4, i32 %5, i32 0)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = call i32 @d_log(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 -1)
unreachable
12: ; preds = %1
%13 = load i32, i32* %2
%14 = load i32, i32* @F_SETFL
%15 = load i32, i32* %3
%16 = load i32, i32* @O_NONBLOCK
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
%19 = zext i1 %18 to i32
%20 = and i32 %15, %19
%21 = call i32 @fcntl(i32 %13, i32 %14, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %12
%24 = call i32 @d_log(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@.str = [18 x i8] c"fcntl(sock,GETFL)\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [23 x i8] c"fcntl(sock,SETFL,opts)\00"
define i32 @SetUnsetBlocking(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 %5, label %8
5: ; preds = %1
%6 = tail call i32 @d_log(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %1
%9 = load i32, i32* @F_SETFL
%10 = load i32, i32* @O_NONBLOCK
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
%13 = and i32 %3, %12
%14 = tail call i32 @fcntl(i32 %0, i32 %9, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %8
%17 = tail call i32 @d_log(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %8
ret i32 0
}