#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ EEXIST;
int O_NONBLOCK;
int O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ S_ISFIFO(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ feof(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ fstat(int, struct stat *);
scalar_t__ mkfifo(char *, int);
int open(char *, int, int /*<<< orphan*/);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  char *fifo_file_name;
  char buf[16384];
  struct stat st;
  int fdr = 0, fdw = 0, n;
  if (argc < 2) {
    fifo_file_name = "/tmp/audio";
  } else {
    fifo_file_name = argv[1];
  }
  if (mkfifo(fifo_file_name, 0666) < 0 && errno != EEXIST) {
    fprintf(stderr, "error creating fifo buffer: %d\n", errno);
    goto err;
  }
  if ((fdr = open(fifo_file_name, O_RDONLY | O_NONBLOCK, 0)) < 0) {
    fprintf(stderr, "error opening fifo buffer read only: %d\n", errno);
    goto err;
  }
  if ((fdw = open(fifo_file_name, O_WRONLY | O_NONBLOCK, 0)) < 0) {
    fprintf(stderr, "error opening fifo buffer write only: %d\n", errno);
    goto err;
  }
  if (fstat(fdw, &st) < 0) {
    fprintf(stderr, "error running fstat on fifo buffer: %d\n", errno);
    goto err;
  }
  if (!S_ISFIFO(st.st_mode)) {
    fprintf(stderr, "%s is no a fifo buffer\n", fifo_file_name);
    goto err;
  }
  while (!feof(stdin) && (n = read(STDIN_FILENO, buf, 16384)) > 0) {
    write(fdw, buf, n);
  }
  close(fdr);
  close(fdw);
  return 0;
err:
  close(fdr);
  close(fdw);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x402c(%rbp)
movl   $0x0,-0x4030(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11d7 <main+0x47>
lea    0xe32(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11e3 <main+0x53>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1b6,%esi
call   1090 <mkfifo@plt>
cmp    $0x0,%rax
jge    1239 <main+0xa9>
mov    0x2db6(%rip),%rax
mov    (%rax),%rax
mov    0x2dbc(%rip),%rcx
cmp    (%rcx),%rax
je     1239 <main+0xa9>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
mov    0x2d93(%rip),%rax
mov    (%rax),%rdx
lea    0xddc(%rip),%rsi
call   1070 <fprintf@plt>
jmp    13ef <main+0x25f>
mov    -0x18(%rbp),%rdi
mov    0x2d9c(%rip),%rax
mov    (%rax),%esi
mov    0x2d9b(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   10a0 <open@plt>
mov    %eax,-0x402c(%rbp)
cmp    $0x0,%eax
jge    1289 <main+0xf9>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
mov    0x2d43(%rip),%rax
mov    (%rax),%rdx
lea    0xdac(%rip),%rsi
call   1070 <fprintf@plt>
jmp    13ef <main+0x25f>
mov    -0x18(%rbp),%rdi
mov    0x2d0c(%rip),%rax
mov    (%rax),%esi
mov    0x2d4b(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   10a0 <open@plt>
mov    %eax,-0x4030(%rbp)
cmp    $0x0,%eax
jge    12d9 <main+0x149>
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
mov    0x2cf3(%rip),%rax
mov    (%rax),%rdx
lea    0xd85(%rip),%rsi
call   1070 <fprintf@plt>
jmp    13ef <main+0x25f>
mov    -0x4030(%rbp),%edi
lea    -0x4028(%rbp),%rsi
call   10b0 <fstat@plt>
cmp    $0x0,%rax
jge    1319 <main+0x189>
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
mov    0x2cb3(%rip),%rax
mov    (%rax),%rdx
lea    0xd6f(%rip),%rsi
call   1070 <fprintf@plt>
jmp    13ef <main+0x25f>
mov    -0x4028(%rbp),%edi
call   1040 <S_ISFIFO@plt>
cmp    $0x0,%eax
jne    134b <main+0x1bb>
mov    0x2c8c(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd65(%rip),%rsi
call   1070 <fprintf@plt>
jmp    13ef <main+0x25f>
jmp    1350 <main+0x1c0>
mov    0x2c81(%rip),%rax
mov    (%rax),%edi
call   1080 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x4035(%rbp)
jne    139d <main+0x20d>
mov    0x2c38(%rip),%rax
mov    (%rax),%edi
lea    -0x4020(%rbp),%rsi
mov    $0x4000,%edx
call   1060 <read@plt>
mov    %eax,-0x4034(%rbp)
cmp    $0x0,%eax
setg   %al
mov    %al,-0x4035(%rbp)
mov    -0x4035(%rbp),%al
test   $0x1,%al
jne    13b0 <main+0x220>
jmp    13cd <main+0x23d>
mov    -0x4030(%rbp),%edi
lea    -0x4020(%rbp),%rsi
mov    -0x4034(%rbp),%edx
call   1030 <write@plt>
jmp    1350 <main+0x1c0>
mov    -0x402c(%rbp),%edi
call   1050 <close@plt>
mov    -0x4030(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    140c <main+0x27c>
mov    -0x402c(%rbp),%edi
call   1050 <close@plt>
mov    -0x4030(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4018,%rsp
cmp    $0x2,%edi
jge    11af <main+0x1f>
lea    0xe53(%rip),%rbx
jmp    11b3 <main+0x23>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
mov    $0x1b6,%esi
call   1090 <mkfifo@plt>
test   %rax,%rax
jns    11df <main+0x4f>
mov    0x2dec(%rip),%rax
mov    (%rax),%rdx
mov    0x2df2(%rip),%rax
cmp    (%rax),%rdx
jne    12d3 <main+0x143>
mov    0x2dfa(%rip),%rax
mov    0x2dfb(%rip),%rbp
mov    0x0(%rbp),%esi
or     (%rax),%esi
xor    %r13d,%r13d
mov    %rbx,%rdi
xor    %edx,%edx
call   10a0 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
js     12b7 <main+0x127>
mov    0x2d8f(%rip),%rax
mov    0x0(%rbp),%esi
or     (%rax),%esi
mov    %rbx,%rdi
xor    %edx,%edx
call   10a0 <open@plt>
mov    %eax,%r13d
test   %eax,%eax
js     12f5 <main+0x165>
lea    0x8(%rsp),%rsi
mov    %r13d,%edi
call   10b0 <fstat@plt>
test   %rax,%rax
js     1311 <main+0x181>
mov    0x8(%rsp),%edi
call   1040 <S_ISFIFO@plt>
test   %eax,%eax
je     132d <main+0x19d>
mov    0x2d7f(%rip),%r12
mov    (%r12),%edi
call   1080 <feof@plt>
xor    %ebx,%ebx
test   %eax,%eax
jne    134a <main+0x1ba>
mov    0x2d3d(%rip),%rbp
lea    0x10(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%edi
mov    %r15,%rsi
mov    $0x4000,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    134a <main+0x1ba>
mov    %r13d,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    (%r12),%edi
call   1080 <feof@plt>
test   %eax,%eax
je     1280 <main+0xf0>
jmp    134a <main+0x1ba>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
mov    0x2cf1(%rip),%rax
mov    (%rax),%rdx
lea    0xd5a(%rip),%rsi
jmp    1340 <main+0x1b0>
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
lea    0xd28(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%ebx
xor    %r14d,%r14d
xor    %r13d,%r13d
jmp    134a <main+0x1ba>
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
mov    0x2cb3(%rip),%rax
mov    (%rax),%rdx
lea    0xd45(%rip),%rsi
jmp    1340 <main+0x1b0>
mov    0x2ca8(%rip),%rax
mov    (%rax),%edi
mov    0x2c97(%rip),%rax
mov    (%rax),%rdx
lea    0xd53(%rip),%rsi
jmp    1340 <main+0x1b0>
mov    0x2c8c(%rip),%rax
mov    (%rax),%edi
lea    0xd69(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    $0x1,%ebx
mov    %r14d,%edi
call   1050 <close@plt>
mov    %r13d,%edi
call   1050 <close@plt>
mov    %ebx,%eax
add    $0x4018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [11 x i8] c"/tmp/audio\00"
@errno = global i64 0
@EEXIST = global i64 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"error creating fifo buffer: %d\0A\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.2 = [41 x i8] c"error opening fifo buffer read only: %d\0A\00"
@O_WRONLY = global i32 0
@.str.3 = [42 x i8] c"error opening fifo buffer write only: %d\0A\00"
@.str.4 = [40 x i8] c"error running fstat on fifo buffer: %d\0A\00"
@.str.5 = [24 x i8] c"%s is no a fifo buffer\0A\00"
@stdin = global i32 0
@STDIN_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [16384 x i8]
%8 = alloca %struct.stat
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
store i32 0, i32* %10
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %15
14: ; preds = %2
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %6
br label %19
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %6
br label %19
19: ; preds = %15, %14
%20 = load i8*, i8** %6
%21 = call i64 @mkfifo(i8* %20, i32 438)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %19
%24 = load i64, i64* @errno
%25 = load i64, i64* @EEXIST
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = load i64, i64* @errno
%30 = inttoptr i64 %29 to i8*
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %30)
br label %96
32: ; preds = %23, %19
%33 = load i8*, i8** %6
%34 = load i32, i32* @O_RDONLY
%35 = load i32, i32* @O_NONBLOCK
%36 = or i32 %34, %35
%37 = call i32 @open(i8* %33, i32 %36, i32 0)
store i32 %37, i32* %9
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %32
%40 = load i32, i32* @stderr
%41 = load i64, i64* @errno
%42 = inttoptr i64 %41 to i8*
%43 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %42)
br label %96
44: ; preds = %32
%45 = load i8*, i8** %6
%46 = load i32, i32* @O_WRONLY
%47 = load i32, i32* @O_NONBLOCK
%48 = or i32 %46, %47
%49 = call i32 @open(i8* %45, i32 %48, i32 0)
store i32 %49, i32* %10
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %44
%52 = load i32, i32* @stderr
%53 = load i64, i64* @errno
%54 = inttoptr i64 %53 to i8*
%55 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %54)
br label %96
56: ; preds = %44
%57 = load i32, i32* %10
%58 = call i64 @fstat(i32 %57, %struct.stat* %8)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %56
%61 = load i32, i32* @stderr
%62 = load i64, i64* @errno
%63 = inttoptr i64 %62 to i8*
%64 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %63)
br label %96
65: ; preds = %56
%66 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%67 = load i32, i32* %66
%68 = call i32 @S_ISFIFO(i32 %67)
%69 = icmp ne i32 %68, 0
br i1 %69, label %74, label %70
70: ; preds = %65
%71 = load i32, i32* @stderr
%72 = load i8*, i8** %6
%73 = call i32 @fprintf(i32 %71, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %72)
br label %96
74: ; preds = %65
br label %75
75: ; preds = %86, %74
%76 = load i32, i32* @stdin
%77 = call i32 @feof(i32 %76)
%78 = icmp ne i32 %77, 0
br i1 %78, label %84, label %79
79: ; preds = %75
%80 = load i32, i32* @STDIN_FILENO
%81 = getelementptr inbounds [16384 x i8], [16384 x i8]* %7, i64 0, i64 0
%82 = call i32 @read(i32 %80, i8* %81, i32 16384)
store i32 %82, i32* %11
%83 = icmp sgt i32 %82, 0
br label %84
84: ; preds = %79, %75
%85 = phi i1 [ false, %75 ], [ %83, %79 ]
br i1 %85, label %86, label %91
86: ; preds = %84
%87 = load i32, i32* %10
%88 = getelementptr inbounds [16384 x i8], [16384 x i8]* %7, i64 0, i64 0
%89 = load i32, i32* %11
%90 = call i32 @write(i32 %87, i8* %88, i32 %89)
br label %75
91: ; preds = %84
%92 = load i32, i32* %9
%93 = call i32 @close(i32 %92)
%94 = load i32, i32* %10
%95 = call i32 @close(i32 %94)
store i32 0, i32* %3
br label %101
96: ; preds = %70, %60, %51, %39, %27
%97 = load i32, i32* %9
%98 = call i32 @close(i32 %97)
%99 = load i32, i32* %10
%100 = call i32 @close(i32 %99)
store i32 1, i32* %3
br label %101
101: ; preds = %96, %91
%102 = load i32, i32* %3
ret i32 %102
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [11 x i8] c"/tmp/audio\00"
@errno = global i64 0
@EEXIST = global i64 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"error creating fifo buffer: %d\0A\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.2 = [41 x i8] c"error opening fifo buffer read only: %d\0A\00"
@O_WRONLY = global i32 0
@.str.3 = [42 x i8] c"error opening fifo buffer write only: %d\0A\00"
@.str.4 = [40 x i8] c"error running fstat on fifo buffer: %d\0A\00"
@.str.5 = [24 x i8] c"%s is no a fifo buffer\0A\00"
@stdin = global i32 0
@STDIN_FILENO = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [16384 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [16384 x i8], [16384 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.stat* %4 to i8*
%7 = icmp slt i32 %0, 2
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
br label %11
11: ; preds = %2, %8
%12 = phi i8* [ %10, %8 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %2 ]
%13 = tail call i64 @mkfifo(i8* %12, i32 438)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = load i64, i64* @errno
%17 = load i64, i64* @EEXIST
%18 = icmp eq i64 %16, %17
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = inttoptr i64 %16 to i8*
%22 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %74
23: ; preds = %15, %11
%24 = load i32, i32* @O_RDONLY
%25 = load i32, i32* @O_NONBLOCK
%26 = or i32 %25, %24
%27 = tail call i32 @open(i8* %12, i32 %26, i32 0)
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %23
%30 = load i32, i32* @stderr
%31 = load i64, i64* @errno
%32 = inttoptr i64 %31 to i8*
%33 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %74
34: ; preds = %23
%35 = load i32, i32* @O_WRONLY
%36 = load i32, i32* @O_NONBLOCK
%37 = or i32 %36, %35
%38 = tail call i32 @open(i8* %12, i32 %37, i32 0)
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %34
%41 = load i32, i32* @stderr
%42 = load i64, i64* @errno
%43 = inttoptr i64 %42 to i8*
%44 = tail call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %43)
br label %74
45: ; preds = %34
%46 = call i64 @fstat(i32 %38, %struct.stat* %4)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %45
%49 = load i32, i32* @stderr
%50 = load i64, i64* @errno
%51 = inttoptr i64 %50 to i8*
%52 = tail call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %51)
br label %74
53: ; preds = %45
%54 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%55 = load i32, i32* %54
%56 = tail call i32 @S_ISFIFO(i32 %55)
%57 = icmp eq i32 %56, 0
br i1 %57, label %62, label %58
58: ; preds = %53
%59 = load i32, i32* @stdin
%60 = tail call i32 @feof(i32 %59)
%61 = icmp eq i32 %60, 0
br i1 %61, label %65, label %74
62: ; preds = %53
%63 = load i32, i32* @stderr
%64 = tail call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %12)
br label %74
65: ; preds = %58, %69
%66 = load i32, i32* @STDIN_FILENO
%67 = call i32 @read(i32 %66, i8* %5, i32 16384)
%68 = icmp sgt i32 %67, 0
br i1 %68, label %69, label %74
69: ; preds = %65
%70 = call i32 @write(i32 %38, i8* %5, i32 %67)
%71 = load i32, i32* @stdin
%72 = tail call i32 @feof(i32 %71)
%73 = icmp eq i32 %72, 0
br i1 %73, label %65, label %74
74: ; preds = %69, %65, %19, %29, %40, %48, %62, %58
%75 = phi i32 [ %27, %58 ], [ 0, %19 ], [ %27, %29 ], [ %27, %40 ], [ %27, %48 ], [ %27, %62 ], [ %27, %65 ], [ %27, %69 ]
%76 = phi i32 [ %38, %58 ], [ 0, %19 ], [ 0, %29 ], [ %38, %40 ], [ %38, %48 ], [ %38, %62 ], [ %38, %65 ], [ %38, %69 ]
%77 = phi i32 [ 0, %58 ], [ 1, %19 ], [ 1, %29 ], [ 1, %40 ], [ 1, %48 ], [ 1, %62 ], [ 0, %65 ], [ 0, %69 ]
%78 = tail call i32 @close(i32 %75)
%79 = tail call i32 @close(i32 %76)
ret i32 %77
}