#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 /*<<< orphan*/ O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ write(int, char *, scalar_t__);
int main(void) {
  char buffer[128];
  char fifoname[] = "myfifo";
  int fifofd;
  mkfifo(fifoname, S_IRUSR | S_IWUSR);
  fifofd = open(fifoname, O_WRONLY);
  printf("Type in 'exit' to quit:\n");
  do {
    fgets(buffer, sizeof(buffer), stdin);
    write(fifofd, buffer, strlen(buffer) + 1);
  } while (strcmp(buffer, "exit\n") != 0);
  close(fifofd);
  unlink(fifoname);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe58(%rip),%eax
mov    %eax,-0x97(%rbp)
mov    0xe4f(%rip),%ax
mov    %ax,-0x93(%rbp)
mov    0xe44(%rip),%al
mov    %al,-0x91(%rbp)
lea    -0x97(%rbp),%rdi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
mov    0x2e01(%rip),%rax
or     (%rax),%esi
call   10a0 <mkfifo@plt>
lea    -0x97(%rbp),%rdi
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x9c(%rbp)
lea    0xdff(%rip),%rdi
call   1060 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    0x2dcd(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1080 <fgets@plt>
mov    -0x9c(%rbp),%eax
mov    %eax,-0xac(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0x90(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xac(%rbp),%edi
mov    -0xa8(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <write@plt>
lea    -0x90(%rbp),%rdi
lea    0xdac(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    120d <main+0x7d>
mov    -0x9c(%rbp),%edi
call   1070 <close@plt>
lea    -0x97(%rbp),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x98,%rsp
movl   $0x6f6669,0xb(%rsp)
movl   $0x6966796d,0x8(%rsp)
69
mov    0x2e1c(%rip),%rax
mov    0x2e25(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <mkfifo@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10b0 <open@plt>
mov    %eax,%ebp
lea    0xe27(%rip),%rdi
call   1040 <puts@plt>
mov    0x2df6(%rip),%r15
lea    0x10(%rsp),%rbx
lea    0xe09(%rip),%r14
xchg   %ax,%ax
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1080 <fgets@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <write@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    1200 <main+0x70>
mov    %ebp,%edi
call   1070 <close@plt>
lea    0x8(%rsp),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.fifoname = [7 x i8] c"myfifo\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@O_WRONLY = global i32 0
@.str = [25 x i8] c"Type in 'exit' to quit:\0A\00"
@stdin = global i32 0
@.str.1 = [6 x i8] c"exit\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = alloca [7 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [7 x i8]* %3 to i8*
%6 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @S_IRUSR
%8 = load i32, i32* @S_IWUSR
%9 = or i32 %7, %8
%10 = call i32 @mkfifo(i8* %6, i32 %9)
%11 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%12 = load i32, i32* @O_WRONLY
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %4
%14 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %25, %0
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%17 = load i32, i32* @stdin
%18 = call i32 @fgets(i8* %16, i32 128, i32 %17)
%19 = load i32, i32* %4
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%22 = call i64 @strlen(i8* %21)
%23 = add nsw i64 %22, 1
%24 = call i32 @write(i32 %19, i8* %20, i64 %23)
br label %25
25: ; preds = %15
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp ne i64 %27, 0
br i1 %28, label %15, label %29
29: ; preds = %25
%30 = load i32, i32* %4
%31 = call i32 @close(i32 %30)
%32 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%33 = call i32 @unlink(i8* %32)
ret i32 0
}

LLVM IR (-O2):
@__const.main.fifoname = [7 x i8] c"myfifo\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@O_WRONLY = global i32 0
@stdin = global i32 0
@.str.1 = [6 x i8] c"exit\0A\00"
@str = [24 x i8] c"Type in 'exit' to quit:\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = alloca [7 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @S_IRUSR
%6 = load i32, i32* @S_IWUSR
%7 = or i32 %6, %5
%8 = call i32 @mkfifo(i8* %4, i32 %7)
%9 = load i32, i32* @O_WRONLY
%10 = call i32 @open(i8* %4, i32 %9)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %12
12: ; preds = %12, %0
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %3, i32 128, i32 %13)
%15 = call i64 @strlen(i8* %3)
%16 = add nsw i64 %15, 1
%17 = call i32 @write(i32 %10, i8* %3, i64 %16)
%18 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %12
20: ; preds = %12
%21 = call i32 @close(i32 %10)
%22 = call i32 @unlink(i8* %4)
ret i32 0
}