#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 /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ generate_cfile_start(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ generate_function(char *, int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ generate_hfile_end(int /*<<< orphan*/ *);
int /*<<< orphan*/ generate_hfile_start(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *openfile(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ validate_argtypes(char *);
int main(int argc, char **argv) {
  char *hfilename;
  char *cfilename;
  FILE *entrada;
  FILE *hfile;
  FILE *cfile;
  char argtypes[1000];
  if (argc != 4) {
    printf("rastro_generate functions name.c name.h\n");
    exit(0);
  }
  cfilename = argv[2];
  hfilename = argv[3];
  entrada = openfile(argv[1], "r");
  cfile = openfile(cfilename, "w");
  hfile = openfile(hfilename, "w");
  generate_hfile_start(hfile, hfilename);
  generate_cfile_start(cfile, hfilename);
  while (fscanf(entrada, "%s", argtypes) == 1) {
    if (!validate_argtypes(argtypes)) {
      fprintf(stderr, "Invalid event types \"%s\" ignored.\n", argtypes);
      continue;
    }
    generate_function(argtypes, hfile, cfile);
  }
  generate_hfile_end(hfile);
  fclose(entrada);
  fclose(cfile);
  fclose(hfile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11e6 <main+0x36>
lea    0xe26(%rip),%rdi
call   1060 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1c(%rip),%rsi
call   1030 <openfile@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   1030 <openfile@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdf6(%rip),%rsi
call   1030 <openfile@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <generate_hfile_start@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <generate_cfile_start@plt>
mov    -0x28(%rbp),%rdi
lea    -0x420(%rbp),%rdx
lea    0xdc3(%rip),%rsi
call   1080 <fscanf@plt>
cmp    $0x1,%eax
jne    12c7 <main+0x117>
lea    -0x420(%rbp),%rdi
call   1070 <validate_argtypes@plt>
cmp    $0x0,%eax
jne    12ae <main+0xfe>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rdx
lea    0xd8c(%rip),%rsi
call   1090 <fprintf@plt>
jmp    1258 <main+0xa8>
lea    -0x420(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   10a0 <generate_function@plt>
jmp    1258 <main+0xa8>
mov    -0x30(%rbp),%rdi
call   10d0 <generate_hfile_end@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3e8,%rsp
cmp    $0x4,%edi
jne    12c7 <main+0x117>
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rbp
mov    0x18(%rsi),%rbx
lea    0xe23(%rip),%rsi
call   1030 <openfile@plt>
mov    %rax,%r12
lea    0xe16(%rip),%r15
mov    %rbp,%rdi
mov    %r15,%rsi
call   1030 <openfile@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <openfile@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
call   10b0 <generate_hfile_start@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <generate_cfile_start@plt>
lea    0xddf(%rip),%rsi
mov    %rsp,%rdx
mov    %r12,%rdi
call   1080 <fscanf@plt>
cmp    $0x1,%eax
jne    1293 <main+0xe3>
mov    %rsp,%rbx
lea    0xdc8(%rip),%r13
lea    0xdbe(%rip),%rbp
jmp    1277 <main+0xc7>
nopl   0x0(%rax,%rax,1)
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1090 <fprintf@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1080 <fscanf@plt>
cmp    $0x1,%eax
jne    1293 <main+0xe3>
mov    %rbx,%rdi
call   1070 <validate_argtypes@plt>
test   %eax,%eax
je     1250 <main+0xa0>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   10a0 <generate_function@plt>
jmp    1264 <main+0xb4>
mov    %r15,%rdi
call   10d0 <generate_hfile_end@plt>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd5c(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"rastro_generate functions name.c name.h\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [3 x i8] c"%s\00"
@stderr = global i32 0
@.str.4 = [35 x i8] c"Invalid event types \22%s\22 ignored.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca [1000 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 4
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
store i8* %20, i8** %7
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 3
%23 = load i8*, i8** %22
store i8* %23, i8** %6
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32* @openfile(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %27, i32** %8
%28 = load i8*, i8** %7
%29 = call i32* @openfile(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %29, i32** %10
%30 = load i8*, i8** %6
%31 = call i32* @openfile(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %31, i32** %9
%32 = load i32*, i32** %9
%33 = load i8*, i8** %6
%34 = call i32 @generate_hfile_start(i32* %32, i8* %33)
%35 = load i32*, i32** %10
%36 = load i8*, i8** %6
%37 = call i32 @generate_cfile_start(i32* %35, i8* %36)
br label %38
38: ; preds = %51, %47, %17
%39 = load i32*, i32** %8
%40 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%41 = call i32 @fscanf(i32* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %40)
%42 = icmp eq i32 %41, 1
br i1 %42, label %43, label %56
43: ; preds = %38
%44 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%45 = call i32 @validate_argtypes(i8* %44)
%46 = icmp ne i32 %45, 0
br i1 %46, label %51, label %47
47: ; preds = %43
%48 = load i32, i32* @stderr
%49 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%50 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %49)
br label %38
51: ; preds = %43
%52 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%53 = load i32*, i32** %9
%54 = load i32*, i32** %10
%55 = call i32 @generate_function(i8* %52, i32* %53, i32* %54)
br label %38
56: ; preds = %38
%57 = load i32*, i32** %9
%58 = call i32 @generate_hfile_end(i32* %57)
%59 = load i32*, i32** %8
%60 = call i32 @fclose(i32* %59)
%61 = load i32*, i32** %10
%62 = call i32 @fclose(i32* %61)
%63 = load i32*, i32** %9
%64 = call i32 @fclose(i32* %63)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [3 x i8] c"%s\00"
@stderr = global i32 0
@.str.4 = [35 x i8] c"Invalid event types \22%s\22 ignored.\0A\00"
@str = [40 x i8] c"rastro_generate functions name.c name.h\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 4
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8*, i8** %1, i64 3
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32* @openfile(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32* @openfile(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = tail call i32* @openfile(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @generate_hfile_start(i32* %18, i8* %13)
%20 = tail call i32 @generate_cfile_start(i32* %17, i8* %13)
%21 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %34
23: ; preds = %9, %29
%24 = call i32 @validate_argtypes(i8* %4)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %4)
br label %29
29: ; preds = %26, %32
%30 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%31 = icmp eq i32 %30, 1
br i1 %31, label %23, label %34
32: ; preds = %23
%33 = call i32 @generate_function(i8* %4, i32* %18, i32* %17)
br label %29
34: ; preds = %29, %9
%35 = call i32 @generate_hfile_end(i32* %18)
%36 = call i32 @fclose(i32* %16)
%37 = call i32 @fclose(i32* %17)
%38 = call i32 @fclose(i32* %18)
ret i32 0
}