#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*/ endswith(char *, char);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
void include_resfile(const char *category, const char *resource,
                     FILE *resfile) {
  extern FILE *output;
  char line[1024];
  int contline = 0;
  int skip = 0;
  fprintf(output, "%%%%BeingResource: %s %s\n", category, resource);
  while (fgets(line, 1024, resfile)) {
    if (!contline)
      skip = (line[0] == '%' && (line[1] == '%' || line[1] == '!'));
    if (!skip)
      fputs(line, output);
    contline = !endswith(line, '\n');
  }
  fprintf(output, "%%%%EndResource\n");
}


x86 assembly (clang, -O0):
<include_resfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x424(%rbp)
movl   $0x0,-0x428(%rbp)
mov    0x2e6e(%rip),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe7c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1263 <include_resfile+0x123>
cmpl   $0x0,-0x424(%rbp)
jne    1217 <include_resfile+0xd7>
movsbl -0x420(%rbp),%ecx
xor    %eax,%eax
cmp    $0x25,%ecx
mov    %al,-0x429(%rbp)
jne    1206 <include_resfile+0xc6>
movsbl -0x41f(%rbp),%ecx
mov    $0x1,%al
cmp    $0x25,%ecx
mov    %al,-0x42a(%rbp)
je     11fa <include_resfile+0xba>
movsbl -0x41f(%rbp),%eax
cmp    $0x21,%eax
sete   %al
mov    %al,-0x42a(%rbp)
mov    -0x42a(%rbp),%al
mov    %al,-0x429(%rbp)
mov    -0x429(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x428(%rbp)
cmpl   $0x0,-0x428(%rbp)
jne    123a <include_resfile+0xfa>
lea    -0x420(%rbp),%rdi
mov    0x2dae(%rip),%rax
mov    (%rax),%rsi
call   1040 <fputs@plt>
lea    -0x420(%rbp),%rdi
mov    $0xa,%esi
call   1030 <endswith@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x424(%rbp)
jmp    118b <include_resfile+0x4b>
mov    0x2d76(%rip),%rax
mov    (%rax),%rdi
lea    0xda6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<include_resfile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rdx,%r14
mov    %rsi,%rcx
mov    %rdi,%rdx
mov    0x2e81(%rip),%r15
mov    (%r15),%rdi
lea    0xe97(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11fa <include_resfile+0xba>
mov    %rsp,%r12
xor    %ebx,%ebx
jmp    11b9 <include_resfile+0x79>
xchg   %ax,%ax
mov    %r12,%rdi
mov    $0xa,%esi
call   1030 <endswith@plt>
xor    %ebx,%ebx
test   %eax,%eax
sete   %bl
mov    %r12,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11fa <include_resfile+0xba>
test   %ebx,%ebx
je     11d0 <include_resfile+0x90>
test   %ebp,%ebp
jne    1190 <include_resfile+0x50>
jmp    11ed <include_resfile+0xad>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%rsp),%eax
movzbl 0x1(%rsp),%ecx
xor    $0x25,%al
and    $0xfb,%cl
xor    $0x21,%cl
xor    %ebp,%ebp
or     %al,%cl
sete   %bpl
test   %ebp,%ebp
jne    1190 <include_resfile+0x50>
mov    (%r15),%rsi
mov    %r12,%rdi
call   1040 <fputs@plt>
jmp    1190 <include_resfile+0x50>
mov    (%r15),%rdi
lea    0xe16(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@output = external global i32*
@.str = [26 x i8] c"%%%%BeingResource: %s %s\0A\00"
@.str.1 = [17 x i8] c"%%%%EndResource\0A\00"
define void @include_resfile(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
store i32 0, i32* %8
store i32 0, i32* %9
%10 = load i32*, i32** @output
%11 = load i8*, i8** %4
%12 = load i8*, i8** %5
%13 = call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %12)
br label %14
14: ; preds = %49, %3
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%16 = load i32*, i32** %6
%17 = call i64 @fgets(i8* %15, i32 1024, i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %55
19: ; preds = %14
%20 = load i32, i32* %8
%21 = icmp ne i32 %20, 0
br i1 %21, label %42, label %22
22: ; preds = %19
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 37
br i1 %26, label %27, label %39
27: ; preds = %22
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 1
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 37
br i1 %31, label %37, label %32
32: ; preds = %27
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 1
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 33
br label %37
37: ; preds = %32, %27
%38 = phi i1 [ true, %27 ], [ %36, %32 ]
br label %39
39: ; preds = %37, %22
%40 = phi i1 [ false, %22 ], [ %38, %37 ]
%41 = zext i1 %40 to i32
store i32 %41, i32* %9
br label %42
42: ; preds = %39, %19
%43 = load i32, i32* %9
%44 = icmp ne i32 %43, 0
br i1 %44, label %49, label %45
45: ; preds = %42
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%47 = load i32*, i32** @output
%48 = call i32 @fputs(i8* %46, i32* %47)
br label %49
49: ; preds = %45, %42
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%51 = call i32 @endswith(i8* %50, i8 signext 10)
%52 = icmp ne i32 %51, 0
%53 = xor i1 %52, true
%54 = zext i1 %53 to i32
store i32 %54, i32* %8
br label %14
55: ; preds = %14
%56 = load i32*, i32** @output
%57 = call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@output = external global i32*
@.str = [26 x i8] c"%%%%BeingResource: %s %s\0A\00"
@.str.1 = [17 x i8] c"%%%%EndResource\0A\00"
define void @include_resfile(i8* %0, i8* %1, i32* nocapture %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = load i32*, i32** @output
%7 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%8 = call i64 @fgets(i8* %5, i32 1024, i32* %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %36, label %10
10: ; preds = %3
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 1
br label %12
12: ; preds = %10, %30
%13 = phi i32 [ 0, %10 ], [ %25, %30 ]
%14 = phi i32 [ 0, %10 ], [ %33, %30 ]
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = load i8, i8* %5
%18 = icmp eq i8 %17, 37
%19 = load i8, i8* %11
%20 = and i8 %19, -5
%21 = icmp eq i8 %20, 33
%22 = select i1 %18, i1 %21, i1 false
%23 = zext i1 %22 to i32
br label %24
24: ; preds = %16, %12
%25 = phi i32 [ %13, %12 ], [ %23, %16 ]
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32*, i32** @output
%29 = call i32 @fputs(i8* %5, i32* %28)
br label %30
30: ; preds = %27, %24
%31 = call i32 @endswith(i8* %5, i8 signext 10)
%32 = icmp eq i32 %31, 0
%33 = zext i1 %32 to i32
%34 = call i64 @fgets(i8* %5, i32 1024, i32* %2)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %12
36: ; preds = %30, %3
%37 = load i32*, i32** @output
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
ret void
}