#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int main(void) {
  FILE *fp;
  char readbuf[8000];
  fp = fopen("/tmp/fifo-file", "w");
  fputs("ls -l", fp);
  fclose(fp);
  fp = fopen("/tmp/fifo-file", "r");
  char line[100];
  fgets(line, 100, fp);
  while (!feof(fp)) {
    strcat(readbuf, line);
    fgets(line, 100, fp);
  }
  printf("The result is\n%s\n", readbuf);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1fc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe6d(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe47(%rip),%rdi
lea    0xe57(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x1fc0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x64,%esi
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11fc <main+0x8c>
jmp    1229 <main+0xb9>
lea    -0x1f50(%rbp),%rdi
lea    -0x1fc0(%rbp),%rsi
call   1090 <strcat@plt>
lea    -0x1fc0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x64,%esi
call   1060 <fgets@plt>
jmp    11de <main+0x6e>
lea    -0x1f50(%rbp),%rsi
lea    0xde2(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1fc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1fb0,%rsp
lea    0xe7d(%rip),%r14
lea    0xe85(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe75(%rip),%rdi
mov    $0x5,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe5a(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1217 <main+0xa7>
lea    0x70(%rsp),%r14
mov    %rsp,%r15
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
mov    %r15,%rdi
mov    $0x64,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11f0 <main+0x80>
lea    0xdfb(%rip),%rdi
lea    0x70(%rsp),%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1fb0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"/tmp/fifo-file\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"ls -l\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [18 x i8] c"The result is\0A%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [8000 x i8]
%4 = alloca [100 x i8]
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%8 = load i32*, i32** %2
%9 = call i32 @fclose(i32* %8)
%10 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %10, i32** %2
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%12 = load i32*, i32** %2
%13 = call i32 @fgets(i8* %11, i32 100, i32* %12)
br label %14
14: ; preds = %19, %0
%15 = load i32*, i32** %2
%16 = call i32 @feof(i32* %15)
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
br i1 %18, label %19, label %26
19: ; preds = %14
%20 = getelementptr inbounds [8000 x i8], [8000 x i8]* %3, i64 0, i64 0
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%22 = call i32 @strcat(i8* %20, i8* %21)
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%24 = load i32*, i32** %2
%25 = call i32 @fgets(i8* %23, i32 100, i32* %24)
br label %14
26: ; preds = %14
%27 = getelementptr inbounds [8000 x i8], [8000 x i8]* %3, i64 0, i64 0
%28 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"/tmp/fifo-file\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"ls -l\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [18 x i8] c"The result is\0A%s\0A\00"
define i32 @main() {
%1 = alloca [8000 x i8]
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [8000 x i8], [8000 x i8]* %1, i64 0, i64 0
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 5, i64 1, i32* %4)
%6 = tail call i32 @fclose(i32* %4)
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%9 = call i32 @fgets(i8* %8, i32 100, i32* %7)
%10 = call i32 @feof(i32* %7)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %0, %12
%13 = call i32 @strcat(i8* %3, i8* %8)
%14 = call i32 @fgets(i8* %8, i32 100, i32* %7)
%15 = call i32 @feof(i32* %7)
%16 = icmp eq i32 %15, 0
br i1 %16, label %12, label %17
17: ; preds = %12, %0
%18 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %3)
ret i32 0
}