#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*/ EXIT_SUCCESS;
int /*<<< orphan*/ F_OK;
int O_WRONLY;
int /*<<< orphan*/ PIPE_BUF;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getpid();
int mkfifo(char *, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ stderr;
int write(int, char *, int /*<<< orphan*/);
int main() {
  int pipe_fd;
  int res, count = 0;
  int open_mode = O_WRONLY;
  int bytes_sent = 0;
  char buffer[PIPE_BUF + 1];
  if (access("/tmp/my_fifo", F_OK) == -1) {
    res = mkfifo("/tmp/my_fifo", 0777);
    if (res != 0) {
      fprintf(stderr, "Could not create fifo %s\n", "/tmp/my_fifo");
      exit(EXIT_FAILURE);
    }
  }
  printf("Process %d opening FIFO O_WRONLY\n", getpid());
  pipe_fd = open("/tmp/my_fifo", open_mode);
  printf("Process %d result %d\n", getpid(), pipe_fd);
  if (pipe_fd != -1) {
    while (bytes_sent < (1024 * 1024 * 10)) {
      printf("count:%d\n", count++);
      res = write(pipe_fd, buffer, PIPE_BUF);
      if (res == -1) {
        fprintf(stderr, "Write error on pipe\n");
        exit(EXIT_FAILURE);
      }
      bytes_sent += res;
    }
    (void)close(pipe_fd);
  } else {
    exit(EXIT_FAILURE);
  }
  printf("Process %d finished\n", getpid());
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
lea    0xe08(%rip),%rdi
call   10a0 <access@plt>
cmp    $0xffffffff,%eax
jne    1255 <main+0xc5>
lea    0xdf3(%rip),%rdi
mov    $0x1ff,%esi
call   1080 <mkfifo@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1250 <main+0xc0>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
lea    0xdd9(%rip),%rsi
lea    0xdc5(%rip),%rdx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
jmp    1255 <main+0xc5>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xd8a(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
mov    -0x8(%rbp),%edx
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0xffffffff,-0x8(%rbp)
je     132f <main+0x19f>
jmp    12a7 <main+0x117>
cmpl   $0xa00000,-0x18(%rbp)
jge    1322 <main+0x192>
mov    -0x10(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    0x2ced(%rip),%rax
mov    (%rax),%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1314 <main+0x184>
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
lea    0xd6a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2ccb(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0xc(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    12a7 <main+0x117>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
jmp    133d <main+0x1ad>
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xd31(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2c75(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e13(%rip),%rax
mov    (%rax),%r14d
mov    0x2e19(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
lea    0xe2b(%rip),%rdi
call   10a0 <access@plt>
cmp    $0xffffffff,%eax
jne    11f8 <main+0x68>
lea    0xe1a(%rip),%rdi
mov    $0x1ff,%esi
call   1080 <mkfifo@plt>
test   %eax,%eax
jne    12c1 <main+0x131>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe21(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdea(%rip),%rdi
mov    %r14d,%esi
call   1090 <open@plt>
mov    %eax,%r12d
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe1a(%rip),%rdi
mov    %eax,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0xffffffff,%r12d
je     12f8 <main+0x168>
lea    0xe13(%rip),%r14
xor    %ebx,%ebx
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d55(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
mov    %r15,%rsi
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     12e1 <main+0x151>
add    $0x1,%ebx
add    %eax,%r13d
cmp    $0xa00000,%r13d
jl     1260 <main+0xd0>
mov    %r12d,%edi
call   1060 <close@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xdd4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
lea    0xd3c(%rip),%rsi
lea    0xd28(%rip),%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12f8 <main+0x168>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
lea    0xd78(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@PIPE_BUF = global i32 0
@.str = [13 x i8] c"/tmp/my_fifo\00"
@F_OK = global i32 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"Could not create fifo %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [34 x i8] c"Process %d opening FIFO O_WRONLY\0A\00"
@.str.3 = [22 x i8] c"Process %d result %d\0A\00"
@.str.4 = [10 x i8] c"count:%d\0A\00"
@.str.5 = [21 x i8] c"Write error on pipe\0A\00"
@.str.6 = [21 x i8] c"Process %d finished\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %4
%9 = load i32, i32* @O_WRONLY
store i32 %9, i32* %5
store i32 0, i32* %6
%10 = load i32, i32* @PIPE_BUF
%11 = add nsw i32 %10, 1
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %7
%14 = alloca i8, i64 %12
store i64 %12, i64* %8
%15 = load i32, i32* @F_OK
%16 = call i32 @access(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %28
18: ; preds = %0
%19 = call i32 @mkfifo(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 511)
store i32 %19, i32* %3
%20 = load i32, i32* %3
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %18
br label %28
28: ; preds = %27, %0
%29 = call i32 (...) @getpid()
%30 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %5
%32 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %31)
store i32 %32, i32* %2
%33 = call i32 (...) @getpid()
%34 = load i32, i32* %2
%35 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %33, i32 %34)
%36 = load i32, i32* %2
%37 = icmp ne i32 %36, -1
br i1 %37, label %38, label %63
38: ; preds = %28
br label %39
39: ; preds = %56, %38
%40 = load i32, i32* %6
%41 = icmp slt i32 %40, 10485760
br i1 %41, label %42, label %60
42: ; preds = %39
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
%45 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %43)
%46 = load i32, i32* %2
%47 = load i32, i32* @PIPE_BUF
%48 = call i32 @write(i32 %46, i8* %14, i32 %47)
store i32 %48, i32* %3
%49 = load i32, i32* %3
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %56
51: ; preds = %42
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %42
%57 = load i32, i32* %3
%58 = load i32, i32* %6
%59 = add nsw i32 %58, %57
store i32 %59, i32* %6
br label %39
60: ; preds = %39
%61 = load i32, i32* %2
%62 = call i32 @close(i32 %61)
br label %66
63: ; preds = %28
%64 = load i32, i32* @EXIT_FAILURE
%65 = call i32 @exit(i32 %64)
unreachable
66: ; preds = %60
%67 = call i32 (...) @getpid()
%68 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %67)
%69 = load i32, i32* @EXIT_SUCCESS
%70 = call i32 @exit(i32 %69)
unreachable
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@PIPE_BUF = global i32 0
@.str = [13 x i8] c"/tmp/my_fifo\00"
@F_OK = global i32 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"Could not create fifo %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [34 x i8] c"Process %d opening FIFO O_WRONLY\0A\00"
@.str.3 = [22 x i8] c"Process %d result %d\0A\00"
@.str.4 = [10 x i8] c"count:%d\0A\00"
@.str.5 = [21 x i8] c"Write error on pipe\0A\00"
@.str.6 = [21 x i8] c"Process %d finished\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = load i32, i32* @O_WRONLY
%2 = load i32, i32* @PIPE_BUF
%3 = add nsw i32 %2, 1
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = load i32, i32* @F_OK
%7 = tail call i32 @access(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %17
9: ; preds = %0
%10 = tail call i32 @mkfifo(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 511)
%11 = icmp eq i32 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %9, %0
%18 = tail call i32 (...) @getpid()
%19 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1)
%21 = tail call i32 (...) @getpid()
%22 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %21, i32 %20)
%23 = icmp eq i32 %20, -1
br i1 %23, label %46, label %24
24: ; preds = %17, %36
%25 = phi i32 [ %37, %36 ], [ 0, %17 ]
%26 = phi i32 [ %38, %36 ], [ 0, %17 ]
%27 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%28 = load i32, i32* @PIPE_BUF
%29 = call i32 @write(i32 %20, i8* %5, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %36
31: ; preds = %24
%32 = load i32, i32* @stderr
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = tail call i32 @exit(i32 %34)
unreachable
36: ; preds = %24
%37 = add nuw nsw i32 %25, 1
%38 = add nsw i32 %29, %26
%39 = icmp slt i32 %38, 10485760
br i1 %39, label %24, label %40
40: ; preds = %36
%41 = tail call i32 @close(i32 %20)
%42 = tail call i32 (...) @getpid()
%43 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %42)
%44 = load i32, i32* @EXIT_SUCCESS
%45 = tail call i32 @exit(i32 %44)
unreachable
46: ; preds = %17
%47 = load i32, i32* @EXIT_FAILURE
%48 = tail call i32 @exit(i32 %47)
unreachable
}