#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*/ regex_t;

/* Variables and functions */
int EOF;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int do_regex(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int getopt(int, char **, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  int c;
  char *filename = NULL;
  char *pattern = NULL;
  extern char *optarg;
  extern int optind, opterr, optopt;
  regex_t *regex;
  int err_no;
  regex = (regex_t *)malloc(sizeof(regex_t));
  memset(regex, 0, sizeof(regex_t));
  if (argc == 1) {
    usage();
    return (EXIT_SUCCESS);
  }
  while ((c = getopt(argc, argv, "f:p:")) != EOF) {
    switch (c) {
    case 'f':
      filename = optarg;
      break;
    case 'p':
      pattern = optarg;
      break;
    case '?':
      fprintf(stderr, "Unknown option `-%c'.\n", optopt);
      usage();
      return EXIT_FAILURE;
    default:
      usage();
      return EXIT_SUCCESS;
    }
  }
  if ((err_no = do_regex(regex, pattern, filename)) != EXIT_SUCCESS) {
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


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)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
cmpl   $0x1,-0x8(%rbp)
jne    11c6 <main+0x66>
mov    $0x0,%al
call   1070 <usage@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12df <main+0x17f>
jmp    11cb <main+0x6b>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe27(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e00(%rip),%rcx
cmp    (%rcx),%eax
je     129f <main+0x13f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0x3f,%eax
je     124c <main+0xec>
jmp    1204 <main+0xa4>
mov    -0x38(%rbp),%eax
sub    $0x66,%eax
je     1226 <main+0xc6>
jmp    1215 <main+0xb5>
mov    -0x38(%rbp),%eax
sub    $0x70,%eax
je     1239 <main+0xd9>
jmp    1282 <main+0x122>
mov    0x2da3(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    129a <main+0x13a>
mov    0x2d90(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    129a <main+0x13a>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
mov    0x2d84(%rip),%rax
mov    (%rax),%edx
lea    0xda0(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1070 <usage@plt>
mov    0x2d48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12df <main+0x17f>
mov    $0x0,%al
call   1070 <usage@plt>
mov    0x2d28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12df <main+0x17f>
jmp    11cb <main+0x6b>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <do_regex@plt>
mov    %eax,-0x34(%rbp)
mov    0x2cfe(%rip),%rcx
cmp    (%rcx),%eax
je     12d3 <main+0x173>
mov    0x2cf7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12df <main+0x17f>
mov    0x2cde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
cmp    $0x1,%ebp
jne    11a4 <main+0x44>
xor    %eax,%eax
call   1070 <usage@plt>
mov    0x2e19(%rip),%rax
jmp    1267 <main+0x107>
lea    0xe55(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1080 <getopt@plt>
mov    0x2e2c(%rip),%r14
cmp    (%r14),%eax
mov    %r15,(%rsp)
jne    11eb <main+0x8b>
xor    %r12d,%r12d
xor    %r15d,%r15d
mov    (%rsp),%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1030 <do_regex@plt>
mov    %eax,%ecx
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
cmp    %eax,%ecx
jne    1260 <main+0x100>
jmp    1269 <main+0x109>
xor    %r15d,%r15d
lea    0xe0b(%rip),%r13
xor    %r12d,%r12d
jmp    121c <main+0xbc>
nopw   0x0(%rax,%rax,1)
mov    0x2dc9(%rip),%rax
mov    (%rax),%r15
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1080 <getopt@plt>
cmp    (%r14),%eax
je     11cb <main+0x6b>
cmp    $0x66,%eax
je     1200 <main+0xa0>
cmp    $0x70,%eax
jne    1232 <main+0xd2>
mov    0x2da3(%rip),%rax
mov    (%rax),%r12
jmp    120a <main+0xaa>
cmp    $0x3f,%eax
jne    1191 <main+0x31>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
mov    0x2d95(%rip),%rax
mov    (%rax),%edx
lea    0xdb1(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1070 <usage@plt>
mov    0x2d59(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
@.str = [5 x i8] c"f:p:\00"
@EOF = global i32 0
@optarg = external global i8*
@stderr = global i32 0
@.str.1 = [23 x i8] c"Unknown option `-%c'.\0A\00"
@optopt = external global i32
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
store i8* null, i8** %8
%11 = call i64 @malloc(i32 4)
%12 = inttoptr i64 %11 to i32*
store i32* %12, i32** %9
%13 = load i32*, i32** %9
%14 = call i32 @memset(i32* %13, i32 0, i32 4)
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 (...) @usage()
%19 = load i32, i32* @EXIT_SUCCESS
store i32 %19, i32* %3
br label %54
20: ; preds = %2
br label %21
21: ; preds = %42, %20
%22 = load i32, i32* %4
%23 = load i8**, i8*** %5
%24 = call i32 @getopt(i32 %22, i8** %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %24, i32* %6
%25 = load i32, i32* @EOF
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %43
27: ; preds = %21
%28 = load i32, i32* %6
switch i32 %28, label %39 [
i32 102, label %29
i32 112, label %31
i32 63, label %33
]
29: ; preds = %27
%30 = load i8*, i8** @optarg
store i8* %30, i8** %7
br label %42
31: ; preds = %27
%32 = load i8*, i8** @optarg
store i8* %32, i8** %8
br label %42
33: ; preds = %27
%34 = load i32, i32* @stderr
%35 = load i32, i32* @optopt
%36 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %35)
%37 = call i32 (...) @usage()
%38 = load i32, i32* @EXIT_FAILURE
store i32 %38, i32* %3
br label %54
39: ; preds = %27
%40 = call i32 (...) @usage()
%41 = load i32, i32* @EXIT_SUCCESS
store i32 %41, i32* %3
br label %54
42: ; preds = %31, %29
br label %21
43: ; preds = %21
%44 = load i32*, i32** %9
%45 = load i8*, i8** %8
%46 = load i8*, i8** %7
%47 = call i32 @do_regex(i32* %44, i8* %45, i8* %46)
store i32 %47, i32* %10
%48 = load i32, i32* @EXIT_SUCCESS
%49 = icmp ne i32 %47, %48
br i1 %49, label %50, label %52
50: ; preds = %43
%51 = load i32, i32* @EXIT_FAILURE
store i32 %51, i32* %3
br label %54
52: ; preds = %43
%53 = load i32, i32* @EXIT_SUCCESS
store i32 %53, i32* %3
br label %54
54: ; preds = %52, %50, %39, %33, %17
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@.str = [5 x i8] c"f:p:\00"
@EOF = global i32 0
@optarg = external global i8*
@stderr = global i32 0
@.str.1 = [23 x i8] c"Unknown option `-%c'.\0A\00"
@optopt = external global i32
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i64 @malloc(i32 4)
%4 = inttoptr i64 %3 to i32*
%5 = tail call i32 @memset(i32* %4, i32 0, i32 4)
%6 = icmp eq i32 %0, 1
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %37, label %14
11: ; preds = %2
%12 = tail call i32 (...) @usage()
%13 = load i32, i32* @EXIT_SUCCESS
br label %45
14: ; preds = %7, %31
%15 = phi i32 [ %34, %31 ], [ %8, %7 ]
%16 = phi i8* [ %33, %31 ], [ null, %7 ]
%17 = phi i8* [ %32, %31 ], [ null, %7 ]
switch i32 %15, label %28 [
i32 102, label %18
i32 112, label %20
i32 63, label %22
]
18: ; preds = %14
%19 = load i8*, i8** @optarg
br label %31
20: ; preds = %14
%21 = load i8*, i8** @optarg
br label %31
22: ; preds = %14
%23 = load i32, i32* @stderr
%24 = load i32, i32* @optopt
%25 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = tail call i32 (...) @usage()
%27 = load i32, i32* @EXIT_FAILURE
br label %45
28: ; preds = %14
%29 = tail call i32 (...) @usage()
%30 = load i32, i32* @EXIT_SUCCESS
br label %45
31: ; preds = %20, %18
%32 = phi i8* [ %21, %20 ], [ %17, %18 ]
%33 = phi i8* [ %16, %20 ], [ %19, %18 ]
%34 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%35 = load i32, i32* @EOF
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %14
37: ; preds = %31, %7
%38 = phi i8* [ null, %7 ], [ %32, %31 ]
%39 = phi i8* [ null, %7 ], [ %33, %31 ]
%40 = tail call i32 @do_regex(i32* %4, i8* %38, i8* %39)
%41 = load i32, i32* @EXIT_SUCCESS
%42 = icmp eq i32 %40, %41
%43 = load i32, i32* @EXIT_FAILURE
%44 = select i1 %42, i32 %41, i32 %43
br label %45
45: ; preds = %37, %28, %22, %11
%46 = phi i32 [ %13, %11 ], [ %30, %28 ], [ %27, %22 ], [ %44, %37 ]
ret i32 %46
}