#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*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdout;
void putfilecontents(char *path) {
  FILE *fin;
  char line[32767];
  fin = fopen(path, "r");
  if (fin == NULL) {
    perror("open");
    return;
  }
  while ((fgets(line, sizeof(line), fin)) != NULL) {
    if (fputs(line, stdout) == EOF) {
      break;
    }
  }
  fclose(fin);
  return;
}


x86 assembly (clang, -O0):
<putfilecontents>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8010,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118f <putfilecontents+0x3f>
lea    0xe7d(%rip),%rdi
call   1070 <perror@plt>
jmp    11eb <putfilecontents+0x9b>
jmp    1194 <putfilecontents+0x44>
lea    -0x8010(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x7fff,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11e2 <putfilecontents+0x92>
lea    -0x8010(%rbp),%rdi
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%rax
jne    11dd <putfilecontents+0x8d>
jmp    11e2 <putfilecontents+0x92>
jmp    1194 <putfilecontents+0x44>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x8010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putfilecontents>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x8008,%rsp
lea    0xe9b(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11cd <putfilecontents+0x7d>
mov    %rax,%rbx
mov    %rsp,%r14
mov    0x2e5c(%rip),%r15
mov    0x2e65(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    $0x7fff,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11b6 <putfilecontents+0x66>
mov    (%r15),%esi
mov    %r14,%rdi
call   1040 <fputs@plt>
cmp    (%r12),%rax
jne    1190 <putfilecontents+0x40>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x8008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe2e(%rip),%rdi
add    $0x8008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1070 <perror@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"open\00"
@stdout = global i32 0
@EOF = global i64 0
define void @putfilecontents(i8* nocapture %0) {
%2 = alloca [32767 x i8]
%3 = getelementptr inbounds [32767 x i8], [32767 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %18
8: ; preds = %1, %11
%9 = call i32* @fgets(i8* %3, i32 32767, i32* %4)
%10 = icmp eq i32* %9, null
br i1 %10, label %16, label %11
11: ; preds = %8
%12 = load i32, i32* @stdout
%13 = call i64 @fputs(i8* %3, i32 %12)
%14 = load i64, i64* @EOF
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %8
16: ; preds = %11, %8
%17 = call i32 @fclose(i32* %4)
br label %18
18: ; preds = %16, %6
ret void
}