#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*/ O_NONBLOCK;
int /*<<< orphan*/ clr_flg(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ set_flg(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(void) {
  char buf[1024] = {};
  if (read(0, buf, 1024) == -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/day04/fcntl.c",
              36, "read", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  printf("buf=%s\n", buf);
  set_flg(0, O_NONBLOCK);
  clr_flg(0, O_NONBLOCK);
  if (read(0, buf, 1024) == -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/day04/fcntl.c",
              52, "read", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
lea    -0x410(%rbp),%rsi
xor    %edi,%edi
mov    $0x400,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
jne    1219 <main+0x99>
jmp    11c6 <main+0x46>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x414(%rbp)
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x414(%rbp),%edi
mov    %rax,%r9
lea    0xe0d(%rip),%rsi
lea    0xe16(%rip),%rdx
mov    $0x24,%ecx
lea    0xe9e(%rip),%r8
call   1060 <fprintf@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    -0x410(%rbp),%rsi
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
call   10a0 <set_flg@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
call   1070 <clr_flg@plt>
lea    -0x410(%rbp),%rsi
xor    %edi,%edi
mov    $0x400,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
jne    12c0 <main+0x140>
jmp    126d <main+0xed>
mov    0x2d64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x418(%rbp)
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x418(%rbp),%edi
mov    %rax,%r9
lea    0xd66(%rip),%rsi
lea    0xd6f(%rip),%rdx
mov    $0x34,%ecx
lea    0xdf7(%rip),%r8
call   1060 <fprintf@plt>
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsp,%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     11fc <main+0x7c>
lea    0xef2(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
call   1030 <printf@plt>
mov    0x2e1f(%rip),%rbx
mov    (%rbx),%esi
xor    %edi,%edi
call   10a0 <set_flg@plt>
mov    (%rbx),%esi
xor    %edi,%edi
call   1070 <clr_flg@plt>
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     1231 <main+0xb1>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2dd5(%rip),%rax
mov    (%rax),%ebx
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xde6(%rip),%rsi
lea    0xdef(%rip),%rdx
lea    0xe7c(%rip),%r8
mov    %ebx,%edi
mov    $0x24,%ecx
jmp    1264 <main+0xe4>
mov    0x2da0(%rip),%rax
mov    (%rax),%ebx
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdb1(%rip),%rsi
lea    0xdba(%rip),%rdx
lea    0xe47(%rip),%r8
mov    %ebx,%edi
mov    $0x34,%ecx
mov    %rax,%r9
call   1060 <fprintf@plt>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.1 = [148 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/day04/fcntl.c\00"
@.str.2 = [5 x i8] c"read\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [8 x i8] c"buf=%s\0A\00"
@O_NONBLOCK = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
store i32 0, i32* %1
%3 = bitcast [1024 x i8]* %2 to i8*
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = call i32 @read(i32 0, i8* %4, i32 1024)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %16
7: ; preds = %0
br label %8
8: ; preds = %7
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; No predecessors!
br label %16
16: ; preds = %15, %0
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%18 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @O_NONBLOCK
%20 = call i32 @set_flg(i32 0, i32 %19)
%21 = load i32, i32* @O_NONBLOCK
%22 = call i32 @clr_flg(i32 0, i32 %21)
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%24 = call i32 @read(i32 0, i8* %23, i32 1024)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %35
26: ; preds = %16
br label %27
27: ; preds = %26
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; No predecessors!
br label %35
35: ; preds = %34, %16
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.1 = [148 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/day04/fcntl.c\00"
@.str.2 = [5 x i8] c"read\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [8 x i8] c"buf=%s\0A\00"
@O_NONBLOCK = global i32 0
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = call i32 @read(i32 0, i8* %2, i32 1024)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %12
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%14 = load i32, i32* @O_NONBLOCK
%15 = call i32 @set_flg(i32 0, i32 %14)
%16 = load i32, i32* @O_NONBLOCK
%17 = call i32 @clr_flg(i32 0, i32 %16)
%18 = call i32 @read(i32 0, i8* %2, i32 1024)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %27
20: ; preds = %12
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %12
ret i32 0
}