#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 fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *stderr;
int includefile(FILE *fout, char name[]) {
  FILE *fin;
  int c = 0;
  if ((fin = fopen(name, "rt")) == NULL) {
    fprintf(stderr, "\nERROR: includefile() could not open `%s'\n\n", name);
    return 0;
  }
  fprintf(fout, "%% (microabc) File `%s' included below:\n", name);
  while ((c = fgetc(fin)) != EOF)
    fputc(c, fout);
  fprintf(fout, "%% (microabc) File `%s' included above.\n", name);
  fclose(fin);
  return 1;
}


x86 assembly (clang, -O0):
<includefile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11ab <includefile+0x5b>
mov    0x2e4c(%rip),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe69(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    120f <includefile+0xbf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe75(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e16(%rip),%rcx
cmp    (%rcx),%eax
je     11eb <includefile+0x9b>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <fputc@plt>
jmp    11bf <includefile+0x6f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe5e(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<includefile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe9b(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d9 <includefile+0x89>
mov    %rax,%rbx
lea    0xeb3(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    0x2e52(%rip),%r12
cmp    (%r12),%eax
je     11b8 <includefile+0x68>
nopl   0x0(%rax)
mov    %eax,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    (%r12),%eax
jne    11a0 <includefile+0x50>
lea    0xe99(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
jmp    11f4 <includefile+0xa4>
mov    0x2df8(%rip),%rax
mov    (%rax),%rdi
lea    0xe19(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rt\00"
@stderr = global i32* null
@.str.1 = [44 x i8] c"\0AERROR: includefile() could not open `%s'\0A\0A\00"
@.str.2 = [41 x i8] c"%% (microabc) File `%s' included below:\0A\00"
@EOF = global i32 0
@.str.3 = [41 x i8] c"%% (microabc) File `%s' included above.\0A\00"
define i32 @includefile(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 0, i32* %7
%8 = load i8*, i8** %5
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32*, i32** @stderr
%13 = load i8*, i8** %5
%14 = call i32 @fprintf(i32* %12, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %13)
store i32 0, i32* %3
br label %34
15: ; preds = %2
%16 = load i32*, i32** %4
%17 = load i8*, i8** %5
%18 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %24, %15
%20 = load i32*, i32** %6
%21 = call i32 @fgetc(i32* %20)
store i32 %21, i32* %7
%22 = load i32, i32* @EOF
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = load i32, i32* %7
%26 = load i32*, i32** %4
%27 = call i32 @fputc(i32 %25, i32* %26)
br label %19
28: ; preds = %19
%29 = load i32*, i32** %4
%30 = load i8*, i8** %5
%31 = call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = load i32*, i32** %6
%33 = call i32 @fclose(i32* %32)
store i32 1, i32* %3
br label %34
34: ; preds = %28, %11
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [3 x i8] c"rt\00"
@stderr = global i32* null
@.str.1 = [44 x i8] c"\0AERROR: includefile() could not open `%s'\0A\0A\00"
@.str.2 = [41 x i8] c"%% (microabc) File `%s' included below:\0A\00"
@EOF = global i32 0
@.str.3 = [41 x i8] c"%% (microabc) File `%s' included above.\0A\00"
define i32 @includefile(i32* nocapture %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32*, i32** @stderr
%7 = tail call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %22
8: ; preds = %2
%9 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%10 = tail call i32 @fgetc(i32* %3)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %19, label %13
13: ; preds = %8, %13
%14 = phi i32 [ %16, %13 ], [ %10, %8 ]
%15 = tail call i32 @fputc(i32 %14, i32* %0)
%16 = tail call i32 @fgetc(i32* %3)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %13
19: ; preds = %13, %8
%20 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%21 = tail call i32 @fclose(i32* %3)
br label %22
22: ; preds = %19, %5
%23 = phi i32 [ 0, %5 ], [ 1, %19 ]
ret i32 %23
}