#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*/ EXIT_FAILURE;
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void set_flg(int fd, int flag) {
  int flags;
  if ((flags = fcntl(fd, F_GETFL, 0)) == -1)
    do {
      fprintf(stderr, "[%s][%d]:%s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day0a/day0a/pipe.c",
              20, "fcntl", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  if (fcntl(fd, F_SETFL, flags | flag) == -1)
    do {
      fprintf(stderr, "[%s][%d]:%s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day0a/day0a/pipe.c",
              22, "fcntl", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
}


x86 assembly (clang, -O0):
<set_flg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    11bf <set_flg+0x7f>
jmp    1172 <set_flg+0x32>
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%r9
lea    0xe67(%rip),%rsi
lea    0xe70(%rip),%rdx
mov    $0x14,%ecx
lea    0xefd(%rip),%r8
call   1040 <fprintf@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x4(%rbp),%edi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
or     -0x8(%rbp),%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    1231 <set_flg+0xf1>
jmp    11e4 <set_flg+0xa4>
mov    0x2df5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%r9
lea    0xdf5(%rip),%rsi
lea    0xdfe(%rip),%rdx
mov    $0x16,%ecx
lea    0xe8b(%rip),%r8
call   1040 <fprintf@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_flg>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     117c <set_flg+0x3c>
mov    0x2e75(%rip),%rcx
mov    (%rcx),%esi
or     %ebp,%eax
mov    %ebx,%edi
mov    %eax,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     11b1 <set_flg+0x71>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e5d(%rip),%rax
mov    (%rax),%ebx
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe66(%rip),%rsi
lea    0xe6f(%rip),%rdx
lea    0xf01(%rip),%r8
mov    %ebx,%edi
mov    $0x14,%ecx
jmp    11e4 <set_flg+0xa4>
mov    0x2e28(%rip),%rax
mov    (%rax),%ebx
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe31(%rip),%rsi
lea    0xe3a(%rip),%rdx
lea    0xecc(%rip),%r8
mov    %ebx,%edi
mov    $0x16,%ecx
mov    %rax,%r9
call   1040 <fprintf@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@F_GETFL = global i32 0
@stderr = global i32 0
@.str = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.1 = [153 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day0a/day0a/pipe.c\00"
@.str.2 = [6 x i8] c"fcntl\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@F_SETFL = global i32 0
define void @set_flg(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 = icmp eq i32 %8, -1
br i1 %9, label %10, label %19
10: ; preds = %2
br label %11
11: ; preds = %10
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.1, i64 0, i64 0), i32 20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; No predecessors!
br label %19
19: ; preds = %18, %2
%20 = load i32, i32* %3
%21 = load i32, i32* @F_SETFL
%22 = load i32, i32* %5
%23 = load i32, i32* %4
%24 = or i32 %22, %23
%25 = call i32 @fcntl(i32 %20, i32 %21, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %36
27: ; preds = %19
br label %28
28: ; preds = %27
%29 = load i32, i32* @stderr
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.1, i64 0, i64 0), i32 22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; No predecessors!
br label %36
36: ; preds = %35, %19
ret void
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@stderr = global i32 0
@.str = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.1 = [153 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day0a/day0a/pipe.c\00"
@.str.2 = [6 x i8] c"fcntl\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@F_SETFL = global i32 0
define void @set_flg(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 %13
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.1, i64 0, i64 0), i32 20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = load i32, i32* @F_SETFL
%15 = or i32 %4, %1
%16 = tail call i32 @fcntl(i32 %0, i32 %14, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %25
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = tail call i8* @strerror(i32 %20)
%22 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.1, i64 0, i64 0), i32 22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %13
ret void
}