#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*/ cgi_init_headers();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ libcgi_error(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ printf(char *, char *);
int cgi_include(const char *filename) {
  FILE *inc;
  char buffer[255];
  if (!(inc = fopen(filename, "r"))) {
    cgi_init_headers();
    libcgi_error(0, "Failed to open include file <b>%s</b>", filename);
    return 0;
  }
  while (fgets(buffer, 255, inc))
    printf("%s", buffer);
  fclose(inc);
  return 1;
}


x86 assembly (clang, -O0):
<cgi_include>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b2 <cgi_include+0x52>
mov    $0x0,%al
call   1050 <cgi_init_headers@plt>
mov    -0x10(%rbp),%rdx
xor    %edi,%edi
lea    0xe61(%rip),%rsi
call   1030 <libcgi_error@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fe <cgi_include+0x9e>
jmp    11b7 <cgi_include+0x57>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xff,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     11ee <cgi_include+0x8e>
lea    -0x120(%rbp),%rsi
lea    0xe44(%rip),%rdi
call   1060 <printf@plt>
jmp    11b7 <cgi_include+0x57>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cgi_include>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%r14
lea    0xe8a(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11df <cgi_include+0x7f>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0xff,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     11d0 <cgi_include+0x70>
lea    0xe89(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    11b0 <cgi_include+0x50>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    $0x1,%ebx
jmp    11f9 <cgi_include+0x99>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <cgi_init_headers@plt>
lea    0xe13(%rip),%rsi
xor    %edi,%edi
mov    %r14,%rdx
call   1030 <libcgi_error@plt>
mov    %ebx,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [38 x i8] c"Failed to open include file <b>%s</b>\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @cgi_include(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [255 x i8]
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = icmp ne i32* %7, null
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = call i32 (...) @cgi_init_headers()
%11 = load i8*, i8** %3
%12 = call i32 @libcgi_error(i32 0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %11)
store i32 0, i32* %2
br label %25
13: ; preds = %1
br label %14
14: ; preds = %19, %13
%15 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%16 = load i32*, i32** %4
%17 = call i64 @fgets(i8* %15, i32 255, i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%21 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %14
22: ; preds = %14
%23 = load i32*, i32** %4
%24 = call i32 @fclose(i32* %23)
store i32 1, i32* %2
br label %25
25: ; preds = %22, %9
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [38 x i8] c"Failed to open include file <b>%s</b>\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @cgi_include(i8* %0) {
%2 = alloca [255 x i8]
%3 = getelementptr inbounds [255 x i8], [255 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 @fgets(i8* %3, i32 255, i32* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %16, label %12
9: ; preds = %1
%10 = tail call i32 (...) @cgi_init_headers()
%11 = tail call i32 @libcgi_error(i32 0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %18
12: ; preds = %6, %12
%13 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%14 = call i64 @fgets(i8* %3, i32 255, i32* %4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %12
16: ; preds = %12, %6
%17 = call i32 @fclose(i32* %4)
br label %18
18: ; preds = %16, %9
%19 = phi i32 [ 1, %16 ], [ 0, %9 ]
ret i32 %19
}