#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
void mergefile(const char *name, FILE *outfile) {
  FILE *infile;
  fprintf(outfile, "\n\n/* INCLUDED FILE : %s */\n", name);
  infile = fopen(name, "r");
  while (!feof(infile)) {
    int ch;
    ch = fgetc(infile);
    if (ch != -1) {
      fputc(ch, outfile);
    }
  }
  fclose(infile);
  fprintf(outfile, "/* END OF INCLUDED FILE : %s */\n\n\n", name);
}


x86 assembly (clang, -O0):
<mergefile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe81(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b6 <mergefile+0x56>
jmp    11dd <mergefile+0x7d>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
je     11d8 <mergefile+0x78>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <fputc@plt>
jmp    1198 <mergefile+0x38>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe29(%rip),%rsi
call   1060 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergefile>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe8e(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1060 <fprintf@plt>
lea    0xe98(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
jmp    11a3 <mergefile+0x43>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11c5 <mergefile+0x65>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    $0xffffffff,%eax
je     11a0 <mergefile+0x40>
mov    %eax,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
jmp    11a0 <mergefile+0x40>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe4a(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <fprintf@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"\0A\0A/* INCLUDED FILE : %s */\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [35 x i8] c"/* END OF INCLUDED FILE : %s */\0A\0A\0A\00"
define void @mergefile(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 i32*, i32** %4
%8 = load i8*, i8** %3
%9 = call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %5
br label %12
12: ; preds = %26, %2
%13 = load i32*, i32** %5
%14 = call i32 @feof(i32* %13)
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
br i1 %16, label %17, label %27
17: ; preds = %12
%18 = load i32*, i32** %5
%19 = call i32 @fgetc(i32* %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32, i32* %6
%24 = load i32*, i32** %4
%25 = call i32 @fputc(i32 %23, i32* %24)
br label %26
26: ; preds = %22, %17
br label %12
27: ; preds = %12
%28 = load i32*, i32** %5
%29 = call i32 @fclose(i32* %28)
%30 = load i32*, i32** %4
%31 = load i8*, i8** %3
%32 = call i32 @fprintf(i32* %30, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %31)
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"\0A\0A/* INCLUDED FILE : %s */\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [35 x i8] c"/* END OF INCLUDED FILE : %s */\0A\0A\0A\00"
define void @mergefile(i8* %0, i32* nocapture %1) {
%3 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @feof(i32* %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %2, %12
%8 = tail call i32 @fgetc(i32* %4)
%9 = icmp eq i32 %8, -1
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @fputc(i32 %8, i32* %1)
br label %12
12: ; preds = %10, %7
%13 = tail call i32 @feof(i32* %4)
%14 = icmp eq i32 %13, 0
br i1 %14, label %7, label %15
15: ; preds = %12, %2
%16 = tail call i32 @fclose(i32* %4)
%17 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %0)
ret void
}