#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_OK;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int /*<<< orphan*/ mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
void test3() {
  int fd;
  int ret;
  if (access("/tmp/test_fifo", F_OK) != 0) {
    mkfifo("/tmp/test_fifo", 0666);
  }
  if (fork() > 0) {
    fd = open("/tmp/test_fifo", O_WRONLY);
    write(fd, "333", 4);
    close(fd);
  } else {
    char read_buf[1024];
    fd = open("/tmp/test_fifo", O_RDONLY);
    if ((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",
                  99, read_buf);
        }
      } while (0);
    }
    close(fd);
  }
}


x86 assembly (clang, -O0):
<test3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
lea    0xe65(%rip),%rdi
call   1090 <access@plt>
cmp    $0x0,%rax
je     11bb <test3+0x3b>
lea    0xe4f(%rip),%rdi
mov    $0x1b6,%esi
call   1070 <mkfifo@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
cmp    $0x0,%rax
jle    1205 <test3+0x85>
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
lea    0xe24(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    0xe21(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
jmp    1277 <test3+0xf7>
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
lea    0xdeb(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    126f <test3+0xef>
jmp    1242 <test3+0xc2>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%r8
lea    0xdba(%rip),%rsi
lea    0xdca(%rip),%rdx
mov    $0x63,%ecx
call   1060 <fprintf@plt>
jmp    126f <test3+0xef>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test3>:
push   %rbx
sub    $0x400,%rsp
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
lea    0xe68(%rip),%rdi
call   1090 <access@plt>
test   %rax,%rax
je     11b3 <test3+0x33>
lea    0xe57(%rip),%rdi
mov    $0x1b6,%esi
call   1070 <mkfifo@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
jle    11f8 <test3+0x78>
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
lea    0xe31(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
lea    0xe32(%rip),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %ebx,%edi
add    $0x400,%rsp
pop    %rbx
jmp    1040 <close@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
lea    0xdf8(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x400,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    1246 <test3+0xc6>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
lea    0xdf1(%rip),%rdx
mov    %rsp,%r8
mov    $0x63,%ecx
call   1060 <fprintf@plt>
mov    %ebx,%edi
call   1040 <close@plt>
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"/tmp/test_fifo\00"
@F_OK = global i32 0
@O_WRONLY = global i32 0
@.str.1 = [4 x i8] c"333\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.2 = [23 x i8] c"%s %d: reader got: %s\0A\00"
@.str.3 = [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"
define void @test3() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = load i32, i32* @F_OK
%5 = call i64 @access(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @mkfifo(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 438)
br label %9
9: ; preds = %7, %0
%10 = call i64 (...) @fork()
%11 = icmp sgt i64 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = load i32, i32* @O_WRONLY
%14 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %1
%15 = load i32, i32* %1
%16 = call i32 @write(i32 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 4)
%17 = load i32, i32* %1
%18 = call i32 @close(i32 %17)
br label %35
19: ; preds = %9
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %20)
store i32 %21, i32* %1
%22 = load i32, i32* %1
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%24 = call i32 @read(i32 %22, i8* %23, i32 1024)
store i32 %24, i32* %2
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %19
br label %27
27: ; preds = %26
%28 = load i32, i32* @stderr
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.3, i64 0, i64 0), i32 99, i8* %29)
br label %31
31: ; preds = %27
br label %32
32: ; preds = %31, %19
%33 = load i32, i32* %1
%34 = call i32 @close(i32 %33)
br label %35
35: ; preds = %32, %12
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"/tmp/test_fifo\00"
@F_OK = global i32 0
@O_WRONLY = global i32 0
@.str.1 = [4 x i8] c"333\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.2 = [23 x i8] c"%s %d: reader got: %s\0A\00"
@.str.3 = [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"
define void @test3() {
%1 = alloca [1024 x i8]
%2 = load i32, i32* @F_OK
%3 = tail call i64 @access(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = tail call i32 @mkfifo(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 438)
br label %7
7: ; preds = %5, %0
%8 = tail call i64 (...) @fork()
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = load i32, i32* @O_WRONLY
%12 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = tail call i32 @write(i32 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 4)
%14 = tail call i32 @close(i32 %12)
br label %26
15: ; preds = %7
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%17 = load i32, i32* @O_RDONLY
%18 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = call i32 @read(i32 %18, i8* %16, i32 1024)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.3, i64 0, i64 0), i32 99, i8* %16)
br label %24
24: ; preds = %21, %15
%25 = call i32 @close(i32 %18)
br label %26
26: ; preds = %24, %10
ret void
}