#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int write_file(int /*<<< orphan*/ *, char *, char *);
int main(int argc, char **argv) {
  FILE *file;
  int i, count;
  char data_name[80], *cp;
  if (argc < 3) {
    printf("Keystone Application Framework File to Module tool\n");
    printf("Copyright (C) Jacob Lister, Abbey Systems 2003.  All rights "
           "reserved.\n\n");
    printf("usage: file2module <outfile> <infiles>\n");
    return 1;
  }
  file = fopen(argv[1], "w");
  fprintf(file, "MODULE::IMPLEMENTATION\n");
  fprintf(file, "#include \"framework.c\"\n");
  for (i = 0; i < argc - 2; i++) {
    sprintf(data_name, "_file_%s", argv[2 + i]);
    cp = data_name;
    while (*cp) {
      if (*cp == '.')
        *cp = '_';
      cp++;
    }
    count = write_file(file, argv[2 + i], data_name);
    fprintf(file, "TMemFileDef _%s_def = {\"%s\", %d, %s};\n", data_name,
            argv[2 + i], count, data_name);
    fprintf(file, "OBJECT<CMemFile, _%s, &_%s_def>;\n\n", data_name, data_name);
  }
  fprintf(file, "MODULE::END\n");
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11b3 <main+0x53>
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
lea    0xe9e(%rip),%rdi
call   1040 <printf@plt>
lea    0xeda(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ff <main+0x19f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xee2(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xed0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xed6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    12dd <main+0x17d>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xeb3(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
cmpb   $0x0,(%rax)
je     1265 <main+0x105>
mov    -0x78(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1254 <main+0xf4>
mov    -0x78(%rbp),%rax
movb   $0x5f,(%rax)
mov    -0x78(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x78(%rbp)
jmp    1230 <main+0xd0>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    -0x70(%rbp),%rdx
call   1050 <write_file@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x70(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x20(%rbp),%r8d
lea    -0x70(%rbp),%r9
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x70(%rbp),%rdx
lea    -0x70(%rbp),%rcx
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11f6 <main+0x96>
mov    -0x18(%rbp),%rdi
lea    0xe41(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
cmp    $0x2,%edi
jg     11b1 <main+0x41>
lea    0xf08(%rip),%rdi
call   1030 <puts@plt>
lea    0xf2f(%rip),%rdi
call   1030 <puts@plt>
lea    0xf6a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    12b1 <main+0x141>
mov    %rsi,%r14
mov    %edi,%r15d
mov    0x8(%rsi),%rdi
lea    0xe3e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
lea    0xe31(%rip),%rdi
mov    $0x17,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
lea    0xe30(%rip),%rdi
mov    $0x17,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1090 <fwrite@plt>
add    $0xfffffffe,%r15d
mov    %rsp,%rbx
lea    0xe58(%rip),%r13
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    0x10(%r14,%rbp,8),%rdx
mov    %rbx,%rdi
lea    0xe13(%rip),%rsi
call   1080 <sprintf@plt>
mov    %rbx,%rax
jmp    1237 <main+0xc7>
nopl   0x0(%rax)
movb   $0x5f,(%rax)
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0x2e,%cl
je     1230 <main+0xc0>
test   %cl,%cl
jne    1233 <main+0xc3>
mov    0x10(%r14,%rbp,8),%rsi
mov    %r12,%rdi
mov    %rbx,%rdx
call   1050 <write_file@plt>
mov    0x10(%r14,%rbp,8),%rcx
mov    %r12,%rdi
lea    0xdd9(%rip),%rsi
mov    %rbx,%rdx
mov    %eax,%r8d
mov    %rbx,%r9
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%rbp
cmp    %r15,%rbp
jne    1210 <main+0xa0>
lea    0xdf0(%rip),%rdi
mov    $0xc,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1090 <fwrite@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [52 x i8] c"Keystone Application Framework File to Module tool\0A\00"
@.str.1 = [72 x i8] c"Copyright (C) Jacob Lister, Abbey Systems 2003. All rights reserved.\0A\0A\00"
@.str.2 = [40 x i8] c"usage: file2module <outfile> <infiles>\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [24 x i8] c"MODULE::IMPLEMENTATION\0A\00"
@.str.5 = [24 x i8] c"#include \22framework.c\22\0A\00"
@.str.6 = [9 x i8] c"_file_%s\00"
@.str.7 = [39 x i8] c"TMemFileDef _%s_def = {\22%s\22, %d, %s};\0A\00"
@.str.8 = [35 x i8] c"OBJECT<CMemFile, _%s, &_%s_def>;\0A\0A\00"
@.str.9 = [13 x i8] c"MODULE::END\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [80 x i8]
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %88
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%24 = load i32*, i32** %6
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %7
br label %26
26: ; preds = %80, %17
%27 = load i32, i32* %7
%28 = load i32, i32* %4
%29 = sub nsw i32 %28, 2
%30 = icmp slt i32 %27, %29
br i1 %30, label %31, label %83
31: ; preds = %26
%32 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%33 = load i8**, i8*** %5
%34 = load i32, i32* %7
%35 = add nsw i32 2, %34
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %33, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %38)
%40 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
store i8* %40, i8** %10
br label %41
41: ; preds = %52, %31
%42 = load i8*, i8** %10
%43 = load i8, i8* %42
%44 = icmp ne i8 %43, 0
br i1 %44, label %45, label %55
45: ; preds = %41
%46 = load i8*, i8** %10
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 46
br i1 %49, label %50, label %52
50: ; preds = %45
%51 = load i8*, i8** %10
store i8 95, i8* %51
br label %52
52: ; preds = %50, %45
%53 = load i8*, i8** %10
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %10
br label %41
55: ; preds = %41
%56 = load i32*, i32** %6
%57 = load i8**, i8*** %5
%58 = load i32, i32* %7
%59 = add nsw i32 2, %58
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %57, i64 %60
%62 = load i8*, i8** %61
%63 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%64 = call i32 @write_file(i32* %56, i8* %62, i8* %63)
store i32 %64, i32* %8
%65 = load i32*, i32** %6
%66 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%67 = load i8**, i8*** %5
%68 = load i32, i32* %7
%69 = add nsw i32 2, %68
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8*, i8** %67, i64 %70
%72 = load i8*, i8** %71
%73 = load i32, i32* %8
%74 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%75 = call i32 (i32*, i8*, ...) @fprintf(i32* %65, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i8* %66, i8* %72, i32 %73, i8* %74)
%76 = load i32*, i32** %6
%77 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%78 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%79 = call i32 (i32*, i8*, ...) @fprintf(i32* %76, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* %77, i8* %78)
br label %80
80: ; preds = %55
%81 = load i32, i32* %7
%82 = add nsw i32 %81, 1
store i32 %82, i32* %7
br label %26
83: ; preds = %26
%84 = load i32*, i32** %6
%85 = call i32 (i32*, i8*, ...) @fprintf(i32* %84, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
%86 = load i32*, i32** %6
%87 = call i32 @fclose(i32* %86)
store i32 0, i32* %3
br label %88
88: ; preds = %83, %13
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [24 x i8] c"MODULE::IMPLEMENTATION\0A\00"
@.str.5 = [24 x i8] c"#include \22framework.c\22\0A\00"
@.str.6 = [9 x i8] c"_file_%s\00"
@.str.7 = [39 x i8] c"TMemFileDef _%s_def = {\22%s\22, %d, %s};\0A\00"
@.str.8 = [35 x i8] c"OBJECT<CMemFile, _%s, &_%s_def>;\0A\0A\00"
@.str.9 = [13 x i8] c"MODULE::END\0A\00"
@str = [51 x i8] c"Keystone Application Framework File to Module tool\00"
@str.10 = [71 x i8] c"Copyright (C) Jacob Lister, Abbey Systems 2003. All rights reserved.\0A\00"
@str.11 = [39 x i8] c"usage: file2module <outfile> <infiles>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str.10, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.11, i64 0, i64 0))
br label %41
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i64 23, i64 1, i32* %13)
%15 = tail call i64 @fwrite(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i64 23, i64 1, i32* %13)
%16 = add nsw i32 %0, -2
%17 = zext i32 %16 to i64
br label %18
18: ; preds = %10, %30
%19 = phi i64 [ 0, %10 ], [ %36, %30 ]
%20 = add nuw nsw i64 %19, 2
%21 = getelementptr inbounds i8*, i8** %1, i64 %20
%22 = load i8*, i8** %21
%23 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %28, %18
%25 = phi i8* [ %4, %18 ], [ %29, %28 ]
%26 = load i8, i8* %25
switch i8 %26, label %28 [
i8 0, label %30
i8 46, label %27
]
27: ; preds = %24
store i8 95, i8* %25
br label %28
28: ; preds = %24, %27
%29 = getelementptr inbounds i8, i8* %25, i64 1
br label %24
30: ; preds = %24
%31 = load i8*, i8** %21
%32 = call i32 @write_file(i32* %13, i8* %31, i8* %4)
%33 = load i8*, i8** %21
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i8* %4, i8* %33, i32 %32, i8* %4)
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* %4, i8* %4)
%36 = add nuw nsw i64 %19, 1
%37 = icmp eq i64 %36, %17
br i1 %37, label %38, label %18
38: ; preds = %30
%39 = call i64 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i64 12, i64 1, i32* %13)
%40 = call i32 @fclose(i32* %13)
br label %41
41: ; preds = %38, %6
%42 = phi i32 [ 1, %6 ], [ 0, %38 ]
ret i32 %42
}