#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*/ exit(int);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ outline(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stderr;
void process_template(char *file, char *var) {
  char line[132];
  FILE *f;
  f = fopen(file, "r");
  if (!f) {
    fprintf(stderr, "could not open file %s\n", file);
    exit(1);
  }
  printf("const char * %s = \n", var);
  while (fgets(line, 131, f)) {
    if (line[0] == '%')
      continue;
    putchar('"');
    outline(line);
    printf("\\n\"\n");
  }
  printf(";\n");
}


x86 assembly (clang, -O0):
<process_template>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
jne    11cb <process_template+0x5b>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe46(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rsi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xa0(%rbp),%rdi
mov    -0xa8(%rbp),%rdx
mov    $0x83,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     123d <process_template+0xcd>
movsbl -0xa0(%rbp),%eax
cmp    $0x25,%eax
jne    1214 <process_template+0xa4>
jmp    11dd <process_template+0x6d>
mov    $0x22,%edi
call   1030 <putchar@plt>
lea    -0xa0(%rbp),%rdi
call   1090 <outline@plt>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11dd <process_template+0x6d>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_template>:
push   %r15
push   %r14
push   %rbx
sub    $0x90,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe67(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1230 <process_template+0xb0>
mov    %rax,%rbx
lea    0xe69(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rdi
mov    $0x83,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1217 <process_template+0x97>
mov    %rsp,%r14
lea    0xe56(%rip),%r15
jmp    11f5 <process_template+0x75>
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x83,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1217 <process_template+0x97>
cmpb   $0x25,(%rsp)
je     11e0 <process_template+0x60>
mov    $0x22,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   10a0 <outline@plt>
mov    %r15,%rdi
call   1040 <puts@plt>
jmp    11e0 <process_template+0x60>
lea    0xe10(%rip),%rdi
call   1040 <puts@plt>
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
lea    0xdc2(%rip),%rsi
mov    %r15,%rdx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"could not open file %s\0A\00"
@.str.2 = [20 x i8] c"const char * %s = \0A\00"
@.str.3 = [5 x i8] c"\\n\22\0A\00"
@.str.4 = [3 x i8] c";\0A\00"
define void @process_template(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [132 x i8]
%6 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %3
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %30, %29, %16
%20 = getelementptr inbounds [132 x i8], [132 x i8]* %5, i64 0, i64 0
%21 = load i32*, i32** %6
%22 = call i64 @fgets(i8* %20, i32 131, i32* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %35
24: ; preds = %19
%25 = getelementptr inbounds [132 x i8], [132 x i8]* %5, i64 0, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 37
br i1 %28, label %29, label %30
29: ; preds = %24
br label %19
30: ; preds = %24
%31 = call i32 @putchar(i8 signext 34)
%32 = getelementptr inbounds [132 x i8], [132 x i8]* %5, i64 0, i64 0
%33 = call i32 @outline(i8* %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %19
35: ; preds = %19
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"could not open file %s\0A\00"
@.str.2 = [20 x i8] c"const char * %s = \0A\00"
@str = [2 x i8] c";\00"
@str.5 = [4 x i8] c"\\n\22\00"
define void @process_template(i8* %0, i8* %1) {
%3 = alloca [132 x i8]
%4 = getelementptr inbounds [132 x i8], [132 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%13 = call i64 @fgets(i8* %4, i32 131, i32* %5)
%14 = icmp eq i64 %13, 0
br i1 %14, label %25, label %15
15: ; preds = %11, %22
%16 = load i8, i8* %4
%17 = icmp eq i8 %16, 37
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = call i32 @putchar(i8 signext 34)
%20 = call i32 @outline(i8* %4)
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.5, i64 0, i64 0))
br label %22
22: ; preds = %18, %15
%23 = call i64 @fgets(i8* %4, i32 131, i32* %5)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %15
25: ; preds = %22, %11
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
}