#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  FILE *fp;
  int i;
  char *fName;
  if (argc < 2) {
    printf("usage: makeprims filename FooPlugin BarPlugin ...\n");
    return -1;
  }
  fName = argv[1];
  fp = fopen(fName, "wt");
  if (!fp) {
    printf("makeprims: Failed to open %s\n", fName);
    return -1;
  }
  fprintf(fp, "/* This is an automatically generated table of all builtin "
              "modules in the VM */\n\n");
  fprintf(fp, "extern sqExport vm_exports[];\n");
  fprintf(fp, "extern sqExport os_exports[];\n");
  for (i = 2; i < argc; i++) {
    fprintf(fp, "extern sqExport %s_exports[];\n", argv[i]);
  }
  fprintf(fp, "\nsqExport *pluginExports[] = {\n");
  fprintf(fp, "\tvm_exports,\n");
  fprintf(fp, "\tos_exports,\n");
  for (i = 2; i < argc; i++) {
    fprintf(fp, "\t%s_exports,\n", argv[i]);
  }
  fprintf(fp, "\tNULL\n");
  fprintf(fp, "};\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    116a <main+0x3a>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c8 <main+0x198>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b3 <main+0x83>
mov    -0x28(%rbp),%rsi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c8 <main+0x198>
mov    -0x18(%rbp),%rdi
lea    0xe96(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xed6(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xee3(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x2,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1228 <main+0xf8>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xed1(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11f0 <main+0xc0>
mov    -0x18(%rbp),%rdi
lea    0xed0(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xede(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xeda(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x2,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    129d <main+0x16d>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xeb7(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1265 <main+0x135>
mov    -0x18(%rbp),%rdi
lea    0xea5(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe9a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     1176 <main+0x26>
lea    0xfbe(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    1334 <main+0x1e4>
mov    %rsi,%r13
mov    %edi,%r15d
mov    0x8(%rsi),%rbp
lea    0xe79(%rip),%rsi
mov    %rbp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     129d <main+0x14d>
mov    %rax,%r14
lea    0xe7f(%rip),%rdi
mov    $0x51,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
lea    0xeb8(%rip),%rdi
mov    $0x1e,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
lea    0xebe(%rip),%rdi
mov    $0x1e,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
cmp    $0x3,%r15d
jb     12b5 <main+0x165>
mov    %r15d,%ebp
mov    $0x2,%ebx
lea    0xeb2(%rip),%r12
nop
mov    0x0(%r13,%rbx,8),%rdx
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1200 <main+0xb0>
lea    0xeae(%rip),%rdi
mov    $0x1f,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
lea    0xeb5(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
lea    0xeaa(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
cmp    $0x3,%r15d
jb     1300 <main+0x1b0>
mov    $0x2,%ebx
lea    0xe90(%rip),%r15
nopl   0x0(%rax)
mov    0x0(%r13,%rbx,8),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1280 <main+0x130>
jmp    1300 <main+0x1b0>
lea    0xd5f(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
jmp    1334 <main+0x1e4>
lea    0xe14(%rip),%rdi
mov    $0x1f,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
lea    0xe1b(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
lea    0xe10(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
lea    0xe13(%rip),%rdi
mov    $0x6,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
lea    0xe01(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [51 x i8] c"usage: makeprims filename FooPlugin BarPlugin ...\0A\00"
@.str.1 = [3 x i8] c"wt\00"
@.str.2 = [30 x i8] c"makeprims: Failed to open %s\0A\00"
@.str.3 = [82 x i8] c"/* This is an automatically generated table of all builtin modules in the VM */\0A\0A\00"
@.str.4 = [31 x i8] c"extern sqExport vm_exports[];\0A\00"
@.str.5 = [31 x i8] c"extern sqExport os_exports[];\0A\00"
@.str.6 = [31 x i8] c"extern sqExport %s_exports[];\0A\00"
@.str.7 = [32 x i8] c"\0AsqExport *pluginExports[] = {\0A\00"
@.str.8 = [14 x i8] c"\09vm_exports,\0A\00"
@.str.9 = [14 x i8] c"\09os_exports,\0A\00"
@.str.10 = [14 x i8] c"\09%s_exports,\0A\00"
@.str.11 = [7 x i8] c"\09NULL\0A\00"
@.str.12 = [4 x i8] c"};\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 i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %73
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %8
%17 = load i8*, i8** %8
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp ne i32* %19, null
br i1 %20, label %24, label %21
21: ; preds = %13
%22 = load i8*, i8** %8
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %22)
store i32 -1, i32* %3
br label %73
24: ; preds = %13
%25 = load i32*, i32** %6
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.3, i64 0, i64 0))
%27 = load i32*, i32** %6
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%29 = load i32*, i32** %6
%30 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
store i32 2, i32* %7
br label %31
31: ; preds = %43, %24
%32 = load i32, i32* %7
%33 = load i32, i32* %4
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %46
35: ; preds = %31
%36 = load i32*, i32** %6
%37 = load i8**, i8*** %5
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %35
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %31
46: ; preds = %31
%47 = load i32*, i32** %6
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0))
%49 = load i32*, i32** %6
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%51 = load i32*, i32** %6
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
store i32 2, i32* %7
br label %53
53: ; preds = %65, %46
%54 = load i32, i32* %7
%55 = load i32, i32* %4
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %68
57: ; preds = %53
%58 = load i32*, i32** %6
%59 = load i8**, i8*** %5
%60 = load i32, i32* %7
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8*, i8** %59, i64 %61
%63 = load i8*, i8** %62
%64 = call i32 (i32*, i8*, ...) @fprintf(i32* %58, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i8* %63)
br label %65
65: ; preds = %57
%66 = load i32, i32* %7
%67 = add nsw i32 %66, 1
store i32 %67, i32* %7
br label %53
68: ; preds = %53
%69 = load i32*, i32** %6
%70 = call i32 (i32*, i8*, ...) @fprintf(i32* %69, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0))
%71 = load i32*, i32** %6
%72 = call i32 (i32*, i8*, ...) @fprintf(i32* %71, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0))
store i32 0, i32* %3
br label %73
73: ; preds = %68, %21, %11
%74 = load i32, i32* %3
ret i32 %74
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"wt\00"
@.str.2 = [30 x i8] c"makeprims: Failed to open %s\0A\00"
@.str.3 = [82 x i8] c"/* This is an automatically generated table of all builtin modules in the VM */\0A\0A\00"
@.str.4 = [31 x i8] c"extern sqExport vm_exports[];\0A\00"
@.str.5 = [31 x i8] c"extern sqExport os_exports[];\0A\00"
@.str.6 = [31 x i8] c"extern sqExport %s_exports[];\0A\00"
@.str.7 = [32 x i8] c"\0AsqExport *pluginExports[] = {\0A\00"
@.str.8 = [14 x i8] c"\09vm_exports,\0A\00"
@.str.9 = [14 x i8] c"\09os_exports,\0A\00"
@.str.10 = [14 x i8] c"\09%s_exports,\0A\00"
@.str.11 = [7 x i8] c"\09NULL\0A\00"
@.str.12 = [4 x i8] c"};\0A\00"
@str = [50 x i8] c"usage: makeprims filename FooPlugin BarPlugin ...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
br label %47
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %8)
br label %47
13: ; preds = %6
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.3, i64 0, i64 0), i64 81, i64 1, i32* %9)
%15 = tail call i64 @fwrite(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i64 30, i64 1, i32* %9)
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i64 30, i64 1, i32* %9)
%17 = icmp ugt i32 %0, 2
br i1 %17, label %18, label %40
18: ; preds = %13
%19 = zext i32 %0 to i64
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ 2, %18 ], [ %25, %20 ]
%22 = getelementptr inbounds i8*, i8** %1, i64 %21
%23 = load i8*, i8** %22
%24 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i8* %23)
%25 = add nuw nsw i64 %21, 1
%26 = icmp eq i64 %25, %19
br i1 %26, label %27, label %20
27: ; preds = %20
%28 = tail call i64 @fwrite(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i64 31, i64 1, i32* %9)
%29 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i64 13, i64 1, i32* %9)
%30 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), i64 13, i64 1, i32* %9)
br i1 %17, label %31, label %44
31: ; preds = %27
%32 = zext i32 %0 to i64
br label %33
33: ; preds = %31, %33
%34 = phi i64 [ 2, %31 ], [ %38, %33 ]
%35 = getelementptr inbounds i8*, i8** %1, i64 %34
%36 = load i8*, i8** %35
%37 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i8* %36)
%38 = add nuw nsw i64 %34, 1
%39 = icmp eq i64 %38, %32
br i1 %39, label %44, label %33
40: ; preds = %13
%41 = tail call i64 @fwrite(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i64 31, i64 1, i32* %9)
%42 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i64 13, i64 1, i32* %9)
%43 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), i64 13, i64 1, i32* %9)
br label %44
44: ; preds = %33, %40, %27
%45 = tail call i64 @fwrite(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i64 6, i64 1, i32* %9)
%46 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i64 3, i64 1, i32* %9)
br label %47
47: ; preds = %44, %11, %4
%48 = phi i32 [ -1, %4 ], [ 0, %44 ], [ -1, %11 ]
ret i32 %48
}