#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__ EAGAIN;
int O_NONBLOCK;
int O_WRONLY;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int write(int, char *, int);
int main() {
  int fd = 0;
  int n;
  char buf[100];
  if ((fd = open("/tmp/myfifo", O_WRONLY | O_NONBLOCK)) < 0) {
    perror("open error");
    exit(-1);
  }
  while (1) {
    fgets(buf, 100, stdin);
    n = strlen(buf);
    if ((n = write(fd, buf, n)) < 0) {
      if (errno == EAGAIN)
        printf("The FIFO has not been read yet. Please try later\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
mov    0x2e52(%rip),%rax
or     (%rax),%esi
lea    0xe61(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11c6 <main+0x56>
lea    0xe55(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    11cb <main+0x5b>
lea    -0x70(%rbp),%rdi
mov    0x2e0a(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1060 <fgets@plt>
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1234 <main+0xc4>
mov    0x2dc0(%rip),%rax
mov    (%rax),%rax
mov    0x2d9e(%rip),%rcx
cmp    (%rcx),%rax
jne    122f <main+0xbf>
lea    0xded(%rip),%rdi
call   1050 <printf@plt>
jmp    1234 <main+0xc4>
jmp    11cb <main+0x5b>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    0x2e3b(%rip),%rax
mov    0x2e5c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe69(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     120c <main+0x9c>
mov    %eax,%ebp
mov    0x2e37(%rip),%r15
mov    %rsp,%rbx
mov    0x2e1d(%rip),%r12
mov    0x2dfe(%rip),%r13
lea    0xe56(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %eax,%eax
jns    11d0 <main+0x60>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
jne    11d0 <main+0x60>
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    11d0 <main+0x60>
lea    0xdf9(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/tmp/myfifo\00"
@O_WRONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [11 x i8] c"open error\00"
@stdin = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@.str.2 = [50 x i8] c"The FIFO has not been read yet. Please try later\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
%5 = load i32, i32* @O_WRONLY
%6 = load i32, i32* @O_NONBLOCK
%7 = or i32 %5, %6
%8 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %0
br label %14
14: ; preds = %13, %32
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%16 = load i32, i32* @stdin
%17 = call i32 @fgets(i8* %15, i32 100, i32 %16)
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %3
%20 = load i32, i32* %2
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%22 = load i32, i32* %3
%23 = call i32 @write(i32 %20, i8* %21, i32 %22)
store i32 %23, i32* %3
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %14
%26 = load i64, i64* @errno
%27 = load i64, i64* @EAGAIN
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %25
br label %32
32: ; preds = %31, %14
br label %14
}

LLVM IR (-O2):
@.str = [12 x i8] c"/tmp/myfifo\00"
@O_WRONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [11 x i8] c"open error\00"
@stdin = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@str = [49 x i8] c"The FIFO has not been read yet. Please try later\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_WRONLY
%4 = load i32, i32* @O_NONBLOCK
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %0, %21
%12 = load i32, i32* @stdin
%13 = call i32 @fgets(i8* %2, i32 100, i32 %12)
%14 = call i32 @strlen(i8* %2)
%15 = call i32 @write(i32 %6, i8* %2, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = load i64, i64* @errno
%19 = load i64, i64* @EAGAIN
%20 = icmp eq i64 %18, %19
br i1 %20, label %22, label %21
21: ; preds = %17, %22, %11
br label %11
22: ; preds = %17
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
br label %21
}