#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int filesend(const char *path, FILE *out) {
  FILE *in;
  int c;
  in = fopen(path, "r");
  if (!in)
    return -1;
  while ((c = getc(in)) != EOF)
    putc(c, out);
  fclose(in);
  return 0;
}


x86 assembly (clang, -O0):
<filesend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117b <filesend+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bc <filesend+0x7c>
jmp    1180 <filesend+0x40>
mov    -0x20(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e55(%rip),%rcx
cmp    (%rcx),%eax
je     11ac <filesend+0x6c>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1040 <putc@plt>
jmp    1180 <filesend+0x40>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filesend>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xeb1(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1193 <filesend+0x53>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <getc@plt>
mov    0x2e7d(%rip),%r15
cmp    (%r15),%eax
je     1187 <filesend+0x47>
mov    %eax,%edi
mov    %r14,%rsi
call   1040 <putc@plt>
mov    %rbx,%rdi
call   1060 <getc@plt>
cmp    (%r15),%eax
jne    1170 <filesend+0x30>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1198 <filesend+0x58>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @filesend(i8* nocapture %0, i32* nocapture %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 %17, label %5
5: ; preds = %2
%6 = tail call i32 @getc(i32* %3)
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %15, label %9
9: ; preds = %5, %9
%10 = phi i32 [ %12, %9 ], [ %6, %5 ]
%11 = tail call i32 @putc(i32 %10, i32* %1)
%12 = tail call i32 @getc(i32* %3)
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %9
15: ; preds = %9, %5
%16 = tail call i32 @fclose(i32* %3)
br label %17
17: ; preds = %2, %15
%18 = phi i32 [ 0, %15 ], [ -1, %2 ]
ret i32 %18
}