#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 sock_set_blocking(int *fd, int blocking) {
  int val = fcntl((*fd), F_GETFL);
  if (val == -1)
    return -1;
  if (blocking)
    val &= ~O_NONBLOCK;
  else
    val |= O_NONBLOCK;
  return fcntl((*fd), F_SETFL, val);
}


x86 assembly (clang, -O0):
<sock_set_blocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    114e <sock_set_blocking+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    119a <sock_set_blocking+0x8a>
cmpl   $0x0,-0x14(%rbp)
je     116f <sock_set_blocking+0x5f>
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    117e <sock_set_blocking+0x6e>
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_set_blocking>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    (%rdi),%edi
mov    0x2eaf(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     115d <sock_set_blocking+0x4d>
mov    0x2eb2(%rip),%rcx
mov    (%rcx),%edx
mov    %edx,%ecx
not    %ecx
and    %eax,%ecx
or     %eax,%edx
test   %ebp,%ebp
cmovne %ecx,%edx
mov    (%rbx),%edi
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <fcntl@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define i32 @sock_set_blocking(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%7 = load i32*, i32** %4
%8 = load i32, i32* %7
%9 = load i32, i32* @F_GETFL
%10 = call i32 (i32, i32, ...) @fcntl(i32 %8, i32 %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %32
14: ; preds = %2
%15 = load i32, i32* %5
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load i32, i32* @O_NONBLOCK
%19 = xor i32 %18, -1
%20 = load i32, i32* %6
%21 = and i32 %20, %19
store i32 %21, i32* %6
br label %26
22: ; preds = %14
%23 = load i32, i32* @O_NONBLOCK
%24 = load i32, i32* %6
%25 = or i32 %24, %23
store i32 %25, i32* %6
br label %26
26: ; preds = %22, %17
%27 = load i32*, i32** %4
%28 = load i32, i32* %27
%29 = load i32, i32* @F_SETFL
%30 = load i32, i32* %6
%31 = call i32 (i32, i32, ...) @fcntl(i32 %28, i32 %29, i32 %30)
store i32 %31, i32* %3
br label %32
32: ; preds = %26, %13
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define i32 @sock_set_blocking(i32* nocapture %0, i32 %1) {
%3 = load i32, i32* %0
%4 = load i32, i32* @F_GETFL
%5 = tail call i32 (i32, i32, ...) @fcntl(i32 %3, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %17, label %7
7: ; preds = %2
%8 = icmp eq i32 %1, 0
%9 = load i32, i32* @O_NONBLOCK
%10 = xor i32 %9, -1
%11 = and i32 %5, %10
%12 = or i32 %9, %5
%13 = select i1 %8, i32 %12, i32 %11
%14 = load i32, i32* %0
%15 = load i32, i32* @F_SETFL
%16 = tail call i32 (i32, i32, ...) @fcntl(i32 %14, i32 %15, i32 %13)
br label %17
17: ; preds = %2, %7
%18 = phi i32 [ %16, %7 ], [ -1, %2 ]
ret i32 %18
}