#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 */
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ mkfifo(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ unlink(char *);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("simplefifo listen or simplefifo send\n");
    return -1;
  }
  mkfifo("/tmp/simplefifo", 0666);
  FILE *in;
  FILE *out;
  if (strcmp(argv[1], "listen") == 0) {
    in = fopen("/tmp/simplefifo", "r");
    out = stdout;
  } else if (strcmp(argv[1], "send") == 0) {
    in = stdin;
    out = fopen("/tmp/simplefifo", "w");
  } else {
    printf("simplefifo listen or simplefifo send\n");
    return -1;
  }
  char *buf = NULL;
  size_t n = 0;
  while (getline(&buf, &n, in) > 0) {
    fputs(buf, out);
    fflush(out);
  }
  unlink("/tmp/simplefifo");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b8 <main+0x38>
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12cf <main+0x14f>
lea    0xe67(%rip),%rdi
mov    $0x1b6,%esi
call   1070 <mkfifo@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5e(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1211 <main+0x91>
lea    0xe38(%rip),%rdi
lea    0xe48(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    0x2dd3(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1276 <main+0xf6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1259 <main+0xd9>
mov    0x2db2(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
lea    0xde2(%rip),%rdi
lea    0xdf9(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
jmp    1271 <main+0xf1>
lea    0xda0(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12cf <main+0x14f>
jmp    1276 <main+0xf6>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   10a0 <getline@plt>
cmp    $0x0,%rax
jle    12bc <main+0x13c>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x20(%rbp),%rdi
call   1080 <fflush@plt>
jmp    1286 <main+0x106>
lea    0xd63(%rip),%rdi
call   1030 <unlink@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    11ce <main+0x4e>
mov    %rsi,%rbx
lea    0xe66(%rip),%rdi
mov    $0x1b6,%esi
call   1070 <mkfifo@plt>
mov    0x8(%rbx),%rdi
lea    0xe61(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11e4 <main+0x64>
mov    0x8(%rbx),%rdi
lea    0xe77(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1206 <main+0x86>
lea    0xe46(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
jmp    1296 <main+0x116>
lea    0xe15(%rip),%rdi
lea    0xe25(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
mov    0x2dd7(%rip),%rax
mov    (%rax),%rbx
jmp    1226 <main+0xa6>
mov    0x2ddb(%rip),%rax
mov    (%rax),%r14
lea    0xde9(%rip),%rdi
lea    0xdfb(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r14,%rdx
call   10a0 <getline@plt>
test   %rax,%rax
jle    1288 <main+0x108>
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
nopl   0x0(%rax)
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   10a0 <getline@plt>
test   %rax,%rax
jg     1260 <main+0xe0>
lea    0xd71(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [38 x i8] c"simplefifo listen or simplefifo send\0A\00"
@.str.1 = [16 x i8] c"/tmp/simplefifo\00"
@.str.2 = [7 x i8] c"listen\00"
@.str.3 = [2 x i8] c"r\00"
@stdout = global i32* null
@.str.4 = [5 x i8] c"send\00"
@stdin = global i32* null
@.str.5 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %49
14: ; preds = %2
%15 = call i32 @mkfifo(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 438)
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %22, i32** %6
%23 = load i32*, i32** @stdout
store i32* %23, i32** %7
br label %36
24: ; preds = %14
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = load i32*, i32** @stdin
store i32* %31, i32** %6
%32 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %32, i32** %7
br label %35
33: ; preds = %24
%34 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %49
35: ; preds = %30
br label %36
36: ; preds = %35, %21
store i8* null, i8** %8
store i64 0, i64* %9
br label %37
37: ; preds = %41, %36
%38 = load i32*, i32** %6
%39 = call i64 @getline(i8** %8, i64* %9, i32* %38)
%40 = icmp sgt i64 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %37
%42 = load i8*, i8** %8
%43 = load i32*, i32** %7
%44 = call i32 @fputs(i8* %42, i32* %43)
%45 = load i32*, i32** %7
%46 = call i32 @fflush(i32* %45)
br label %37
47: ; preds = %37
%48 = call i32 @unlink(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %49
49: ; preds = %47, %33, %12
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str.1 = [16 x i8] c"/tmp/simplefifo\00"
@.str.2 = [7 x i8] c"listen\00"
@.str.3 = [2 x i8] c"r\00"
@stdout = global i32* null
@.str.4 = [5 x i8] c"send\00"
@stdin = global i32* null
@.str.5 = [2 x i8] c"w\00"
@str.6 = [37 x i8] c"simplefifo listen or simplefifo send\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = icmp eq i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.6, i64 0, i64 0))
br label %41
8: ; preds = %2
%9 = tail call i32 @mkfifo(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 438)
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%16 = load i32*, i32** @stdout
br label %26
17: ; preds = %8
%18 = load i8*, i8** %10
%19 = tail call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32*, i32** @stdin
%23 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %26
24: ; preds = %17
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.6, i64 0, i64 0))
br label %41
26: ; preds = %21, %14
%27 = phi i32* [ %15, %14 ], [ %22, %21 ]
%28 = phi i32* [ %16, %14 ], [ %23, %21 ]
%29 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%30 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%31 = call i64 @getline(i8** %3, i64* %4, i32* %27)
%32 = icmp sgt i64 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %26, %33
%34 = load i8*, i8** %3
%35 = call i32 @fputs(i8* %34, i32* %28)
%36 = call i32 @fflush(i32* %28)
%37 = call i64 @getline(i8** %3, i64* %4, i32* %27)
%38 = icmp sgt i64 %37, 0
br i1 %38, label %33, label %39
39: ; preds = %33, %26
%40 = call i32 @unlink(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %41
41: ; preds = %24, %39, %6
%42 = phi i32 [ -1, %6 ], [ 0, %39 ], [ -1, %24 ]
ret i32 %42
}