#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);
void ytcpsocket_set_block(int socket, int on) {
  int flags;
  flags = fcntl(socket, F_GETFL, 0);
  if (on == 0) {
    fcntl(socket, F_SETFL, flags | O_NONBLOCK);
  } else {
    flags &= ~O_NONBLOCK;
    fcntl(socket, F_SETFL, flags);
  }
}


x86 assembly (clang, -O0):
<ytcpsocket_set_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1160 <ytcpsocket_set_block+0x50>
mov    -0x4(%rbp),%edi
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e94(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
jmp    1186 <ytcpsocket_set_block+0x76>
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
call   1030 <fcntl@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ytcpsocket_set_block>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2eb2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
test   %ebp,%ebp
je     1143 <ytcpsocket_set_block+0x33>
mov    0x2eb6(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %ecx,%eax
mov    0x2e99(%rip),%rcx
mov    (%rcx),%esi
jmp    1155 <ytcpsocket_set_block+0x45>
mov    0x2e8e(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e95(%rip),%rcx
or     (%rcx),%eax
mov    %ebx,%edi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <fcntl@plt>

LLVM IR (-O0):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define void @ytcpsocket_set_block(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%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* %5
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* %3
%13 = load i32, i32* @F_SETFL
%14 = load i32, i32* %5
%15 = load i32, i32* @O_NONBLOCK
%16 = or i32 %14, %15
%17 = call i32 @fcntl(i32 %12, i32 %13, i32 %16)
br label %27
18: ; preds = %2
%19 = load i32, i32* @O_NONBLOCK
%20 = xor i32 %19, -1
%21 = load i32, i32* %5
%22 = and i32 %21, %20
store i32 %22, i32* %5
%23 = load i32, i32* %3
%24 = load i32, i32* @F_SETFL
%25 = load i32, i32* %5
%26 = call i32 @fcntl(i32 %23, i32 %24, i32 %25)
br label %27
27: ; preds = %18, %11
ret void
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define void @ytcpsocket_set_block(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 %1, 0
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = load i32, i32* @F_SETFL
%8 = load i32, i32* @O_NONBLOCK
%9 = or i32 %8, %4
%10 = tail call i32 @fcntl(i32 %0, i32 %7, i32 %9)
br label %17
11: ; preds = %2
%12 = load i32, i32* @O_NONBLOCK
%13 = xor i32 %12, -1
%14 = and i32 %4, %13
%15 = load i32, i32* @F_SETFL
%16 = tail call i32 @fcntl(i32 %0, i32 %15, i32 %14)
br label %17
17: ; preds = %11, %6
ret void
}