#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*/ O_WRONLY;
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ sleep(int);
int write(int, char *, int);
int main(void) {
  char msg[64];
  int fd, cnt;
  if ((fd = open("./fifo", O_WRONLY)) < 0) {
    printf("fail to open fifo file\n");
    exit(1);
  }
  for (cnt = 0; cnt < 3; cnt++) {
    printf("input a message: ");
    scanf("%s", msg);
    if (write(fd, msg, 64) == -1) {
      printf("fail to write to fifo\n");
      exit(1);
    }
    sleep(1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x54(%rbp)
cmp    $0x0,%eax
jge    11a6 <main+0x46>
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x58(%rbp)
cmpl   $0x3,-0x58(%rbp)
jge    121b <main+0xbb>
lea    0xe61(%rip),%rdi
call   1040 <printf@plt>
lea    -0x50(%rbp),%rsi
lea    0xe63(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x54(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x40,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1203 <main+0xa3>
lea    0xe40(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    11ad <main+0x4d>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
lea    0xe79(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     1261 <main+0xf1>
mov    %eax,%ebx
lea    0xe6a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe70(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
call   1060 <scanf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     1258 <main+0xe8>
mov    $0x1,%edi
call   1090 <sleep@plt>
lea    0xe2a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe30(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
call   1060 <scanf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     1258 <main+0xe8>
mov    $0x1,%edi
call   1090 <sleep@plt>
lea    0xdee(%rip),%rdi
call   1050 <printf@plt>
lea    0xdf4(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
call   1060 <scanf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     1258 <main+0xe8>
mov    $0x1,%edi
call   1090 <sleep@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdbd(%rip),%rdi
jmp    1268 <main+0xf8>
lea    0xdca(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"./fifo\00"
@O_WRONLY = global i32 0
@.str.1 = [24 x i8] c"fail to open fifo file\0A\00"
@.str.2 = [18 x i8] c"input a message: \00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [23 x i8] c"fail to write to fifo\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [64 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @O_WRONLY
%6 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
store i32 0, i32* %4
br label %12
12: ; preds = %28, %11
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %31
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%19 = load i32, i32* %3
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%21 = call i32 @write(i32 %19, i8* %20, i32 64)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %15
%27 = call i32 @sleep(i32 1)
br label %28
28: ; preds = %26
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %12
31: ; preds = %12
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [7 x i8] c"./fifo\00"
@O_WRONLY = global i32 0
@.str.2 = [18 x i8] c"input a message: \00"
@.str.3 = [3 x i8] c"%s\00"
@str = [22 x i8] c"fail to write to fifo\00"
@str.5 = [23 x i8] c"fail to open fifo file\00"
define i32 @main() {
%1 = alloca [64 x i8]
%2 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %0
%7 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%9 = call i32 @write(i32 %4, i8* %2, i32 64)
%10 = icmp eq i32 %9, -1
br i1 %10, label %14, label %17
11: ; preds = %0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.5, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %23, %17, %6
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %6
%18 = call i32 @sleep(i32 1)
%19 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%21 = call i32 @write(i32 %4, i8* %2, i32 64)
%22 = icmp eq i32 %21, -1
br i1 %22, label %14, label %23
23: ; preds = %17
%24 = call i32 @sleep(i32 1)
%25 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%27 = call i32 @write(i32 %4, i8* %2, i32 64)
%28 = icmp eq i32 %27, -1
br i1 %28, label %14, label %29
29: ; preds = %23
%30 = call i32 @sleep(i32 1)
ret i32 0
}