#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int O_NONBLOCK;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strcpy(char *, char *);
int write(int, char *, int);
int main(void) {
  char buffer[80];
  memset(buffer, 0, sizeof(buffer));
  char FIFO[] = "FIFO";
  int fd;
  fd = open(FIFO, O_WRONLY | O_NONBLOCK);
  if (fd == -1) {
    perror("cannot open fifo");
    return 1;
  }
  while (1) {
    memset(buffer, 0, sizeof(buffer));
    strcpy(buffer, "Hello world");
    if (write(fd, buffer, sizeof(buffer)) == -1) {
      perror("write data error");
    } else {
      printf("write to fifo data is: %s\n", buffer);
    }
    sleep(2);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1060 <memset@plt>
mov    0xe6b(%rip),%eax
mov    %eax,-0x65(%rbp)
mov    0xe66(%rip),%al
mov    %al,-0x61(%rbp)
lea    -0x65(%rbp),%rdi
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
mov    0x2e33(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0xffffffff,-0x6c(%rbp)
jne    11e0 <main+0x70>
lea    0xe35(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%eax
add    $0x70,%rsp
pop    %rbp
ret
jmp    11e5 <main+0x75>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1060 <memset@plt>
lea    -0x60(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x6c(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x50,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    1230 <main+0xc0>
lea    0xdfc(%rip),%rdi
call   1080 <perror@plt>
jmp    1240 <main+0xd0>
lea    -0x60(%rbp),%rsi
lea    0xdf8(%rip),%rdi
call   1050 <printf@plt>
mov    $0x2,%edi
call   1090 <sleep@plt>
jmp    11e5 <main+0x75>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x60,%rsp
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1060 <memset@plt>
movb   $0x0,0xc(%rsp)
movl   $0x4f464946,0x8(%rsp)
4f
mov    0x2e2f(%rip),%rax
mov    0x2e40(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0x8(%rsp),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     122d <main+0xbd>
mov    %eax,%ebp
lea    0x10(%rsp),%rbx
lea    0xe4d(%rip),%r14
lea    0xe52(%rip),%r15
lea    0xe5c(%rip),%r12
jmp    11f5 <main+0x85>
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    $0x2,%edi
call   1090 <sleep@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x50,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    11e0 <main+0x70>
mov    %r15,%rdi
call   1080 <perror@plt>
jmp    11eb <main+0x7b>
lea    0xdd1(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.FIFO = [5 x i8] c"FIFO\00"
@O_WRONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str = [17 x i8] c"cannot open fifo\00"
@.str.1 = [12 x i8] c"Hello world\00"
@.str.2 = [17 x i8] c"write data error\00"
@.str.3 = [27 x i8] c"write to fifo data is: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca [5 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 80)
%7 = bitcast [5 x i8]* %3 to i8*
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%9 = load i32, i32* @O_WRONLY
%10 = load i32, i32* @O_NONBLOCK
%11 = or i32 %9, %10
%12 = call i32 @open(i8* %8, i32 %11)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
ret i32 1
17: ; preds = %0
br label %18
18: ; preds = %17, %32
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i32 0, i32 80)
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%22 = call i32 @strcpy(i8* %21, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* %4
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%25 = call i32 @write(i32 %23, i8* %24, i32 80)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %18
%28 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %32
29: ; preds = %18
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%31 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %29, %27
%33 = call i32 @sleep(i32 2)
br label %18
}

LLVM IR (-O2):
@__const.main.FIFO = [5 x i8] c"FIFO\00"
@O_WRONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str = [17 x i8] c"cannot open fifo\00"
@.str.1 = [12 x i8] c"Hello world\00"
@.str.2 = [17 x i8] c"write data error\00"
@.str.3 = [27 x i8] c"write to fifo data is: %s\0A\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = alloca [5 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 80)
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* @O_WRONLY
%7 = load i32, i32* @O_NONBLOCK
%8 = or i32 %7, %6
%9 = call i32 @open(i8* %5, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
ret i32 1
13: ; preds = %0, %22
%14 = call i32 @memset(i8* %3, i32 0, i32 80)
%15 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @write(i32 %9, i8* %3, i32 80)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %22
20: ; preds = %13
%21 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %3)
br label %22
22: ; preds = %20, %18
%23 = call i32 @sleep(i32 2)
br label %13
}