#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*/ FILE;

/* Variables and functions */
scalar_t__ EEXIST;
int S_IFIFO;
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ gets(char *);
scalar_t__ mkfifo(char *, int);
int /*<<< orphan*/ printf(char *);
scalar_t__ strncmp(char *, char *, int);
int main() {
  FILE *fp;
  char buf[255];
  if (mkfifo("myfifo", S_IFIFO | 0666) < 0 && errno != EEXIST)
    return 0;
  while (1) {
    if ((fp = fopen("myfifo", "w")) == NULL)
      return 0;
    printf("please input:");
    gets(buf);
    fputs(buf, fp);
    fputs("\n", fp);
    if (strncmp(buf, "quit", 4) == 0 || strncmp(buf, "exit", 4) == 0)
      break;
    fclose(fp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
lea    0xe68(%rip),%rdi
call   1070 <mkfifo@plt>
cmp    $0x0,%rax
jge    11cd <main+0x5d>
mov    0x2e2a(%rip),%rax
mov    (%rax),%rax
mov    0x2e28(%rip),%rcx
cmp    (%rcx),%rax
je     11cd <main+0x5d>
movl   $0x0,-0x4(%rbp)
jmp    1295 <main+0x125>
jmp    11d2 <main+0x62>
lea    0xe27(%rip),%rdi
lea    0xe27(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11ff <main+0x8f>
movl   $0x0,-0x4(%rbp)
jmp    1295 <main+0x125>
lea    0xe03(%rip),%rdi
call   1050 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1080 <gets@plt>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <fputs@plt>
mov    -0x10(%rbp),%rsi
lea    0xde5(%rip),%rdi
call   1060 <fputs@plt>
lea    -0x110(%rbp),%rdi
lea    0xdd4(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     127b <main+0x10b>
lea    -0x110(%rbp),%rdi
lea    0xdb7(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1280 <main+0x110>
jmp    128e <main+0x11e>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
jmp    11d2 <main+0x62>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    0x2e38(%rip),%rax
mov    $0x1b6,%esi
or     (%rax),%esi
lea    0xe5a(%rip),%rdi
call   1080 <mkfifo@plt>
test   %rax,%rax
jns    11ca <main+0x4a>
mov    0x2e21(%rip),%rax
mov    (%rax),%rax
mov    0x2e1f(%rip),%rcx
cmp    (%rcx),%rax
jne    1281 <main+0x101>
lea    0xe2f(%rip),%rdi
lea    0xe2f(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1281 <main+0x101>
mov    %rax,%rbx
mov    %rsp,%r15
lea    0xe24(%rip),%r12
lea    0xe22(%rip),%r13
lea    0xdff(%rip),%rbp
lea    0xdff(%rip),%r14
nopl   0x0(%rax,%rax,1)
lea    0xdf2(%rip),%rdi
call   1050 <printf@plt>
mov    %r15,%rdi
call   1090 <gets@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <fputs@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1281 <main+0x101>
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1281 <main+0x101>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1210 <main+0x90>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"myfifo\00"
@S_IFIFO = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [14 x i8] c"please input:\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [5 x i8] c"quit\00"
@.str.5 = [5 x i8] c"exit\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [255 x i8]
store i32 0, i32* %1
%4 = load i32, i32* @S_IFIFO
%5 = or i32 %4, 438
%6 = call i64 @mkfifo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %0
%9 = load i64, i64* @errno
%10 = load i64, i64* @EEXIST
%11 = icmp ne i64 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %8
store i32 0, i32* %1
br label %39
13: ; preds = %8, %0
br label %14
14: ; preds = %13, %35
%15 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %2
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 0, i32* %1
br label %39
18: ; preds = %14
%19 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%20 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%21 = call i32 @gets(i8* %20)
%22 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%23 = load i32*, i32** %2
%24 = call i32 @fputs(i8* %22, i32* %23)
%25 = load i32*, i32** %2
%26 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32* %25)
%27 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%28 = call i64 @strncmp(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%29 = icmp eq i64 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %18
%31 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%32 = call i64 @strncmp(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %30, %18
br label %38
35: ; preds = %30
%36 = load i32*, i32** %2
%37 = call i32 @fclose(i32* %36)
br label %14
38: ; preds = %34
store i32 0, i32* %1
br label %39
39: ; preds = %38, %17, %12
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@.str = [7 x i8] c"myfifo\00"
@S_IFIFO = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [14 x i8] c"please input:\00"
@.str.4 = [5 x i8] c"quit\00"
@.str.5 = [5 x i8] c"exit\00"
define i32 @main() {
%1 = alloca [255 x i8]
%2 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @S_IFIFO
%4 = or i32 %3, 438
%5 = tail call i64 @mkfifo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i64, i64* @errno
%9 = load i64, i64* @EEXIST
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %29
11: ; preds = %7, %0
%12 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %29, label %14
14: ; preds = %11, %25
%15 = phi i32* [ %27, %25 ], [ %12, %11 ]
%16 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @gets(i8* %2)
%18 = call i32 @fputs(i8* %2, i32* %15)
%19 = call i32 @fputc(i32 10, i32* %15)
%20 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%21 = icmp eq i64 %20, 0
br i1 %21, label %29, label %22
22: ; preds = %14
%23 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4)
%24 = icmp eq i64 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %22
%26 = call i32 @fclose(i32* %15)
%27 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %14
29: ; preds = %25, %14, %22, %11, %7
ret i32 0
}