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

/* Variables and functions */
int O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main() {
  char buf[10];
  memset(buf, 0, sizeof(buf));
  int fd = open("fifo_file", O_WRONLY | O_RDONLY);
  printf("fd = %d\n", fd);
  while (1) {
    read(STDIN_FILENO, buf, sizeof(buf));
    if (buf[0] == '0') {
      break;
    }
    write(fd, buf, strlen(buf));
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xe(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <memset@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
mov    0x2e49(%rip),%rax
or     (%rax),%esi
lea    0xe58(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe50(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    -0xe(%rbp),%rsi
mov    $0xa,%edx
call   1080 <read@plt>
movsbl -0xe(%rbp),%eax
cmp    $0x30,%eax
jne    11e8 <main+0x78>
jmp    1212 <main+0xa2>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0xe(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0xe(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    11bf <main+0x4f>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xe(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <memset@plt>
mov    0x2e33(%rip),%rax
mov    0x2e4c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe59(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebp
lea    0xe55(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    0x2e15(%rip),%r15
mov    (%r15),%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1080 <read@plt>
cmpb   $0x30,0xe(%rsp)
je     120b <main+0x9b>
lea    0xe(%rsp),%rbx
nop
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    (%r15),%edi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1080 <read@plt>
cmpb   $0x30,0xe(%rsp)
jne    11e0 <main+0x70>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"fifo_file\00"
@O_WRONLY = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [9 x i8] c"fd = %d\0A\00"
@STDIN_FILENO = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 10)
%6 = load i32, i32* @O_WRONLY
%7 = load i32, i32* @O_RDONLY
%8 = or i32 %6, %7
%9 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %0, %21
%13 = load i32, i32* @STDIN_FILENO
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%15 = call i32 @read(i32 %13, i8* %14, i32 10)
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 48
br i1 %19, label %20, label %21
20: ; preds = %12
br label %27
21: ; preds = %12
%22 = load i32, i32* %3
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = call i32 @write(i32 %22, i8* %23, i32 %25)
br label %12
27: ; preds = %20
%28 = load i32, i32* %3
%29 = call i32 @close(i32 %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"fifo_file\00"
@O_WRONLY = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [9 x i8] c"fd = %d\0A\00"
@STDIN_FILENO = global i32 0
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = call i32 @memset(i8* %2, i32 0, i32 10)
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_RDONLY
%6 = or i32 %5, %4
%7 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @STDIN_FILENO
%10 = call i32 @read(i32 %9, i8* %2, i32 10)
%11 = load i8, i8* %2
%12 = icmp eq i8 %11, 48
br i1 %12, label %20, label %13
13: ; preds = %0, %13
%14 = call i32 @strlen(i8* %2)
%15 = call i32 @write(i32 %7, i8* %2, i32 %14)
%16 = load i32, i32* @STDIN_FILENO
%17 = call i32 @read(i32 %16, i8* %2, i32 10)
%18 = load i8, i8* %2
%19 = icmp eq i8 %18, 48
br i1 %19, label %20, label %13
20: ; preds = %13, %0
%21 = call i32 @close(i32 %7)
ret i32 0
}