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


x86 assembly (clang, -O0):
<filesend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1174 <filesend+0x34>
jmp    11ae <filesend+0x6e>
jmp    1179 <filesend+0x39>
mov    -0x18(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e5c(%rip),%rcx
cmp    (%rcx),%eax
je     11a5 <filesend+0x65>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <putc@plt>
jmp    1179 <filesend+0x39>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%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     1194 <filesend+0x54>
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
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
define void @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
ret void
}