#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*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int feof(int /*<<< orphan*/ *);
int ferror(int /*<<< orphan*/ *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
int getpagesize();
char *malloc(int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ stdout;
int main() {
  FILE *fp;
  int nbytes, BSIZE = getpagesize();
  char *buffer = malloc(BSIZE);
  fp = popen("finger", "r");
  while ((nbytes = fread(buffer, 1, BSIZE, fp)) > 0)
    fwrite(buffer, 1, nbytes, stdout);
  printf("EOF = %d and Error = %d\n", feof(fp), ferror(fp));
  pclose(fp);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10a0 <getpagesize@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
lea    0xe34(%rip),%rdi
lea    0xe32(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    121c <main+0x7c>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    0x2dd5(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
jmp    11dc <main+0x3c>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
mov    -0x24(%rbp),%esi
mov    %eax,%edx
lea    0xdca(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <pclose@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   10a0 <getpagesize@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0xe3f(%rip),%rdi
lea    0xe3d(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jle    1218 <main+0x78>
mov    0x2df3(%rip),%r15
nopl   (%rax)
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
call   10c0 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jg     11f0 <main+0x50>
mov    %r14,%rdi
call   1070 <feof@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <ferror@plt>
lea    0xdd6(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1050 <printf@plt>
mov    %r14,%rdi
call   1060 <pclose@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"finger\00"
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32 0
@.str.2 = [25 x i8] c"EOF = %d and Error = %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
%6 = call i32 (...) @getpagesize()
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = call i8* @malloc(i32 %7)
store i8* %8, i8** %5
%9 = call i32* @popen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %2
br label %10
10: ; preds = %16, %0
%11 = load i8*, i8** %5
%12 = load i32, i32* %4
%13 = load i32*, i32** %2
%14 = call i32 @fread(i8* %11, i32 1, i32 %12, i32* %13)
store i32 %14, i32* %3
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %10
%17 = load i8*, i8** %5
%18 = load i32, i32* %3
%19 = load i32, i32* @stdout
%20 = call i32 @fwrite(i8* %17, i32 1, i32 %18, i32 %19)
br label %10
21: ; preds = %10
%22 = load i32*, i32** %2
%23 = call i32 @feof(i32* %22)
%24 = load i32*, i32** %2
%25 = call i32 @ferror(i32* %24)
%26 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %25)
%27 = load i32*, i32** %2
%28 = call i32 @pclose(i32* %27)
%29 = load i32, i32* @EXIT_SUCCESS
%30 = call i32 @exit(i32 %29)
unreachable
}

LLVM IR (-O2):
@.str = [7 x i8] c"finger\00"
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32 0
@.str.2 = [25 x i8] c"EOF = %d and Error = %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i32 (...) @getpagesize()
%2 = tail call i8* @malloc(i32 %1)
%3 = tail call i32* @popen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @fread(i8* %2, i32 1, i32 %1, i32* %3)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %0, %6
%7 = phi i32 [ %10, %6 ], [ %4, %0 ]
%8 = load i32, i32* @stdout
%9 = tail call i32 @fwrite(i8* %2, i32 1, i32 %7, i32 %8)
%10 = tail call i32 @fread(i8* %2, i32 1, i32 %1, i32* %3)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %6, label %12
12: ; preds = %6, %0
%13 = tail call i32 @feof(i32* %3)
%14 = tail call i32 @ferror(i32* %3)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %14)
%16 = tail call i32 @pclose(i32* %3)
%17 = load i32, i32* @EXIT_SUCCESS
%18 = tail call i32 @exit(i32 %17)
unreachable
}