#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
char *strchr(char *, char);
scalar_t__ strncmp(char *, char *, int);
char *strstr(char *, char *);
int main(int iArgc, char *cArgv[]) {
  FILE *fp;
  if (iArgc != 2) {
    printf("usage: %s <snort .rules file>\n", cArgv[0]);
    return (0);
  }
  if ((fp = fopen(cArgv[1], "r")) != NULL) {
    char cLine[1024];
    while (fgets(cLine, 1023, fp) != NULL) {
      if (cLine[0] == '#')
        continue;
      if (strncmp(cLine, "alert", 5))
        continue;
      char *cp;
      char *cp2;
      if ((cp = strstr(cLine, "sid:"))) {
        if ((cp2 = strchr(cp + 4, ';'))) {
          *cp2 = 0;
          printf("\"%s\"", cp + 4);
          *cp2 = ';';
        }
      }
      if ((cp = strstr(cLine, "msg:"))) {
        if ((cp2 = strchr(cp + 4, ';'))) {
          *cp2 = 0;
          printf(",%s\n", cp + 4);
          *cp2 = ';';
        }
      }
    }
    fclose(fp);
  } else {
    printf("error: could not open %s\n", cArgv[1]);
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b2 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe5f(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1362 <main+0x1f2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     133b <main+0x1cb>
jmp    11d9 <main+0x69>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x3ff,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     132d <main+0x1bd>
movsbl -0x420(%rbp),%eax
cmp    $0x23,%eax
jne    120d <main+0x9d>
jmp    11d9 <main+0x69>
lea    -0x420(%rbp),%rdi
lea    0xe06(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1234 <main+0xc4>
jmp    11d9 <main+0x69>
lea    -0x420(%rbp),%rdi
lea    0xde5(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
je     12ae <main+0x13e>
mov    -0x428(%rbp),%rdi
add    $0x4,%rdi
mov    $0x3b,%esi
call   1050 <strchr@plt>
mov    %rax,-0x430(%rbp)
cmp    $0x0,%rax
je     12a9 <main+0x139>
mov    -0x430(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x428(%rbp),%rsi
add    $0x4,%rsi
lea    0xd92(%rip),%rdi
call   1060 <printf@plt>
mov    -0x430(%rbp),%rax
movb   $0x3b,(%rax)
jmp    12ae <main+0x13e>
lea    -0x420(%rbp),%rdi
lea    0xd75(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
je     1328 <main+0x1b8>
mov    -0x428(%rbp),%rdi
add    $0x4,%rdi
mov    $0x3b,%esi
call   1050 <strchr@plt>
mov    %rax,-0x430(%rbp)
cmp    $0x0,%rax
je     1323 <main+0x1b3>
mov    -0x430(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x428(%rbp),%rsi
add    $0x4,%rsi
lea    0xd22(%rip),%rdi
call   1060 <printf@plt>
mov    -0x430(%rbp),%rax
movb   $0x3b,(%rax)
jmp    1328 <main+0x1b8>
jmp    11d9 <main+0x69>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
jmp    135b <main+0x1eb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xcf1(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1362 <main+0x1f2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbp
cmp    $0x2,%edi
jne    129d <main+0x12d>
mov    0x8(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12bd <main+0x14d>
mov    %rax,%r13
mov    %rsp,%rdi
mov    $0x3ff,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12b1 <main+0x141>
mov    %rsp,%r14
lea    0xe55(%rip),%r15
jmp    11e9 <main+0x79>
xchg   %ax,%ax
mov    %r14,%rdi
mov    $0x3ff,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12b1 <main+0x141>
cmpb   $0x23,(%rsp)
je     11d0 <main+0x60>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11d0 <main+0x60>
mov    %r14,%rdi
lea    0xe19(%rip),%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     124b <main+0xdb>
mov    %rax,%rbp
add    $0x4,%rbp
mov    %rbp,%rdi
mov    $0x3b,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     124b <main+0xdb>
mov    %rax,%r12
movb   $0x0,(%rax)
lea    0xdee(%rip),%rdi
mov    %rbp,%rsi
call   1060 <printf@plt>
movb   $0x3b,(%r12)
mov    %r14,%rdi
lea    0xddc(%rip),%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     11d0 <main+0x60>
mov    %rax,%rbp
add    $0x4,%rbp
mov    %rbp,%rdi
mov    $0x3b,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11d0 <main+0x60>
mov    %rax,%rbx
movb   $0x0,(%rax)
lea    0xda9(%rip),%rdi
mov    %rbp,%rsi
call   1060 <printf@plt>
movb   $0x3b,(%rbx)
jmp    11d0 <main+0x60>
mov    0x0(%rbp),%rsi
lea    0xd58(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
jmp    12d2 <main+0x162>
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    12d2 <main+0x162>
mov    0x8(%rbp),%rsi
lea    0xd73(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"usage: %s <snort .rules file>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"alert\00"
@.str.3 = [5 x i8] c"sid:\00"
@.str.4 = [5 x i8] c"\22%s\22\00"
@.str.5 = [5 x i8] c"msg:\00"
@.str.6 = [5 x i8] c",%s\0A\00"
@.str.7 = [26 x i8] c"error: could not open %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [1024 x i8]
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 0, i32* %3
br label %82
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.1, i64 0, i64 0))
store i32* %21, i32** %6
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %76
23: ; preds = %17
br label %24
24: ; preds = %72, %39, %34, %23
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%26 = load i32*, i32** %6
%27 = call i32* @fgets(i8* %25, i32 1023, i32* %26)
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %73
29: ; preds = %24
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 35
br i1 %33, label %34, label %35
34: ; preds = %29
br label %24
35: ; preds = %29
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%37 = call i64 @strncmp(i8* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %35
br label %24
40: ; preds = %35
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%42 = call i8* @strstr(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i8* %42, i8** %8
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %56
44: ; preds = %40
%45 = load i8*, i8** %8
%46 = getelementptr inbounds i8, i8* %45, i64 4
%47 = call i8* @strchr(i8* %46, i8 signext 59)
store i8* %47, i8** %9
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %55
49: ; preds = %44
%50 = load i8*, i8** %9
store i8 0, i8* %50
%51 = load i8*, i8** %8
%52 = getelementptr inbounds i8, i8* %51, i64 4
%53 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %52)
%54 = load i8*, i8** %9
store i8 59, i8* %54
br label %55
55: ; preds = %49, %44
br label %56
56: ; preds = %55, %40
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%58 = call i8* @strstr(i8* %57, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
store i8* %58, i8** %8
%59 = icmp ne i8* %58, null
br i1 %59, label %60, label %72
60: ; preds = %56
%61 = load i8*, i8** %8
%62 = getelementptr inbounds i8, i8* %61, i64 4
%63 = call i8* @strchr(i8* %62, i8 signext 59)
store i8* %63, i8** %9
%64 = icmp ne i8* %63, null
br i1 %64, label %65, label %71
65: ; preds = %60
%66 = load i8*, i8** %9
store i8 0, i8* %66
%67 = load i8*, i8** %8
%68 = getelementptr inbounds i8, i8* %67, i64 4
%69 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %68)
%70 = load i8*, i8** %9
store i8 59, i8* %70
br label %71
71: ; preds = %65, %60
br label %72
72: ; preds = %71, %56
br label %24
73: ; preds = %24
%74 = load i32*, i32** %6
%75 = call i32 @fclose(i32* %74)
br label %81
76: ; preds = %17
%77 = load i8**, i8*** %5
%78 = getelementptr inbounds i8*, i8** %77, i64 1
%79 = load i8*, i8** %78
%80 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %79)
store i32 1, i32* %3
br label %82
81: ; preds = %73
store i32 0, i32* %3
br label %82
82: ; preds = %81, %76, %12
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
@.str = [31 x i8] c"usage: %s <snort .rules file>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"alert\00"
@.str.3 = [5 x i8] c"sid:\00"
@.str.4 = [5 x i8] c"\22%s\22\00"
@.str.5 = [5 x i8] c"msg:\00"
@.str.6 = [5 x i8] c",%s\0A\00"
@.str.7 = [26 x i8] c"error: could not open %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %49
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %46, label %13
13: ; preds = %8
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%15 = call i32* @fgets(i8* %14, i32 1023, i32* %11)
%16 = icmp eq i32* %15, null
br i1 %16, label %44, label %17
17: ; preds = %13, %41
%18 = load i8, i8* %14
%19 = icmp eq i8 %18, 35
br i1 %19, label %41, label %20
20: ; preds = %17
%21 = call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %41
23: ; preds = %20
%24 = call i8* @strstr(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i8* %24, null
br i1 %25, label %32, label %26
26: ; preds = %23
%27 = getelementptr inbounds i8, i8* %24, i64 4
%28 = call i8* @strchr(i8* %27, i8 signext 59)
%29 = icmp eq i8* %28, null
br i1 %29, label %32, label %30
30: ; preds = %26
store i8 0, i8* %28
%31 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %27)
store i8 59, i8* %28
br label %32
32: ; preds = %26, %30, %23
%33 = call i8* @strstr(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%34 = icmp eq i8* %33, null
br i1 %34, label %41, label %35
35: ; preds = %32
%36 = getelementptr inbounds i8, i8* %33, i64 4
%37 = call i8* @strchr(i8* %36, i8 signext 59)
%38 = icmp eq i8* %37, null
br i1 %38, label %41, label %39
39: ; preds = %35
store i8 0, i8* %37
%40 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %36)
store i8 59, i8* %37
br label %41
41: ; preds = %32, %39, %35, %17, %20
%42 = call i32* @fgets(i8* %14, i32 1023, i32* %11)
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %17
44: ; preds = %41, %13
%45 = call i32 @fclose(i32* %11)
br label %49
46: ; preds = %8
%47 = load i8*, i8** %9
%48 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %44, %46, %5
%50 = phi i32 [ 0, %5 ], [ 0, %44 ], [ 1, %46 ]
ret i32 %50
}