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

/* Variables and functions */
int O_CREAT;
int O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ mkfifo(char *, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  mkfifo("in.fifo", 0666);
  mkfifo("out.fifo", 0666);
  int fifo_in = open("in.fifo", O_RDONLY | O_CREAT);
  int fifo_out = open("out.fifo", O_WRONLY | O_CREAT);
  char buf[512];
  ssize_t r;
  while ((r = read(fifo_in, buf, 10)) > 0) {
    printf("Read %zu: %s\n", r, buf);
    write(fifo_out, buf, r);
  }
  close(fifo_in);
  close(fifo_out);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe80(%rip),%rdi
mov    $0x1b6,%esi
call   1070 <mkfifo@plt>
lea    0xe77(%rip),%rdi
mov    $0x1b6,%esi
call   1070 <mkfifo@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
mov    0x2e4d(%rip),%rax
or     (%rax),%esi
lea    0xe4c(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
mov    0x2e2c(%rip),%rax
or     (%rax),%esi
lea    0xe33(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0xa,%edx
call   1060 <read@plt>
mov    %eax,-0x224(%rbp)
cmp    $0x0,%eax
jle    1233 <main+0xd3>
mov    -0x224(%rbp),%esi
lea    -0x220(%rbp),%rdx
lea    0xdfd(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    -0x224(%rbp),%edx
call   1030 <write@plt>
jmp    11dd <main+0x7d>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
lea    0xe8a(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1b6,%esi
call   1070 <mkfifo@plt>
lea    0xe7e(%rip),%r14
mov    %r14,%rdi
mov    $0x1b6,%esi
call   1070 <mkfifo@plt>
mov    0x2e42(%rip),%rax
mov    0x2e53(%rip),%rbp
mov    0x0(%rbp),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
mov    %eax,%r15d
mov    0x2e0c(%rip),%rax
mov    0x0(%rbp),%esi
or     (%rax),%esi
mov    %r14,%rdi
call   1080 <open@plt>
mov    %eax,%r12d
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0xa,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    1220 <main+0xc0>
mov    %eax,%ebp
lea    0xe28(%rip),%r14
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
call   1040 <printf@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1060 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     11f0 <main+0x90>
mov    %r15d,%edi
call   1050 <close@plt>
mov    %r12d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"in.fifo\00"
@.str.1 = [9 x i8] c"out.fifo\00"
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@.str.2 = [14 x i8] c"Read %zu: %s\0A\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 [512 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 @mkfifo(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 438)
%11 = call i32 @mkfifo(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 438)
%12 = load i32, i32* @O_RDONLY
%13 = load i32, i32* @O_CREAT
%14 = or i32 %12, %13
%15 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* @O_WRONLY
%17 = load i32, i32* @O_CREAT
%18 = or i32 %16, %17
%19 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %18)
store i32 %19, i32* %7
br label %20
20: ; preds = %25, %2
%21 = load i32, i32* %6
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%23 = call i32 @read(i32 %21, i8* %22, i32 10)
store i32 %23, i32* %9
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %20
%26 = load i32, i32* %9
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%28 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %26, i8* %27)
%29 = load i32, i32* %7
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%31 = load i32, i32* %9
%32 = call i32 @write(i32 %29, i8* %30, i32 %31)
br label %20
33: ; preds = %20
%34 = load i32, i32* %6
%35 = call i32 @close(i32 %34)
%36 = load i32, i32* %7
%37 = call i32 @close(i32 %36)
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [8 x i8] c"in.fifo\00"
@.str.1 = [9 x i8] c"out.fifo\00"
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@.str.2 = [14 x i8] c"Read %zu: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [512 x i8]
%4 = tail call i32 @mkfifo(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 438)
%5 = tail call i32 @mkfifo(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 438)
%6 = load i32, i32* @O_RDONLY
%7 = load i32, i32* @O_CREAT
%8 = or i32 %7, %6
%9 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @O_WRONLY
%11 = load i32, i32* @O_CREAT
%12 = or i32 %11, %10
%13 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%15 = call i32 @read(i32 %9, i8* %14, i32 10)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %2, %17
%18 = phi i32 [ %21, %17 ], [ %15, %2 ]
%19 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %18, i8* %14)
%20 = call i32 @write(i32 %13, i8* %14, i32 %18)
%21 = call i32 @read(i32 %9, i8* %14, i32 10)
%22 = icmp sgt i32 %21, 0
br i1 %22, label %17, label %23
23: ; preds = %17, %2
%24 = call i32 @close(i32 %9)
%25 = call i32 @close(i32 %13)
ret i32 0
}