#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 */
scalar_t__ ENOENT;
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ O_WRONLY;
scalar_t__ access(char *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int write(int, char *, int);
int main() {
  int fd, count, ok;
  char buf[256] = "Hello fifo";
  if (access("foo", F_OK) != 0) {
    printf("No pipe found. Will create one\n");
    mkfifo("foo", 0660);
  }
  printf("About to open pipe\n");
  fd = open("foo", O_WRONLY);
  if (fd == -1) {
    if (errno == ENOENT) {
      printf("Couldn't open file as it doesn't exist\n");
    } else {
      printf("Errno: %d \n", errno);
      perror("Error while opening pipe");
      return 1;
    }
  }
  printf("About to write to pipe, fd: %d\n", fd);
  count = write(fd, buf, 10);
  printf("Wrote %d bytes to pipe\n", count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xe70(%rip),%rsi
mov    $0x100,%edx
call   1060 <memcpy@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
lea    0xf56(%rip),%rdi
call   1080 <access@plt>
cmp    $0x0,%rax
je     11d8 <main+0x68>
lea    0xf44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf32(%rip),%rdi
mov    $0x1b0,%esi
call   1050 <mkfifo@plt>
lea    0xf45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
lea    0xf0a(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    126a <main+0xfa>
mov    0x2dd1(%rip),%rax
mov    (%rax),%rax
mov    0x2db7(%rip),%rcx
cmp    (%rcx),%rax
jne    1235 <main+0xc5>
lea    0xf0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1265 <main+0xf5>
mov    0x2da4(%rip),%rax
mov    (%rax),%rsi
lea    0xf1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf18(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12aa <main+0x13a>
jmp    126a <main+0xfa>
mov    -0x8(%rbp),%esi
lea    0xf11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0xa,%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xf09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
lea    0xe70(%rip),%rsi
mov    %rsp,%rdi
mov    $0x100,%edx
call   1070 <memcpy@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
lea    0xf53(%rip),%rdi
call   1090 <access@plt>
test   %rax,%rax
je     11d4 <main+0x54>
lea    0xfdd(%rip),%rdi
call   1030 <puts@plt>
lea    0xf36(%rip),%rdi
mov    $0x1b0,%esi
call   1060 <mkfifo@plt>
lea    0xf86(%rip),%rdi
call   1030 <puts@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
lea    0xf10(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    121e <main+0x9e>
mov    0x2ddd(%rip),%rax
mov    (%rax),%rsi
mov    0x2dc3(%rip),%rax
cmp    (%rax),%rsi
jne    125b <main+0xdb>
lea    0xf5b(%rip),%rdi
call   1030 <puts@plt>
lea    0xf04(%rip),%rdi
xor    %ebp,%ebp
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xa,%edx
call   1040 <write@plt>
lea    0xf03(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%eax
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xea2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea0(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%ebp
jmp    124f <main+0xcf>

LLVM IR (-O0):
@__const.main.buf = [256 x i8] c"Hello fifo\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [4 x i8] c"foo\00"
@F_OK = global i32 0
@.str.1 = [32 x i8] c"No pipe found. Will create one\0A\00"
@.str.2 = [20 x i8] c"About to open pipe\0A\00"
@O_WRONLY = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@.str.3 = [40 x i8] c"Couldn't open file as it doesn't exist\0A\00"
@.str.4 = [12 x i8] c"Errno: %d \0A\00"
@.str.5 = [25 x i8] c"Error while opening pipe\00"
@.str.6 = [32 x i8] c"About to write to pipe, fd: %d\0A\00"
@.str.7 = [24 x i8] c"Wrote %d bytes to pipe\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [256 x i8]
store i32 0, i32* %1
%6 = bitcast [256 x i8]* %5 to i8*
%7 = load i32, i32* @F_OK
%8 = call i64 @access(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @mkfifo(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 432)
br label %13
13: ; preds = %10, %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* @O_WRONLY
%16 = call i32 @open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 %16, i32* %2
%17 = load i32, i32* %2
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %30
19: ; preds = %13
%20 = load i64, i64* @errno
%21 = load i64, i64* @ENOENT
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
br label %29
25: ; preds = %19
%26 = load i64, i64* @errno
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i64 %26)
%28 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %38
29: ; preds = %23
br label %30
30: ; preds = %29, %13
%31 = load i32, i32* %2
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %2
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%35 = call i32 @write(i32 %33, i8* %34, i32 10)
store i32 %35, i32* %3
%36 = load i32, i32* %3
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %36)
store i32 0, i32* %1
br label %38
38: ; preds = %30, %25
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@__const.main.buf = [256 x i8] c"Hello fifo\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [4 x i8] c"foo\00"
@F_OK = global i32 0
@O_WRONLY = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@.str.4 = [12 x i8] c"Errno: %d \0A\00"
@.str.5 = [25 x i8] c"Error while opening pipe\00"
@.str.6 = [32 x i8] c"About to write to pipe, fd: %d\0A\00"
@.str.7 = [24 x i8] c"Wrote %d bytes to pipe\0A\00"
@str = [19 x i8] c"About to open pipe\00"
@str.8 = [39 x i8] c"Couldn't open file as it doesn't exist\00"
@str.9 = [31 x i8] c"No pipe found. Will create one\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @F_OK
%4 = tail call i64 @access(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.9, i64 0, i64 0))
%8 = tail call i32 @mkfifo(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 432)
br label %9
9: ; preds = %6, %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%11 = load i32, i32* @O_WRONLY
%12 = tail call i32 @open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %23
14: ; preds = %9
%15 = load i64, i64* @errno
%16 = load i64, i64* @ENOENT
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.8, i64 0, i64 0))
br label %23
20: ; preds = %14
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i64 %15)
%22 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
br label %27
23: ; preds = %18, %9
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 %12)
%25 = call i32 @write(i32 %12, i8* %2, i32 10)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %23, %20
%28 = phi i32 [ 0, %23 ], [ 1, %20 ]
ret i32 %28
}