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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
char *malloc(size_t);
int /*<<< orphan*/ snprintf(char *, size_t, char const *, char *, char *);
int sscanf(char *, char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int strlen(char const *);
char tolower(char);
char *buildCompleteSourceFile(FILE *currentFile, char *currentFileName,
                              FILE *completeFile, int level) {
  char buffer[2048], directive[2048], operand[2048], *error;
  if (level > 15)
    return ("Too many nested INCLUDEs\n");
  while (fgets(buffer, sizeof(buffer), currentFile) != NULL) {
    if (sscanf(buffer, "%s %s", directive, operand) != 2) {
      fprintf(completeFile, "%s", buffer);
      continue;
    }
    for (int i = 0; i < strlen(directive); ++i)
      directive[i] = tolower(directive[i]);
    if (strcmp(directive, "include") == 0) {
      FILE *includeFile = fopen(operand, "r");
      if (!includeFile) {
        const char *fmt = "Could not find INCLUDE file: %s\n"
                          "  for file: %s\n";
        size_t len =
            strlen(operand) + strlen(currentFileName) + strlen(fmt) + 1;
        char *tmp = malloc(len);
        snprintf(tmp, len, fmt, operand, currentFileName);
        return tmp;
      }
      error = buildCompleteSourceFile(includeFile, operand, completeFile,
                                      level + 1);
      fclose(includeFile);
      if (error) {
        return error;
      }
      continue;
    }
    fprintf(completeFile, "%s", buffer);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<buildCompleteSourceFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1870,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpl   $0xf,-0x24(%rbp)
jle    11e4 <buildCompleteSourceFile+0x34>
lea    0xe25(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1417 <buildCompleteSourceFile+0x267>
jmp    11e9 <buildCompleteSourceFile+0x39>
lea    -0x830(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x800,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     140f <buildCompleteSourceFile+0x25f>
lea    -0x830(%rbp),%rdi
lea    -0x1030(%rbp),%rdx
lea    -0x1830(%rbp),%rcx
lea    0xdf6(%rip),%rsi
call   10c0 <sscanf@plt>
cmp    $0x2,%eax
je     124e <buildCompleteSourceFile+0x9e>
mov    -0x20(%rbp),%rdi
lea    -0x830(%rbp),%rdx
lea    0xdd9(%rip),%rsi
call   1080 <fprintf@plt>
jmp    11e9 <buildCompleteSourceFile+0x39>
movl   $0x0,-0x183c(%rbp)
mov    -0x183c(%rbp),%eax
mov    %eax,-0x1864(%rbp)
lea    -0x1030(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1864(%rbp),%eax
cmp    %ecx,%eax
jge    12b8 <buildCompleteSourceFile+0x108>
movslq -0x183c(%rbp),%rax
movsbl -0x1030(%rbp,%rax,1),%edi
ff
call   10a0 <tolower@plt>
mov    %al,%cl
movslq -0x183c(%rbp),%rax
mov    %cl,-0x1030(%rbp,%rax,1)
mov    -0x183c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x183c(%rbp)
jmp    1258 <buildCompleteSourceFile+0xa8>
lea    -0x1030(%rbp),%rdi
lea    0xd5a(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    13f3 <buildCompleteSourceFile+0x243>
lea    -0x1830(%rbp),%rdi
lea    0xd45(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x1848(%rbp)
cmpq   $0x0,-0x1848(%rbp)
jne    13a0 <buildCompleteSourceFile+0x1f0>
lea    0xd26(%rip),%rax
mov    %rax,-0x1850(%rbp)
lea    -0x1830(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x186c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x186c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1868(%rbp)
mov    -0x1850(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1868(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
mov    %rax,-0x1858(%rbp)
mov    -0x1858(%rbp),%rdi
call   10b0 <malloc@plt>
mov    %rax,-0x1860(%rbp)
mov    -0x1860(%rbp),%rdi
mov    -0x1858(%rbp),%rsi
mov    -0x1850(%rbp),%rdx
lea    -0x1830(%rbp),%rcx
mov    -0x18(%rbp),%r8
call   1050 <snprintf@plt>
mov    -0x1860(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1417 <buildCompleteSourceFile+0x267>
mov    -0x1848(%rbp),%rdi
lea    -0x1830(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
call   1090 <buildCompleteSourceFile@plt>
mov    %rax,-0x1838(%rbp)
mov    -0x1848(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x0,-0x1838(%rbp)
je     13ee <buildCompleteSourceFile+0x23e>
mov    -0x1838(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1417 <buildCompleteSourceFile+0x267>
jmp    11e9 <buildCompleteSourceFile+0x39>
mov    -0x20(%rbp),%rdi
lea    -0x830(%rbp),%rdx
lea    0xc18(%rip),%rsi
call   1080 <fprintf@plt>
jmp    11e9 <buildCompleteSourceFile+0x39>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1870,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buildCompleteSourceFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1818,%rsp
cmp    $0xf,%ecx
jle    11d2 <buildCompleteSourceFile+0x22>
lea    0xe33(%rip),%rax
jmp    1316 <buildCompleteSourceFile+0x166>
mov    %ecx,%ebx
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0x10(%rsp),%rdi
mov    $0x800,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1314 <buildCompleteSourceFile+0x164>
mov    %rbp,0x8(%rsp)
add    $0x1,%ebx
mov    %ebx,0x4(%rsp)
lea    0x10(%rsp),%rbx
lea    0x1010(%rsp),%r15
lea    0x810(%rsp),%rbp
jmp    124c <buildCompleteSourceFile+0x9c>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <fputs@plt>
mov    %rbx,%rdi
mov    $0x800,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
lea    0x810(%rsp),%rbp
je     1314 <buildCompleteSourceFile+0x164>
mov    %rbx,%rdi
lea    0xdc4(%rip),%rsi
mov    %r15,%rdx
mov    %rbp,%rcx
call   10c0 <sscanf@plt>
cmp    $0x2,%eax
jne    1220 <buildCompleteSourceFile+0x70>
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    12a7 <buildCompleteSourceFile+0xf7>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl 0x1010(%rsp,%rbx,1),%edi
call   10a0 <tolower@plt>
mov    %al,0x1010(%rsp,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1280 <buildCompleteSourceFile+0xd0>
mov    %r15,%rdi
lea    0xd6f(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
lea    0x10(%rsp),%rbx
jne    1220 <buildCompleteSourceFile+0x70>
mov    %r13,%rbx
mov    %rbp,%rdi
lea    0xd57(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1328 <buildCompleteSourceFile+0x178>
mov    %rax,%r13
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %rbx,%rbp
mov    %rbx,%rdx
mov    0x4(%rsp),%ecx
call   1090 <buildCompleteSourceFile@plt>
mov    %rax,%r12
mov    %r13,%rdi
mov    %rbx,%r13
call   1030 <fclose@plt>
test   %r12,%r12
lea    0x10(%rsp),%rbx
je     122b <buildCompleteSourceFile+0x7b>
mov    %r12,%rax
jmp    1316 <buildCompleteSourceFile+0x166>
xor    %eax,%eax
add    $0x1818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x810(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
mov    0x8(%rsp),%r13
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0xcd9(%rip),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
add    %r12d,%ebx
add    %ebx,%eax
add    $0x1,%eax
movslq %eax,%rbx
mov    %rbx,%rdi
call   10b0 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %r13,%r8
call   1050 <snprintf@plt>
mov    %rbp,%rax
jmp    1316 <buildCompleteSourceFile+0x166>

LLVM IR (-O0):
@.str = [26 x i8] c"Too many nested INCLUDEs\0A\00"
@.str.1 = [6 x i8] c"%s %s\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [8 x i8] c"include\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [48 x i8] c"Could not find INCLUDE file: %s\0A for file: %s\0A\00"
define i8* @buildCompleteSourceFile(i32* %0, i8* %1, i32* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca [2048 x i8]
%11 = alloca [2048 x i8]
%12 = alloca [2048 x i8]
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32*
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i8*
store i32* %0, i32** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
%19 = load i32, i32* %9
%20 = icmp sgt i32 %19, 15
br i1 %20, label %21, label %22
21: ; preds = %4
store i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8** %5
br label %104
22: ; preds = %4
br label %23
23: ; preds = %99, %98, %34, %22
%24 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%25 = load i32*, i32** %6
%26 = call i32* @fgets(i8* %24, i32 2048, i32* %25)
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %103
28: ; preds = %23
%29 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%30 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %12, i64 0, i64 0
%32 = call i32 @sscanf(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* %31)
%33 = icmp ne i32 %32, 2
br i1 %33, label %34, label %38
34: ; preds = %28
%35 = load i32*, i32** %8
%36 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%37 = call i32 @fprintf(i32* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %36)
br label %23
38: ; preds = %28
store i32 0, i32* %14
br label %39
39: ; preds = %53, %38
%40 = load i32, i32* %14
%41 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%42 = call i32 @strlen(i8* %41)
%43 = icmp slt i32 %40, %42
br i1 %43, label %44, label %56
44: ; preds = %39
%45 = load i32, i32* %14
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = call signext i8 @tolower(i8 signext %48)
%50 = load i32, i32* %14
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 %51
store i8 %49, i8* %52
br label %53
53: ; preds = %44
%54 = load i32, i32* %14
%55 = add nsw i32 %54, 1
store i32 %55, i32* %14
br label %39
56: ; preds = %39
%57 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%58 = call i64 @strcmp(i8* %57, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %99
60: ; preds = %56
%61 = getelementptr inbounds [2048 x i8], [2048 x i8]* %12, i64 0, i64 0
%62 = call i32* @fopen(i8* %61, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %62, i32** %15
%63 = load i32*, i32** %15
%64 = icmp ne i32* %63, null
br i1 %64, label %85, label %65
65: ; preds = %60
store i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), i8** %16
%66 = getelementptr inbounds [2048 x i8], [2048 x i8]* %12, i64 0, i64 0
%67 = call i32 @strlen(i8* %66)
%68 = load i8*, i8** %7
%69 = call i32 @strlen(i8* %68)
%70 = add nsw i32 %67, %69
%71 = load i8*, i8** %16
%72 = call i32 @strlen(i8* %71)
%73 = add nsw i32 %70, %72
%74 = add nsw i32 %73, 1
%75 = sext i32 %74 to i64
store i64 %75, i64* %17
%76 = load i64, i64* %17
%77 = call i8* @malloc(i64 %76)
store i8* %77, i8** %18
%78 = load i8*, i8** %18
%79 = load i64, i64* %17
%80 = load i8*, i8** %16
%81 = getelementptr inbounds [2048 x i8], [2048 x i8]* %12, i64 0, i64 0
%82 = load i8*, i8** %7
%83 = call i32 @snprintf(i8* %78, i64 %79, i8* %80, i8* %81, i8* %82)
%84 = load i8*, i8** %18
store i8* %84, i8** %5
br label %104
85: ; preds = %60
%86 = load i32*, i32** %15
%87 = getelementptr inbounds [2048 x i8], [2048 x i8]* %12, i64 0, i64 0
%88 = load i32*, i32** %8
%89 = load i32, i32* %9
%90 = add nsw i32 %89, 1
%91 = call i8* @buildCompleteSourceFile(i32* %86, i8* %87, i32* %88, i32 %90)
store i8* %91, i8** %13
%92 = load i32*, i32** %15
%93 = call i32 @fclose(i32* %92)
%94 = load i8*, i8** %13
%95 = icmp ne i8* %94, null
br i1 %95, label %96, label %98
96: ; preds = %85
%97 = load i8*, i8** %13
store i8* %97, i8** %5
br label %104
98: ; preds = %85
br label %23
99: ; preds = %56
%100 = load i32*, i32** %8
%101 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%102 = call i32 @fprintf(i32* %100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %101)
br label %23
103: ; preds = %23
store i8* null, i8** %5
br label %104
104: ; preds = %103, %96, %65, %21
%105 = load i8*, i8** %5
ret i8* %105
}

LLVM IR (-O2):
@.str = [26 x i8] c"Too many nested INCLUDEs\0A\00"
@.str.1 = [6 x i8] c"%s %s\00"
@.str.3 = [8 x i8] c"include\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [48 x i8] c"Could not find INCLUDE file: %s\0A for file: %s\0A\00"
define i8* @buildCompleteSourceFile(i32* nocapture %0, i8* %1, i32* nocapture %2, i32 %3) {
%5 = alloca [2048 x i8]
%6 = alloca [2048 x i8]
%7 = alloca [2048 x i8]
%8 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%11 = icmp sgt i32 %3, 15
br i1 %11, label %57, label %12
12: ; preds = %4
%13 = call i32* @fgets(i8* %8, i32 2048, i32* %0)
%14 = icmp eq i32* %13, null
br i1 %14, label %57, label %15
15: ; preds = %12
%16 = add nsw i32 %3, 1
br label %17
17: ; preds = %15, %25
%18 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* %10)
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = call i32 @strlen(i8* %9)
%22 = icmp sgt i32 %21, 0
br i1 %22, label %31, label %28
23: ; preds = %17, %28
%24 = call i32 @fputs(i8* %8, i32* %2)
br label %25
25: ; preds = %23, %53
%26 = call i32* @fgets(i8* %8, i32 2048, i32* %0)
%27 = icmp eq i32* %26, null
br i1 %27, label %57, label %17
28: ; preds = %31, %20
%29 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %40, label %23
31: ; preds = %20, %31
%32 = phi i64 [ %36, %31 ], [ 0, %20 ]
%33 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = call signext i8 @tolower(i8 signext %34)
store i8 %35, i8* %33
%36 = add nuw nsw i64 %32, 1
%37 = call i32 @strlen(i8* %9)
%38 = sext i32 %37 to i64
%39 = icmp slt i64 %36, %38
br i1 %39, label %31, label %28
40: ; preds = %28
%41 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %53
43: ; preds = %40
%44 = call i32 @strlen(i8* %10)
%45 = call i32 @strlen(i8* %1)
%46 = call i32 @strlen(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0))
%47 = add i32 %44, 1
%48 = add i32 %47, %45
%49 = add i32 %48, %46
%50 = sext i32 %49 to i64
%51 = call i8* @malloc(i64 %50)
%52 = call i32 @snprintf(i8* %51, i64 %50, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), i8* %10, i8* %1)
br label %57
53: ; preds = %40
%54 = call i8* @buildCompleteSourceFile(i32* %41, i8* %10, i32* %2, i32 %16)
%55 = call i32 @fclose(i32* %41)
%56 = icmp eq i8* %54, null
br i1 %56, label %25, label %57
57: ; preds = %53, %25, %12, %43, %4
%58 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), %4 ], [ %51, %43 ], [ null, %12 ], [ %54, %53 ], [ null, %25 ]
ret i8* %58
}