#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 */
typedef scalar_t__ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int O_NONBLOCK;
int errno;
int fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int tcp_set_block(int sockfd, uint8_t block) {
  int ret;
  int flags;
  flags = fcntl(sockfd, F_GETFL, 0);
  if (flags < 0) {
    ret = -errno;
    fprintf(stderr, "%s +%d: fcntl: %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/iamyuiwong/swift-socket/refs/heads/"
            "master/socket/tcp.c",
            43, strerror(errno));
    return ret;
  }
  if (0 == block) {
    ret = fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
  } else {
    flags &= ~O_NONBLOCK;
    ret = fcntl(sockfd, F_SETFL, flags);
  }
  if (ret < 0) {
    ret = -errno;
    fprintf(stderr, "%s +%d: fcntl: %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/iamyuiwong/swift-socket/refs/heads/"
            "master/socket/tcp.c",
            59, strerror(errno));
    return ret;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<tcp_set_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11b0 <tcp_set_block+0x80>
xor    %eax,%eax
mov    0x2e60(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%r8
lea    0xe6c(%rip),%rsi
lea    0xe78(%rip),%rdx
mov    $0x2b,%ecx
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    126c <tcp_set_block+0x13c>
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    11e1 <tcp_set_block+0xb1>
mov    -0x8(%rbp),%edi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%edx
mov    0x2e16(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
mov    %eax,-0x14(%rbp)
jmp    120a <tcp_set_block+0xda>
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2dd3(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%edx
call   1030 <fcntl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1265 <tcp_set_block+0x135>
xor    %eax,%eax
mov    0x2dab(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x14(%rbp)
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%r8
lea    0xdb7(%rip),%rsi
lea    0xdc3(%rip),%rdx
mov    $0x3b,%ecx
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    126c <tcp_set_block+0x13c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcp_set_block>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
mov    %edi,%ebx
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
test   %eax,%eax
js     116a <tcp_set_block+0x3a>
test   %rbp,%rbp
je     1172 <tcp_set_block+0x42>
mov    0x2e8f(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %ecx,%eax
mov    0x2e6a(%rip),%rcx
mov    (%rcx),%esi
jmp    1184 <tcp_set_block+0x54>
mov    $0x2b,%r14d
jmp    1199 <tcp_set_block+0x69>
mov    0x2e57(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e66(%rip),%rcx
or     (%rcx),%eax
mov    %ebx,%edi
mov    %eax,%edx
call   1030 <fcntl@plt>
xor    %ebx,%ebx
test   %eax,%eax
jns    11cf <tcp_set_block+0x9f>
mov    $0x3b,%r14d
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    %edi,%ebx
neg    %ebx
mov    0x2e2b(%rip),%rax
mov    (%rax),%ebp
call   1050 <strerror@plt>
lea    0xe45(%rip),%rsi
lea    0xe51(%rip),%rdx
mov    %ebp,%edi
mov    %r14d,%ecx
mov    %rax,%r8
call   1040 <fprintf@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"%s +%d: fcntl: %s\0A\00"
@.str.1 = [145 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/iamyuiwong/swift-socket/refs/heads/master/socket/tcp.c\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32 @tcp_set_block(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i64 %1, i64* %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* %7
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load i32, i32* @errno
%15 = sub nsw i32 0, %14
store i32 %15, i32* %6
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.1, i64 0, i64 0), i32 43, i8* %18)
%20 = load i32, i32* %6
store i32 %20, i32* %3
br label %52
21: ; preds = %2
%22 = load i64, i64* %5
%23 = icmp eq i64 0, %22
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = load i32, i32* %4
%26 = load i32, i32* @F_SETFL
%27 = load i32, i32* %7
%28 = load i32, i32* @O_NONBLOCK
%29 = or i32 %27, %28
%30 = call i32 @fcntl(i32 %25, i32 %26, i32 %29)
store i32 %30, i32* %6
br label %40
31: ; preds = %21
%32 = load i32, i32* @O_NONBLOCK
%33 = xor i32 %32, -1
%34 = load i32, i32* %7
%35 = and i32 %34, %33
store i32 %35, i32* %7
%36 = load i32, i32* %4
%37 = load i32, i32* @F_SETFL
%38 = load i32, i32* %7
%39 = call i32 @fcntl(i32 %36, i32 %37, i32 %38)
store i32 %39, i32* %6
br label %40
40: ; preds = %31, %24
%41 = load i32, i32* %6
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %51
43: ; preds = %40
%44 = load i32, i32* @errno
%45 = sub nsw i32 0, %44
store i32 %45, i32* %6
%46 = load i32, i32* @stderr
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.1, i64 0, i64 0), i32 59, i8* %48)
%50 = load i32, i32* %6
store i32 %50, i32* %3
br label %52
51: ; preds = %40
store i32 0, i32* %3
br label %52
52: ; preds = %51, %43, %13
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"%s +%d: fcntl: %s\0A\00"
@.str.1 = [145 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/iamyuiwong/swift-socket/refs/heads/master/socket/tcp.c\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32 @tcp_set_block(i32 %0, i64 %1) {
%3 = load i32, i32* @F_GETFL
%4 = tail call i32 @fcntl(i32 %0, i32 %3, i32 0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %22, label %6
6: ; preds = %2
%7 = icmp eq i64 %1, 0
br i1 %7, label %8, label %13
8: ; preds = %6
%9 = load i32, i32* @F_SETFL
%10 = load i32, i32* @O_NONBLOCK
%11 = or i32 %10, %4
%12 = tail call i32 @fcntl(i32 %0, i32 %9, i32 %11)
br label %19
13: ; preds = %6
%14 = load i32, i32* @O_NONBLOCK
%15 = xor i32 %14, -1
%16 = and i32 %4, %15
%17 = load i32, i32* @F_SETFL
%18 = tail call i32 @fcntl(i32 %0, i32 %17, i32 %16)
br label %19
19: ; preds = %13, %8
%20 = phi i32 [ %12, %8 ], [ %18, %13 ]
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %19, %2
%23 = phi i32 [ 43, %2 ], [ 59, %19 ]
%24 = load i32, i32* @errno
%25 = sub nsw i32 0, %24
%26 = load i32, i32* @stderr
%27 = tail call i8* @strerror(i32 %24)
%28 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.1, i64 0, i64 0), i32 %23, i8* %27)
br label %29
29: ; preds = %22, %19
%30 = phi i32 [ 0, %19 ], [ %25, %22 ]
ret i32 %30
}