#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, ...);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
void *read_fifo1(void *dummy) {
  int fd = open("/tmp/test_fifo", O_RDONLY);
  int ret;
  char read_buf[1024];
  do {
    if (4 <= 4) {
      fprintf(stderr,
              "%s %d: "
              "fifo open for reading ok\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/clpsz/linux-ipcs/refs/heads/master/"
              "fifo/main.c",
              17);
    }
  } while (0);
  while ((ret = read(fd, read_buf, 1024)) > 0) {
    do {
      if (4 <= 4) {
        fprintf(stderr,
                "%s %d: "
                "reader got: %s\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/clpsz/linux-ipcs/refs/heads/"
                "master/fifo/main.c",
                20, read_buf);
      }
    } while (0);
  }
  close(fd);
  return NULL;
}


x86 assembly (clang, -O0):
<read_fifo1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    0xe98(%rip),%rsi
lea    0xeb2(%rip),%rdx
mov    $0x11,%ecx
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    118f <read_fifo1+0x4f>
mov    -0xc(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jle    11e3 <read_fifo1+0xa3>
jmp    11b4 <read_fifo1+0x74>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%r8
lea    0xeee(%rip),%rsi
lea    0xe5e(%rip),%rdx
mov    $0x14,%ecx
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    118f <read_fifo1+0x4f>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_fifo1>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebp
mov    0x2e6b(%rip),%r12
mov    (%r12),%edi
lea    0xe97(%rip),%rsi
lea    0xeb1(%rip),%rdx
mov    $0x11,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x400,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    11dc <read_fifo1+0x9c>
lea    0xf14(%rip),%r14
lea    0xe84(%rip),%r15
mov    %rsp,%rbx
nop
mov    (%r12),%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    $0x14,%ecx
mov    %rbx,%r8
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
test   %eax,%eax
jg     11b0 <read_fifo1+0x70>
mov    %ebp,%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"/tmp/test_fifo\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [33 x i8] c"%s %d: fifo open for reading ok\0A\00"
@.str.2 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/clpsz/linux-ipcs/refs/heads/master/fifo/main.c\00"
@.str.3 = [23 x i8] c"%s %d: reader got: %s\0A\00"
define i8* @read_fifo1(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
store i8* %0, i8** %2
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %3
br label %8
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 17)
br label %11
11: ; preds = %8
br label %12
12: ; preds = %22, %11
%13 = load i32, i32* %3
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%15 = call i32 @read(i32 %13, i8* %14, i32 1024)
store i32 %15, i32* %4
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %12
br label %18
18: ; preds = %17
%19 = load i32, i32* @stderr
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%21 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 20, i8* %20)
br label %22
22: ; preds = %18
br label %12
23: ; preds = %12
%24 = load i32, i32* %3
%25 = call i32 @close(i32 %24)
ret i8* null
}

LLVM IR (-O2):
@.str = [15 x i8] c"/tmp/test_fifo\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [33 x i8] c"%s %d: fifo open for reading ok\0A\00"
@.str.2 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/clpsz/linux-ipcs/refs/heads/master/fifo/main.c\00"
@.str.3 = [23 x i8] c"%s %d: reader got: %s\0A\00"
define noalias i8* @read_fifo1(i8* nocapture readnone %0) {
%2 = alloca [1024 x i8]
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 17)
%8 = call i32 @read(i32 %4, i8* %5, i32 1024)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %1, %10
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 20, i8* %5)
%13 = call i32 @read(i32 %4, i8* %5, i32 1024)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %10, label %15
15: ; preds = %10, %1
%16 = call i32 @close(i32 %4)
ret i8* null
}