#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int readFromPipe(const char *path, char buffer[]) {
  FILE *fp = NULL;
  fp = fopen(path, "r");
  if (fp == NULL) {
    return -1;
  }
  while (fgets(buffer, 2048, fp) != NULL) {
  }
  fclose(fp);
  return 1;
}


x86 assembly (clang, -O0):
<readFromPipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xead(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1173 <readFromPipe+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a9 <readFromPipe+0x79>
jmp    1178 <readFromPipe+0x48>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x800,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1199 <readFromPipe+0x69>
jmp    1178 <readFromPipe+0x48>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFromPipe>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xec2(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1174 <readFromPipe+0x44>
mov    %rax,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x800,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    1150 <readFromPipe+0x20>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
jmp    1179 <readFromPipe+0x49>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @readFromPipe(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* null, i32** %6
%7 = load i8*, i8** %4
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %22
12: ; preds = %2
br label %13
13: ; preds = %18, %12
%14 = load i8*, i8** %5
%15 = load i32*, i32** %6
%16 = call i32* @fgets(i8* %14, i32 2048, i32* %15)
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %13
br label %13
19: ; preds = %13
%20 = load i32*, i32** %6
%21 = call i32 @fclose(i32* %20)
store i32 1, i32* %3
br label %22
22: ; preds = %19, %11
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @readFromPipe(i8* nocapture %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %10, label %5
5: ; preds = %2, %5
%6 = tail call i32* @fgets(i8* %1, i32 2048, i32* %3)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %5
8: ; preds = %5
%9 = tail call i32 @fclose(i32* %3)
br label %10
10: ; preds = %2, %8
%11 = phi i32 [ 1, %8 ], [ -1, %2 ]
ret i32 %11
}