#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 errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *,
                           int);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ html_raw(char *, size_t);
int /*<<< orphan*/ stderr;
char *strerror(int);
int html_include(const char *filename) {
  FILE *f;
  char buf[4096];
  size_t len;
  if (!(f = fopen(filename, "r"))) {
    fprintf(stderr, "[cgit] Failed to include file %s: %s (%d).\n", filename,
            strerror(errno), errno);
    return -1;
  }
  while ((len = fread(buf, 1, 4096, f)) > 0)
    html_raw(buf, len);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<html_include>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11e7 <html_include+0x87>
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1034(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x1030(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x1034(%rbp),%edi
mov    -0x1030(%rbp),%rdx
mov    %rax,%rcx
mov    0x2e0c(%rip),%rax
mov    (%rax),%r8d
lea    0xe2c(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123f <html_include+0xdf>
jmp    11ec <html_include+0x8c>
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %rax,-0x1028(%rbp)
cmp    $0x0,%rax
jbe    122f <html_include+0xcf>
lea    -0x1020(%rbp),%rdi
mov    -0x1028(%rbp),%rsi
call   1050 <html_raw@plt>
jmp    11ec <html_include+0x8c>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<html_include>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rdi,%r14
lea    0xe8a(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d1 <html_include+0x71>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11c5 <html_include+0x65>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <html_raw@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jne    11a0 <html_include+0x40>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1205 <html_include+0xa5>
mov    0x2e08(%rip),%rax
mov    (%rax),%ebx
mov    0x2df7(%rip),%r15
mov    (%r15),%edi
call   1080 <strerror@plt>
mov    (%r15),%r8d
lea    0xe0f(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [44 x i8] c"[cgit] Failed to include file %s: %s (%d).\0A\00"
@errno = global i32 0
define i32 @html_include(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [4096 x i8]
%6 = alloca i64
store i8* %0, i8** %3
%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** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %17, label %10
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %3
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = load i32, i32* @errno
%16 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %12, i8* %14, i32 %15)
store i32 -1, i32* %2
br label %30
17: ; preds = %1
br label %18
18: ; preds = %23, %17
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%20 = load i32*, i32** %4
%21 = call i64 @fread(i8* %19, i32 1, i32 4096, i32* %20)
store i64 %21, i64* %6
%22 = icmp ugt i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%25 = load i64, i64* %6
%26 = call i32 @html_raw(i8* %24, i64 %25)
br label %18
27: ; preds = %18
%28 = load i32*, i32** %4
%29 = call i32 @fclose(i32* %28)
store i32 0, i32* %2
br label %30
30: ; preds = %27, %10
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [44 x i8] c"[cgit] Failed to include file %s: %s (%d).\0A\00"
@errno = global i32 0
define i32 @html_include(i8* %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 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 %9, label %6
6: ; preds = %1
%7 = call i64 @fread(i8* %3, i32 1, i32 4096, i32* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %20, label %15
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = load i32, i32* @errno
%14 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %12, i32 %13)
br label %22
15: ; preds = %6, %15
%16 = phi i64 [ %18, %15 ], [ %7, %6 ]
%17 = call i32 @html_raw(i8* %3, i64 %16)
%18 = call i64 @fread(i8* %3, i32 1, i32 4096, i32* %4)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %15
20: ; preds = %15, %6
%21 = call i32 @fclose(i32* %4)
br label %22
22: ; preds = %20, %9
%23 = phi i32 [ 0, %20 ], [ -1, %9 ]
ret i32 %23
}