#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ lrexe_execute(char *);
int lrexe_init();
int /*<<< orphan*/ lrexe_release();
scalar_t__ malloc(long);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int ret;
  FILE *fp;
  char *fpath;
  char *code;
  long size;
  if (argc < 2) {
    printf("not input rule files. example: \n\tlrexe [FILE]\n");
    exit(0);
  }
  fpath = argv[1];
  fp = fopen(fpath, "r");
  if (!fp) {
    printf("Cannot open rule file %s\n", fpath);
    exit(0);
  }
  fseek(fp, SEEK_SET, SEEK_END);
  size = ftell(fp);
  printf("%s size:%ld\n", fpath, size);
  rewind(fp);
  code = (char *)malloc(size + 1);
  ret = fread(code, 1, size, fp);
  if (ret != size) {
    printf("Read %s failed.\n", fpath);
  }
  code[size] = '\0';
  fclose(fp);
  ret = lrexe_init();
  if (ret)
    exit(0);
  printf("Execute rule file: %s\n", fpath);
  lrexe_execute(code);
  lrexe_release();
  free(code);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1205 <main+0x35>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe13(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1249 <main+0x79>
mov    -0x28(%rbp),%rsi
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
mov    0x2d8b(%rip),%rax
mov    (%rax),%edx
call   10c0 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1070 <rewind@plt>
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
call   10b0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    -0x38(%rbp),%rax
je     12da <main+0x10a>
mov    -0x28(%rbp),%rsi
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x0,%al
call   10e0 <lrexe_init@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     130a <main+0x13a>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    -0x28(%rbp),%rsi
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x30(%rbp),%rdi
call   10a0 <lrexe_execute@plt>
mov    $0x0,%al
call   1080 <lrexe_release@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jle    12d6 <main+0xf6>
mov    0x8(%rsi),%r14
lea    0xe04(%rip),%rsi
mov    %r14,%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     12e9 <main+0x109>
mov    %rax,%r12
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
mov    0x2dc8(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
call   10d0 <fseek@plt>
mov    %r12,%rdi
call   10a0 <ftell@plt>
mov    %rax,%rbx
lea    0xde0(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
call   1080 <rewind@plt>
lea    0x1(%rbx),%rdi
call   10c0 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1050 <fread@plt>
cltq
cmp    %rax,%rbx
je     1288 <main+0xa8>
lea    0xdab(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
movb   $0x0,(%r15,%rbx,1)
mov    %r12,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
call   10f0 <lrexe_init@plt>
test   %eax,%eax
jne    12fa <main+0x11a>
lea    0xd93(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rdi
call   10b0 <lrexe_execute@plt>
xor    %eax,%eax
call   1090 <lrexe_release@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd74(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1100 <exit@plt>
lea    0xd12(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
@.str = [47 x i8] c"not input rule files. example: \0A\09lrexe [FILE]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Cannot open rule file %s\0A\00"
@SEEK_SET = global i32 0
@SEEK_END = global i32 0
@.str.3 = [13 x i8] c"%s size:%ld\0A\00"
@.str.4 = [17 x i8] c"Read %s failed.\0A\00"
@.str.5 = [23 x i8] c"Execute rule file: %s\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*
%9 = alloca i8*
%10 = alloca i64
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, 2
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %8
%20 = load i8*, i8** %8
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %7
%22 = load i32*, i32** %7
%23 = icmp ne i32* %22, null
br i1 %23, label %28, label %24
24: ; preds = %16
%25 = load i8*, i8** %8
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %16
%29 = load i32*, i32** %7
%30 = load i32, i32* @SEEK_SET
%31 = load i32, i32* @SEEK_END
%32 = call i32 @fseek(i32* %29, i32 %30, i32 %31)
%33 = load i32*, i32** %7
%34 = call i64 @ftell(i32* %33)
store i64 %34, i64* %10
%35 = load i8*, i8** %8
%36 = load i64, i64* %10
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %35, i64 %36)
%38 = load i32*, i32** %7
%39 = call i32 @rewind(i32* %38)
%40 = load i64, i64* %10
%41 = add nsw i64 %40, 1
%42 = call i64 @malloc(i64 %41)
%43 = inttoptr i64 %42 to i8*
store i8* %43, i8** %9
%44 = load i8*, i8** %9
%45 = load i64, i64* %10
%46 = load i32*, i32** %7
%47 = call i32 @fread(i8* %44, i32 1, i64 %45, i32* %46)
store i32 %47, i32* %6
%48 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = load i64, i64* %10
%51 = icmp ne i64 %49, %50
br i1 %51, label %52, label %55
52: ; preds = %28
%53 = load i8*, i8** %8
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %52, %28
%56 = load i8*, i8** %9
%57 = load i64, i64* %10
%58 = getelementptr inbounds i8, i8* %56, i64 %57
store i8 0, i8* %58
%59 = load i32*, i32** %7
%60 = call i32 @fclose(i32* %59)
%61 = call i32 (...) @lrexe_init()
store i32 %61, i32* %6
%62 = load i32, i32* %6
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %55
%65 = call i32 @exit(i32 0)
unreachable
66: ; preds = %55
%67 = load i8*, i8** %8
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %67)
%69 = load i8*, i8** %9
%70 = call i32 @lrexe_execute(i8* %69)
%71 = call i32 (...) @lrexe_release()
%72 = load i8*, i8** %9
%73 = call i32 @free(i8* %72)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Cannot open rule file %s\0A\00"
@SEEK_SET = global i32 0
@SEEK_END = global i32 0
@.str.3 = [13 x i8] c"%s size:%ld\0A\00"
@.str.4 = [17 x i8] c"Read %s failed.\0A\00"
@.str.5 = [23 x i8] c"Execute rule file: %s\0A\00"
@str = [46 x i8] c"not input rule files. example: \0A\09lrexe [FILE]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 0)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %7
%16 = load i32, i32* @SEEK_SET
%17 = load i32, i32* @SEEK_END
%18 = tail call i32 @fseek(i32* %10, i32 %16, i32 %17)
%19 = tail call i64 @ftell(i32* %10)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %9, i64 %19)
%21 = tail call i32 @rewind(i32* %10)
%22 = add nsw i64 %19, 1
%23 = tail call i64 @malloc(i64 %22)
%24 = inttoptr i64 %23 to i8*
%25 = tail call i32 @fread(i8* %24, i32 1, i64 %19, i32* %10)
%26 = sext i32 %25 to i64
%27 = icmp eq i64 %19, %26
br i1 %27, label %30, label %28
28: ; preds = %15
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %9)
br label %30
30: ; preds = %28, %15
%31 = getelementptr inbounds i8, i8* %24, i64 %19
store i8 0, i8* %31
%32 = tail call i32 @fclose(i32* %10)
%33 = tail call i32 (...) @lrexe_init()
%34 = icmp eq i32 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %30
%36 = tail call i32 @exit(i32 0)
unreachable
37: ; preds = %30
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %9)
%39 = tail call i32 @lrexe_execute(i8* %24)
%40 = tail call i32 (...) @lrexe_release()
%41 = tail call i32 @free(i8* %24)
ret i32 0
}