#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 const *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ lrtest_exec(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char const *, ...);
int read_rule_line(char *, int, int /*<<< orphan*/ *, int);
int lrtest_file_exec(const char *path) {
  FILE *confp;
  char *buf;
  int len;
  int i = 0;
  confp = fopen(path, "r");
  if (!confp) {
    printf("cannot open lrtest file %s\n", path);
    return 0;
  }
  buf = malloc((16 * 1024));
  while ((len = read_rule_line(buf, (16 * 1024), confp, (1))) > 0) {
    printf("RULE: '%s', len:%d\n", buf, len);
    lrtest_exec(buf);
    i++;
  }
  printf("load lrtest file: %s success.(count:%d)\n", path, i);
  free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<lrtest_file_exec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b0 <lrtest_file_exec+0x50>
mov    -0x10(%rbp),%rsi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1232 <lrtest_file_exec+0xd2>
mov    $0x4000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x4000,%esi
mov    $0x1,%ecx
call   1050 <read_rule_line@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jle    120d <lrtest_file_exec+0xad>
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1070 <lrtest_exec@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11be <lrtest_file_exec+0x5e>
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%edx
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lrtest_file_exec>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
lea    0xe8e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11e5 <lrtest_file_exec+0x85>
mov    %rax,%r15
mov    $0x4000,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x4000,%esi
mov    %r15,%rdx
mov    $0x1,%ecx
call   1050 <read_rule_line@plt>
test   %eax,%eax
jle    11f8 <lrtest_file_exec+0x98>
lea    0xe72(%rip),%r12
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <lrtest_exec@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
mov    $0x4000,%esi
mov    %r15,%rdx
mov    $0x1,%ecx
call   1050 <read_rule_line@plt>
test   %eax,%eax
jg     11b0 <lrtest_file_exec+0x50>
jmp    11fa <lrtest_file_exec+0x9a>
lea    0xe16(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1215 <lrtest_file_exec+0xb5>
xor    %ebp,%ebp
lea    0xe31(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [28 x i8] c"cannot open lrtest file %s\0A\00"
@.str.2 = [20 x i8] c"RULE: '%s', len:%d\0A\00"
@.str.3 = [41 x i8] c"load lrtest file: %s success.(count:%d)\0A\00"
define i32 @lrtest_file_exec(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %7
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp ne i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %13)
store i32 0, i32* %2
br label %36
15: ; preds = %1
%16 = call i8* @malloc(i32 16384)
store i8* %16, i8** %5
br label %17
17: ; preds = %22, %15
%18 = load i8*, i8** %5
%19 = load i32*, i32** %4
%20 = call i32 @read_rule_line(i8* %18, i32 16384, i32* %19, i32 1)
store i32 %20, i32* %6
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %17
%23 = load i8*, i8** %5
%24 = load i32, i32* %6
%25 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %23, i32 %24)
%26 = load i8*, i8** %5
%27 = call i32 @lrtest_exec(i8* %26)
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %17
30: ; preds = %17
%31 = load i8*, i8** %3
%32 = load i32, i32* %7
%33 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %31, i32 %32)
%34 = load i8*, i8** %5
%35 = call i32 @free(i8* %34)
store i32 0, i32* %2
br label %36
36: ; preds = %30, %12
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [28 x i8] c"cannot open lrtest file %s\0A\00"
@.str.2 = [20 x i8] c"RULE: '%s', len:%d\0A\00"
@.str.3 = [41 x i8] c"load lrtest file: %s success.(count:%d)\0A\00"
define i32 @lrtest_file_exec(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %22
6: ; preds = %1
%7 = tail call dereferenceable_or_null(16384) i8* @malloc(i32 16384)
%8 = tail call i32 @read_rule_line(i8* %7, i32 16384, i32* %2, i32 1)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %6, %10
%11 = phi i32 [ %16, %10 ], [ %8, %6 ]
%12 = phi i32 [ %15, %10 ], [ 0, %6 ]
%13 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %7, i32 %11)
%14 = tail call i32 @lrtest_exec(i8* %7)
%15 = add nuw nsw i32 %12, 1
%16 = tail call i32 @read_rule_line(i8* %7, i32 16384, i32* %2, i32 1)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %10, label %18
18: ; preds = %10, %6
%19 = phi i32 [ 0, %6 ], [ %15, %10 ]
%20 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32 %19)
%21 = tail call i32 @free(i8* %7)
br label %22
22: ; preds = %18, %4
ret i32 0
}