#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 /*<<< orphan*/ _eprintf_exit(int, int, int, char *, char *);
int fcntl(int, int /*<<< orphan*/, int);
void set_fd_blocking(int fd, int blocking) {
  int flags = fcntl(fd, F_GETFL, 0);
  if (flags == -1) {
    _eprintf_exit(0x00, 0x06, 100,
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/mgrosvenor/camio1.0/refs/"
                  "heads/master/istreams/camio_istream_raw.c",
                  "Could not get file flags\n");
  }
  if (blocking) {
    flags &= ~O_NONBLOCK;
  } else {
    flags |= O_NONBLOCK;
  }
  if (fcntl(fd, F_SETFL, flags) == -1) {
    _eprintf_exit(0x00, 0x06, 111,
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/mgrosvenor/camio1.0/refs/"
                  "heads/master/istreams/camio_istream_raw.c",
                  "Could not set file flags\n");
  }
}


x86 assembly (clang, -O0):
<set_fd_blocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    116d <set_fd_blocking+0x4d>
xor    %edi,%edi
mov    $0x6,%esi
mov    $0x64,%edx
lea    0xe9f(%rip),%rcx
lea    0xf35(%rip),%r8
call   1040 <_eprintf_exit@plt>
cmpl   $0x0,-0x8(%rbp)
je     118e <set_fd_blocking+0x6e>
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    119d <set_fd_blocking+0x7d>
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11d9 <set_fd_blocking+0xb9>
xor    %edi,%edi
mov    $0x6,%esi
mov    $0x6f,%edx
lea    0xe33(%rip),%rcx
lea    0xee3(%rip),%r8
call   1040 <_eprintf_exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_fd_blocking>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebx
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    115f <set_fd_blocking+0x3f>
lea    0xeb9(%rip),%rcx
lea    0xf4f(%rip),%r8
xor    %edi,%edi
mov    $0x6,%esi
mov    $0x64,%edx
call   1040 <_eprintf_exit@plt>
mov    0x2e82(%rip),%rax
mov    (%rax),%edx
mov    %edx,%eax
not    %eax
and    %ebp,%eax
or     %ebp,%edx
test   %r14d,%r14d
cmovne %eax,%edx
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1190 <set_fd_blocking+0x70>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe69(%rip),%rcx
lea    0xf19(%rip),%r8
xor    %edi,%edi
mov    $0x6,%esi
mov    $0x6f,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <_eprintf_exit@plt>

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [157 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/mgrosvenor/camio1.0/refs/heads/master/istreams/camio_istream_raw.c\00"
@.str.1 = [26 x i8] c"Could not get file flags\0A\00"
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
@.str.2 = [26 x i8] c"Could not set file flags\0A\00"
define void @set_fd_blocking(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* %5
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @_eprintf_exit(i32 0, i32 6, i32 100, i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load i32, i32* @O_NONBLOCK
%18 = xor i32 %17, -1
%19 = load i32, i32* %5
%20 = and i32 %19, %18
store i32 %20, i32* %5
br label %25
21: ; preds = %13
%22 = load i32, i32* @O_NONBLOCK
%23 = load i32, i32* %5
%24 = or i32 %23, %22
store i32 %24, i32* %5
br label %25
25: ; preds = %21, %16
%26 = load i32, i32* %3
%27 = load i32, i32* @F_SETFL
%28 = load i32, i32* %5
%29 = call i32 @fcntl(i32 %26, i32 %27, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = call i32 @_eprintf_exit(i32 0, i32 6, i32 111, i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %25
ret void
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@.str = [157 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/mgrosvenor/camio1.0/refs/heads/master/istreams/camio_istream_raw.c\00"
@.str.1 = [26 x i8] c"Could not get file flags\0A\00"
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
@.str.2 = [26 x i8] c"Could not set file flags\0A\00"
define void @set_fd_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 %6, label %8
6: ; preds = %2
%7 = tail call i32 @_eprintf_exit(i32 0, i32 6, i32 100, i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = icmp eq i32 %1, 0
%10 = load i32, i32* @O_NONBLOCK
%11 = xor i32 %10, -1
%12 = and i32 %4, %11
%13 = or i32 %10, %4
%14 = select i1 %9, i32 %13, i32 %12
%15 = load i32, i32* @F_SETFL
%16 = tail call i32 @fcntl(i32 %0, i32 %15, i32 %14)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %8
%19 = tail call i32 @_eprintf_exit(i32 0, i32 6, i32 111, i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %8
ret void
}