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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ *stderr;
char *strstr(char *, char *);
void n_printfile(FILE *outfd, char *fname) {
  FILE *infd;
  char *tp, ibuf[2048];
  infd = fopen(fname, "r");
  if (infd == NULL) {
    fprintf(stderr, "ERROR: Couldn't open \"%s\"!\n", fname);
    exit(-1);
  }
  while (fgets(ibuf, sizeof(ibuf), infd) != NULL) {
    tp = strstr(ibuf, "#include \"");
    if (tp == NULL) {
      fprintf(outfd, "%s", ibuf);
      continue;
    }
    tp += 10;
    if (strstr(tp, "\"") == NULL) {
      fprintf(outfd, "%s", ibuf);
      continue;
    }
    strstr(tp, "\"")[0] = '\0';
    n_printfile(outfd, tp);
  }
  fclose(infd);
}


x86 assembly (clang, -O0):
<n_printfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c6 <n_printfile+0x56>
mov    0x2e37(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe4b(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
jmp    11cb <n_printfile+0x5b>
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x800,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     128f <n_printfile+0x11f>
lea    -0x820(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1228 <n_printfile+0xb8>
mov    -0x8(%rbp),%rdi
lea    -0x820(%rbp),%rdx
lea    0xe0b(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11cb <n_printfile+0x5b>
mov    -0x20(%rbp),%rax
add    $0xa,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xde8(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
jne    126a <n_printfile+0xfa>
mov    -0x8(%rbp),%rdi
lea    -0x820(%rbp),%rdx
lea    0xdc9(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11cb <n_printfile+0x5b>
mov    -0x20(%rbp),%rdi
lea    0xdb2(%rip),%rsi
call   1090 <strstr@plt>
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <n_printfile@plt>
jmp    11cb <n_printfile+0x5b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<n_printfile>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe53(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1262 <n_printfile+0xd2>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x800,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1249 <n_printfile+0xb9>
lea    0xe41(%rip),%r15
mov    %rsp,%r13
jmp    1210 <n_printfile+0x80>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r14,%rsi
call   1050 <fputs@plt>
mov    %r13,%rdi
mov    $0x800,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1249 <n_printfile+0xb9>
mov    %r13,%rdi
mov    %r15,%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
je     11f0 <n_printfile+0x60>
mov    %rax,%rbx
add    $0xa,%rbx
mov    %rbx,%rdi
mov    $0x22,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11f0 <n_printfile+0x60>
movb   $0x0,(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <n_printfile@plt>
jmp    11fb <n_printfile+0x6b>
mov    %r12,%rdi
call   1030 <fclose@plt>
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2d77(%rip),%rax
mov    (%rax),%rdi
lea    0xd8f(%rip),%rsi
mov    %rbx,%rdx
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32* null
@.str.1 = [28 x i8] c"ERROR: Couldn't open \22%s\22!\0A\00"
@.str.2 = [11 x i8] c"#include \22\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [2 x i8] c"\22\00"
define void @n_printfile(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca [2048 x i8]
store i32* %0, i32** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i32*, i32** %5
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i32*, i32** @stderr
%14 = load i8*, i8** %4
%15 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %2
br label %18
18: ; preds = %42, %38, %28, %17
%19 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%20 = load i32*, i32** %5
%21 = call i32* @fgets(i8* %19, i32 2048, i32* %20)
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %48
23: ; preds = %18
%24 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%25 = call i8* @strstr(i8* %24, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i8* %25, i8** %6
%26 = load i8*, i8** %6
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = load i32*, i32** %3
%30 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%31 = call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %30)
br label %18
32: ; preds = %23
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i64 10
store i8* %34, i8** %6
%35 = load i8*, i8** %6
%36 = call i8* @strstr(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %42
38: ; preds = %32
%39 = load i32*, i32** %3
%40 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%41 = call i32 @fprintf(i32* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %40)
br label %18
42: ; preds = %32
%43 = load i8*, i8** %6
%44 = call i8* @strstr(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%45 = getelementptr inbounds i8, i8* %44, i64 0
store i8 0, i8* %45
%46 = load i32*, i32** %3
%47 = load i8*, i8** %6
br label %18
48: ; preds = %18
%49 = load i32*, i32** %5
%50 = call i32 @fclose(i32* %49)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32* null
@.str.1 = [28 x i8] c"ERROR: Couldn't open \22%s\22!\0A\00"
@.str.2 = [11 x i8] c"#include \22\00"
define void @n_printfile(i32* nocapture %0, i8* %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i32* @fgets(i8* %4, i32 2048, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %29, label %14
10: ; preds = %2
%11 = load i32*, i32** @stderr
%12 = tail call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %7, %19
%15 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = call i32 @fputs(i8* %4, i32* %0)
br label %19
19: ; preds = %17, %26, %28
%20 = call i32* @fgets(i8* %4, i32 2048, i32* %5)
%21 = icmp eq i32* %20, null
br i1 %21, label %29, label %14
22: ; preds = %14
%23 = getelementptr inbounds i8, i8* %15, i64 10
%24 = call i8* @strchr(i8* %23, i32 34)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @fputs(i8* %4, i32* %0)
br label %19
28: ; preds = %22
store i8 0, i8* %24
br label %19
29: ; preds = %19, %7
%30 = call i32 @fclose(i32* %5)
ret void
}