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

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int open(char *, int, ...);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int pipe = open("fifo", O_RDONLY);
  int log = open("log", O_WRONLY | O_CREAT | O_TRUNC, 0666);
  char buf;
  while (1) {
    while (read(pipe, &buf, 1)) {
      write(log, &buf, 1);
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    0x2e88(%rip),%rax
or     (%rax),%esi
mov    0x2e77(%rip),%rax
or     (%rax),%esi
lea    0xe83(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x0,%al
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
jmp    1196 <main+0x66>
mov    -0x14(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
je     11c7 <main+0x97>
mov    -0x18(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1196 <main+0x66>
jmp    1191 <main+0x61>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0xeb8(%rip),%rdi
xor    %eax,%eax
call   1050 <open@plt>
mov    0x2e6a(%rip),%rcx
mov    0x2e9b(%rip),%rdx
mov    (%rdx),%esi
or     (%rcx),%esi
mov    %eax,%r14d
mov    0x2e85(%rip),%rax
or     (%rax),%esi
lea    0xe91(%rip),%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   1050 <open@plt>
mov    %eax,%ebp
lea    0xf(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
test   %rax,%rax
je     1190 <main+0x60>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
test   %rax,%rax
jne    11b0 <main+0x80>
jmp    1190 <main+0x60>

LLVM IR (-O0):
@.str = [5 x i8] c"fifo\00"
@O_RDONLY = global i32 0
@.str.1 = [4 x i8] c"log\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @O_RDONLY
%10 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %6
%11 = load i32, i32* @O_WRONLY
%12 = load i32, i32* @O_CREAT
%13 = or i32 %11, %12
%14 = load i32, i32* @O_TRUNC
%15 = or i32 %13, %14
%16 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 438)
store i32 %16, i32* %7
br label %17
17: ; preds = %2, %25
br label %18
18: ; preds = %22, %17
%19 = load i32, i32* %6
%20 = call i64 @read(i32 %19, i8* %8, i32 1)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* %7
%24 = call i32 @write(i32 %23, i8* %8, i32 1)
br label %18
25: ; preds = %18
br label %17
}

LLVM IR (-O2):
@.str = [5 x i8] c"fifo\00"
@O_RDONLY = global i32 0
@.str.1 = [4 x i8] c"log\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @O_WRONLY
%7 = load i32, i32* @O_CREAT
%8 = or i32 %7, %6
%9 = load i32, i32* @O_TRUNC
%10 = or i32 %8, %9
%11 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 438)
br label %12
12: ; preds = %15, %2
%13 = call i64 @read(i32 %5, i8* %3, i32 1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %16, %12
br label %12
16: ; preds = %12, %16
%17 = call i32 @write(i32 %11, i8* %3, i32 1)
%18 = call i64 @read(i32 %5, i8* %3, i32 1)
%19 = icmp eq i64 %18, 0
br i1 %19, label %15, label %16
}