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

/* Variables and functions */
char *cat(char *, char *);
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ fatal(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ filter(int /*<<< orphan*/ *, int /*<<< orphan*/ *, char *,
                          int, int *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
int is_header(char *);
scalar_t__ readln(int /*<<< orphan*/ *, int *);
char *strip_suffix(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void generate(char *name) {
  int ih = is_header(name), lineno = 0;
  char *base = strip_suffix(name), *src_name = cat(base, ".tmpl");
  FILE *src = fopen(src_name, "r"), *dst;
  time_t t;
  if (!src)
    fatal("could not open `%s' for reading\n", src_name);
  dst = fopen(name, "w");
  if (!dst)
    fatal("could not open `%s' for writing\n", name);
  fprintf(dst, "/* THIS FILE IS AUTOMICALLY GENERATED -- DO NOT EDIT\n");
  time(&t);
  fprintf(dst, " * from `%s' on %s */\n\n", src_name, ctime(&t));
  if (ih) {
    fprintf(dst, "#ifndef _%s_h_INCLUDED\n", base);
    fprintf(dst, "#define _%s_h_INCLUDED\n\n", base);
  }
  while (readln(src, &lineno))
    filter(src, dst, src_name, ih, &lineno);
  if (ih)
    fprintf(dst, "#endif\n");
  free(base);
  free(src_name);
  fclose(dst);
  fclose(src);
}


x86 assembly (clang, -O0):
<generate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <is_header@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   10c0 <strip_suffix@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   10e0 <cat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    122f <generate+0x6f>
mov    -0x20(%rbp),%rsi
lea    0xdde(%rip),%rdi
call   10d0 <fatal@plt>
mov    -0x8(%rbp),%rdi
lea    0xdef(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    125e <generate+0x9e>
mov    -0x8(%rbp),%rsi
lea    0xdd2(%rip),%rdi
call   10d0 <fatal@plt>
mov    -0x30(%rbp),%rdi
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    -0x34(%rbp),%rdi
call   1090 <time@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x34(%rbp),%rdi
call   1050 <ctime@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xdde(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
cmpl   $0x0,-0xc(%rbp)
je     12e1 <generate+0x121>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdd6(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdd8(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    12e6 <generate+0x126>
mov    -0x28(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   10a0 <readln@plt>
cmp    $0x0,%rax
je     131a <generate+0x15a>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    -0x10(%rbp),%r8
call   1060 <filter@plt>
jmp    12e6 <generate+0x126>
cmpl   $0x0,-0xc(%rbp)
je     1336 <generate+0x176>
mov    -0x30(%rbp),%rdi
lea    0xd9c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r13
call   1070 <is_header@plt>
mov    %eax,%r12d
movl   $0x0,0x4(%rsp)
mov    %r13,%rdi
call   10c0 <strip_suffix@plt>
lea    0xe00(%rip),%rsi
mov    %rax,0x8(%rsp)
mov    %rax,%rdi
call   10f0 <cat@plt>
mov    %rax,%r15
lea    0xdef(%rip),%rsi
mov    %rax,%rdi
call   10b0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1236 <generate+0x66>
lea    0xdda(%rip),%rdi
mov    %r15,%rsi
call   10e0 <fatal@plt>
lea    0xdec(%rip),%rsi
mov    %r13,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    125c <generate+0x8c>
lea    0xdd7(%rip),%rdi
mov    %r13,%rsi
call   10e0 <fatal@plt>
lea    0xde9(%rip),%rdi
mov    $0x35,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10d0 <fwrite@plt>
lea    0x14(%rsp),%rbp
mov    %rbp,%rdi
call   1090 <time@plt>
mov    %rbp,%rdi
call   1050 <ctime@plt>
lea    0xdf1(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
test   %r12d,%r12d
mov    0x8(%rsp),%r13
je     12d3 <generate+0x103>
lea    0xde8(%rip),%rsi
mov    %r14,%rdi
mov    %r13,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xdec(%rip),%rsi
mov    %r14,%rdi
mov    %r13,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   10a0 <readln@plt>
test   %rax,%rax
je     1314 <generate+0x144>
lea    0x4(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12d,%ecx
mov    %rbp,%r8
call   1060 <filter@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10a0 <readln@plt>
test   %rax,%rax
jne    12f0 <generate+0x120>
test   %r12d,%r12d
je     1332 <generate+0x162>
lea    0xdab(%rip),%rdi
mov    $0x7,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10d0 <fwrite@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c".tmpl\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"could not open `%s' for reading\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [33 x i8] c"could not open `%s' for writing\0A\00"
@.str.5 = [54 x i8] c"/* THIS FILE IS AUTOMICALLY GENERATED -- DO NOT EDIT\0A\00"
@.str.6 = [24 x i8] c" * from `%s' on %s */\0A\0A\00"
@.str.7 = [24 x i8] c"#ifndef _%s_h_INCLUDED\0A\00"
@.str.8 = [25 x i8] c"#define _%s_h_INCLUDED\0A\0A\00"
@.str.9 = [8 x i8] c"#endif\0A\00"
define void @generate(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %2
%10 = load i8*, i8** %2
%11 = call i32 @is_header(i8* %10)
store i32 %11, i32* %3
store i32 0, i32* %4
%12 = load i8*, i8** %2
%13 = call i8* @strip_suffix(i8* %12)
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = call i8* @cat(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %7
%18 = load i32*, i32** %7
%19 = icmp ne i32* %18, null
br i1 %19, label %23, label %20
20: ; preds = %1
%21 = load i8*, i8** %6
%22 = call i32 @fatal(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %20, %1
%24 = load i8*, i8** %2
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %25, i32** %8
%26 = load i32*, i32** %8
%27 = icmp ne i32* %26, null
br i1 %27, label %31, label %28
28: ; preds = %23
%29 = load i8*, i8** %2
%30 = call i32 @fatal(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %28, %23
%32 = load i32*, i32** %8
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0))
%34 = call i32 @time(i32* %9)
%35 = load i32*, i32** %8
%36 = load i8*, i8** %6
%37 = call i8* @ctime(i32* %9)
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %36, i8* %37)
%39 = load i32, i32* %3
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %48
41: ; preds = %31
%42 = load i32*, i32** %8
%43 = load i8*, i8** %5
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %43)
%45 = load i32*, i32** %8
%46 = load i8*, i8** %5
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %41, %31
br label %49
49: ; preds = %53, %48
%50 = load i32*, i32** %7
%51 = call i64 @readln(i32* %50, i32* %4)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %59
53: ; preds = %49
%54 = load i32*, i32** %7
%55 = load i32*, i32** %8
%56 = load i8*, i8** %6
%57 = load i32, i32* %3
%58 = call i32 @filter(i32* %54, i32* %55, i8* %56, i32 %57, i32* %4)
br label %49
59: ; preds = %49
%60 = load i32, i32* %3
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %59
%63 = load i32*, i32** %8
%64 = call i32 (i32*, i8*, ...) @fprintf(i32* %63, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
br label %65
65: ; preds = %62, %59
%66 = load i8*, i8** %5
%67 = call i32 @free(i8* %66)
%68 = load i8*, i8** %6
%69 = call i32 @free(i8* %68)
%70 = load i32*, i32** %8
%71 = call i32 @fclose(i32* %70)
%72 = load i32*, i32** %7
%73 = call i32 @fclose(i32* %72)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c".tmpl\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"could not open `%s' for reading\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [33 x i8] c"could not open `%s' for writing\0A\00"
@.str.5 = [54 x i8] c"/* THIS FILE IS AUTOMICALLY GENERATED -- DO NOT EDIT\0A\00"
@.str.6 = [24 x i8] c" * from `%s' on %s */\0A\0A\00"
@.str.7 = [24 x i8] c"#ifndef _%s_h_INCLUDED\0A\00"
@.str.8 = [25 x i8] c"#define _%s_h_INCLUDED\0A\0A\00"
@.str.9 = [8 x i8] c"#endif\0A\00"
define void @generate(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = tail call i32 @is_header(i8* %0)
%5 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%6 = tail call i8* @strip_suffix(i8* %0)
%7 = tail call i8* @cat(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = bitcast i32* %3 to i8*
%10 = icmp eq i32* %8, null
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = tail call i32 @fatal(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %7)
br label %13
13: ; preds = %11, %1
%14 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @fatal(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %18
18: ; preds = %16, %13
%19 = tail call i64 @fwrite(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i64 53, i64 1, i32* %14)
%20 = call i32 @time(i32* %3)
%21 = call i8* @ctime(i32* %3)
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %7, i8* %21)
%23 = icmp eq i32 %4, 0
br i1 %23, label %27, label %24
24: ; preds = %18
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %6)
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i8* %6)
br label %27
27: ; preds = %24, %18
%28 = call i64 @readln(i32* %8, i32* %2)
%29 = icmp eq i64 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %27, %30
%31 = call i32 @filter(i32* %8, i32* %14, i8* %7, i32 %4, i32* %2)
%32 = call i64 @readln(i32* %8, i32* %2)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %30
34: ; preds = %30, %27
br i1 %23, label %37, label %35
35: ; preds = %34
%36 = call i64 @fwrite(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i64 7, i64 1, i32* %14)
br label %37
37: ; preds = %35, %34
%38 = call i32 @free(i8* %6)
%39 = call i32 @free(i8* %7)
%40 = call i32 @fclose(i32* %14)
%41 = call i32 @fclose(i32* %8)
ret void
}