#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 */
struct timeval {
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ execute_command(char *, char *, char *);
char getopt(int, char **, char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int hexstring_to_int(char *);
char *optarg;
int /*<<< orphan*/ print_help();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ search_hex_pattern(char *, int, char *, int);
int /*<<< orphan*/ search_text_pattern(char *, int, char *, int);
int main(int argc, char *argv[]) {
  int aflag, tflag, cflag, oflag;
  int patnum, patlen;
  struct timeval t1, t2;
  char *filename, *pattern, c;
  char *command, *offset;
  int ioffset;
  filename = pattern = command = offset = NULL;
  aflag = tflag = cflag = oflag = 0;
  while ((c = getopt(argc, argv, "atp:f:c:o:")) != -1) {
    switch (c) {
    case 'a':
      aflag = 1;
      break;
    case 't':
      tflag = 1;
      break;
    case 'p':
      pattern = optarg;
      break;
    case 'f':
      filename = optarg;
      break;
    case 'c':
      cflag = 1;
      command = optarg;
      break;
    case 'o':
      oflag = 1;
      offset = optarg;
      break;
    case '?':
      print_help();
      return 1;
    default:
      printf(" Invalid arguments provided\n");
      print_help();
      abort();
    }
  }
  if ((argc < 3) || (filename == NULL)) {
    print_help();
    return -1;
  }
  if (cflag) {
    execute_command(command, filename, offset);
  } else {
    if (pattern == NULL) {
      printf(" please enter the pattern value\n");
      print_help();
      return -1;
    }
    ioffset = hexstring_to_int(offset);
    gettimeofday(&t1, NULL);
    if (tflag) {
      search_text_pattern(pattern, aflag, filename, ioffset);
    } else {
      search_hex_pattern(pattern, aflag, filename, ioffset);
    }
    gettimeofday(&t2, NULL);
    printf(" Search time = %d sec\n", (int)(t2.tv_sec - t1.tv_sec));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x60(%rbp)
movq   $0x0,-0x58(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xee8(%rip),%rdx
call   1090 <getopt@plt>
mov    %al,-0x49(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     12d4 <main+0x144>
movsbl -0x49(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x70(%rbp)
sub    $0x35,%eax
ja     12b3 <main+0x123>
mov    -0x70(%rbp),%rax
lea    0xddb(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x14(%rbp)
jmp    12cf <main+0x13f>
movl   $0x1,-0x18(%rbp)
jmp    12cf <main+0x13f>
mov    0x2dab(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
jmp    12cf <main+0x13f>
mov    0x2d98(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    12cf <main+0x13f>
movl   $0x1,-0x1c(%rbp)
mov    0x2d7e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
jmp    12cf <main+0x13f>
movl   $0x1,-0x20(%rbp)
mov    0x2d64(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x60(%rbp)
jmp    12cf <main+0x13f>
mov    $0x0,%al
call   10a0 <print_help@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c2 <main+0x232>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   10a0 <print_help@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    11e2 <main+0x52>
cmpl   $0x3,-0x8(%rbp)
jl     12e9 <main+0x159>
cmpq   $0x0,-0x40(%rbp)
jne    12fc <main+0x16c>
mov    $0x0,%al
call   10a0 <print_help@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c2 <main+0x232>
cmpl   $0x0,-0x1c(%rbp)
je     131c <main+0x18c>
mov    -0x58(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x60(%rbp),%rdx
call   10b0 <execute_command@plt>
jmp    13bb <main+0x22b>
cmpq   $0x0,-0x48(%rbp)
jne    1348 <main+0x1b8>
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   10a0 <print_help@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c2 <main+0x232>
mov    -0x60(%rbp),%rdi
call   1040 <hexstring_to_int@plt>
mov    %eax,-0x64(%rbp)
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <gettimeofday@plt>
cmpl   $0x0,-0x18(%rbp)
je     1383 <main+0x1f3>
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x40(%rbp),%rdx
mov    -0x64(%rbp),%ecx
call   1060 <search_text_pattern@plt>
jmp    1396 <main+0x206>
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x40(%rbp),%rdx
mov    -0x64(%rbp),%ecx
call   1050 <search_hex_pattern@plt>
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <gettimeofday@plt>
mov    -0x38(%rbp),%rax
sub    -0x30(%rbp),%rax
mov    %eax,%esi
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xf1e(%rip),%rdx
call   10a0 <getopt@plt>
cmp    $0xff,%al
je     130b <main+0x16b>
xor    %ecx,%ecx
mov    %rcx,0x8(%rsp)
lea    0xe2b(%rip),%r12
lea    0xefc(%rip),%r14
mov    0x2e15(%rip),%r13
xor    %ecx,%ecx
mov    %rcx,0x18(%rsp)
xor    %r15d,%r15d
xor    %ecx,%ecx
mov    %rcx,0x10(%rsp)
xor    %ecx,%ecx
mov    %rcx,0x20(%rsp)
movl   $0x0,(%rsp)
movl   $0x0,0x4(%rsp)
jmp    1234 <main+0x94>
movl   $0x1,(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ecx,%r15d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10a0 <getopt@plt>
cmp    $0xff,%al
je     1289 <main+0xe9>
movsbl %al,%eax
add    $0xffffffc1,%eax
cmp    $0x35,%eax
ja     135f <main+0x1bf>
mov    %r15d,%ecx
mov    $0x1,%r15d
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
mov    0x0(%r13),%rax
mov    %rax,0x18(%rsp)
movl   $0x1,0x4(%rsp)
jmp    1220 <main+0x80>
mov    0x0(%r13),%rax
mov    %rax,0x20(%rsp)
jmp    1220 <main+0x80>
mov    0x0(%r13),%rax
mov    %rax,0x8(%rsp)
jmp    1220 <main+0x80>
mov    0x0(%r13),%rax
mov    %rax,0x10(%rsp)
jmp    1220 <main+0x80>
cmp    $0x3,%ebp
mov    0x20(%rsp),%rbp
jl     130b <main+0x16b>
test   %rbp,%rbp
je     130b <main+0x16b>
cmpl   $0x0,0x4(%rsp)
je     12b5 <main+0x115>
mov    0x18(%rsp),%rdi
mov    %rbp,%rsi
mov    0x8(%rsp),%rdx
call   10c0 <execute_command@plt>
xor    %ebx,%ebx
jmp    1317 <main+0x177>
mov    0x10(%rsp),%rbx
test   %rbx,%rbx
je     12ff <main+0x15f>
mov    0x8(%rsp),%rdi
call   1050 <hexstring_to_int@plt>
mov    %eax,%r14d
lea    0x30(%rsp),%rdi
xor    %esi,%esi
call   1090 <gettimeofday@plt>
cmpl   $0x0,(%rsp)
je     1328 <main+0x188>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %rbp,%rdx
mov    %r14d,%ecx
call   1070 <search_text_pattern@plt>
jmp    1339 <main+0x199>
xor    %eax,%eax
call   10b0 <print_help@plt>
mov    $0x1,%ebx
jmp    1317 <main+0x177>
lea    0xdf4(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   10b0 <print_help@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %rbp,%rdx
mov    %r14d,%ecx
call   1060 <search_hex_pattern@plt>
xor    %ebx,%ebx
lea    0x28(%rsp),%rdi
xor    %esi,%esi
call   1090 <gettimeofday@plt>
mov    0x28(%rsp),%esi
sub    0x30(%rsp),%esi
lea    0xd8d(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1317 <main+0x177>
lea    0xdb4(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   10b0 <print_help@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.timeval = type { i64 }
@.str = [11 x i8] c"atp:f:c:o:\00"
@optarg = global i8* null
@.str.1 = [29 x i8] c" Invalid arguments provided\0A\00"
@.str.2 = [33 x i8] c" please enter the pattern value\0A\00"
@.str.3 = [23 x i8] c" Search time = %d sec\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 i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.timeval
%13 = alloca %struct.timeval
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %18
store i8* null, i8** %17
store i8* null, i8** %15
store i8* null, i8** %14
store i32 0, i32* %9
store i32 0, i32* %8
store i32 0, i32* %7
store i32 0, i32* %6
br label %20
20: ; preds = %45, %2
%21 = load i32, i32* %4
%22 = load i8**, i8*** %5
%23 = call signext i8 @getopt(i32 %21, i8** %22, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8 %23, i8* %16
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, -1
br i1 %25, label %26, label %46
26: ; preds = %20
%27 = load i8, i8* %16
%28 = sext i8 %27 to i32
switch i32 %28, label %41 [
i32 97, label %29
i32 116, label %30
i32 112, label %31
i32 102, label %33
i32 99, label %35
i32 111, label %37
i32 63, label %39
]
29: ; preds = %26
store i32 1, i32* %6
br label %45
30: ; preds = %26
store i32 1, i32* %7
br label %45
31: ; preds = %26
%32 = load i8*, i8** @optarg
store i8* %32, i8** %15
br label %45
33: ; preds = %26
%34 = load i8*, i8** @optarg
store i8* %34, i8** %14
br label %45
35: ; preds = %26
store i32 1, i32* %8
%36 = load i8*, i8** @optarg
store i8* %36, i8** %17
br label %45
37: ; preds = %26
store i32 1, i32* %9
%38 = load i8*, i8** @optarg
store i8* %38, i8** %18
br label %45
39: ; preds = %26
%40 = call i32 (...) @print_help()
store i32 1, i32* %3
br label %96
41: ; preds = %26
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%43 = call i32 (...) @print_help()
%44 = call i32 (...) @abort()
unreachable
45: ; preds = %37, %35, %33, %31, %30, %29
br label %20
46: ; preds = %20
%47 = load i32, i32* %4
%48 = icmp slt i32 %47, 3
br i1 %48, label %52, label %49
49: ; preds = %46
%50 = load i8*, i8** %14
%51 = icmp eq i8* %50, null
br i1 %51, label %52, label %54
52: ; preds = %49, %46
%53 = call i32 (...) @print_help()
store i32 -1, i32* %3
br label %96
54: ; preds = %49
%55 = load i32, i32* %8
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %62
57: ; preds = %54
%58 = load i8*, i8** %17
%59 = load i8*, i8** %14
%60 = load i8*, i8** %18
%61 = call i32 @execute_command(i8* %58, i8* %59, i8* %60)
br label %95
62: ; preds = %54
%63 = load i8*, i8** %15
%64 = icmp eq i8* %63, null
br i1 %64, label %65, label %68
65: ; preds = %62
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%67 = call i32 (...) @print_help()
store i32 -1, i32* %3
br label %96
68: ; preds = %62
%69 = load i8*, i8** %18
%70 = call i32 @hexstring_to_int(i8* %69)
store i32 %70, i32* %19
%71 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
%72 = load i32, i32* %7
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %80
74: ; preds = %68
%75 = load i8*, i8** %15
%76 = load i32, i32* %6
%77 = load i8*, i8** %14
%78 = load i32, i32* %19
%79 = call i32 @search_text_pattern(i8* %75, i32 %76, i8* %77, i32 %78)
br label %86
80: ; preds = %68
%81 = load i8*, i8** %15
%82 = load i32, i32* %6
%83 = load i8*, i8** %14
%84 = load i32, i32* %19
%85 = call i32 @search_hex_pattern(i8* %81, i32 %82, i8* %83, i32 %84)
br label %86
86: ; preds = %80, %74
%87 = call i32 @gettimeofday(%struct.timeval* %13, i32* null)
%88 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
%89 = load i64, i64* %88
%90 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%91 = load i64, i64* %90
%92 = sub nsw i64 %89, %91
%93 = trunc i64 %92 to i32
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %93)
br label %95
95: ; preds = %86, %57
store i32 0, i32* %3
br label %96
96: ; preds = %95, %65, %52, %39
%97 = load i32, i32* %3
ret i32 %97
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
@.str = [11 x i8] c"atp:f:c:o:\00"
@optarg = global i8* null
@.str.3 = [23 x i8] c" Search time = %d sec\0A\00"
@str = [32 x i8] c" please enter the pattern value\00"
@str.4 = [28 x i8] c" Invalid arguments provided\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
%7 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8 %7, -1
br i1 %8, label %48, label %9
9: ; preds = %2, %34
%10 = phi i8 [ %42, %34 ], [ %7, %2 ]
%11 = phi i8* [ %41, %34 ], [ null, %2 ]
%12 = phi i8* [ %40, %34 ], [ null, %2 ]
%13 = phi i32 [ %39, %34 ], [ 0, %2 ]
%14 = phi i8* [ %38, %34 ], [ null, %2 ]
%15 = phi i8* [ %37, %34 ], [ null, %2 ]
%16 = phi i32 [ %36, %34 ], [ 0, %2 ]
%17 = phi i32 [ %35, %34 ], [ 0, %2 ]
%18 = sext i8 %10 to i32
switch i32 %18, label %30 [
i32 97, label %34
i32 116, label %19
i32 112, label %20
i32 102, label %22
i32 99, label %24
i32 111, label %26
i32 63, label %28
]
19: ; preds = %9
br label %34
20: ; preds = %9
%21 = load i8*, i8** @optarg
br label %34
22: ; preds = %9
%23 = load i8*, i8** @optarg
br label %34
24: ; preds = %9
%25 = load i8*, i8** @optarg
br label %34
26: ; preds = %9
%27 = load i8*, i8** @optarg
br label %34
28: ; preds = %9
%29 = tail call i32 (...) @print_help()
br label %76
30: ; preds = %9
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.4, i64 0, i64 0))
%32 = tail call i32 (...) @print_help()
%33 = tail call i32 (...) @abort()
unreachable
34: ; preds = %9, %26, %24, %22, %20, %19
%35 = phi i32 [ %17, %26 ], [ 1, %24 ], [ %17, %22 ], [ %17, %20 ], [ %17, %19 ], [ %17, %9 ]
%36 = phi i32 [ %16, %26 ], [ %16, %24 ], [ %16, %22 ], [ %16, %20 ], [ 1, %19 ], [ %16, %9 ]
%37 = phi i8* [ %15, %26 ], [ %15, %24 ], [ %23, %22 ], [ %15, %20 ], [ %15, %19 ], [ %15, %9 ]
%38 = phi i8* [ %14, %26 ], [ %14, %24 ], [ %14, %22 ], [ %21, %20 ], [ %14, %19 ], [ %14, %9 ]
%39 = phi i32 [ %13, %26 ], [ %13, %24 ], [ %13, %22 ], [ %13, %20 ], [ %13, %19 ], [ 1, %9 ]
%40 = phi i8* [ %12, %26 ], [ %25, %24 ], [ %12, %22 ], [ %12, %20 ], [ %12, %19 ], [ %12, %9 ]
%41 = phi i8* [ %27, %26 ], [ %11, %24 ], [ %11, %22 ], [ %11, %20 ], [ %11, %19 ], [ %11, %9 ]
%42 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%43 = icmp eq i8 %42, -1
br i1 %43, label %44, label %9
44: ; preds = %34
%45 = icmp slt i32 %0, 3
%46 = icmp eq i8* %37, null
%47 = select i1 %45, i1 true, i1 %46
br i1 %47, label %48, label %50
48: ; preds = %2, %44
%49 = tail call i32 (...) @print_help()
br label %76
50: ; preds = %44
%51 = icmp eq i32 %35, 0
br i1 %51, label %54, label %52
52: ; preds = %50
%53 = tail call i32 @execute_command(i8* %40, i8* %37, i8* %41)
br label %76
54: ; preds = %50
%55 = icmp eq i8* %38, null
br i1 %55, label %56, label %59
56: ; preds = %54
%57 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%58 = tail call i32 (...) @print_help()
br label %76
59: ; preds = %54
%60 = tail call i32 @hexstring_to_int(i8* %41)
%61 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%62 = icmp eq i32 %36, 0
br i1 %62, label %65, label %63
63: ; preds = %59
%64 = tail call i32 @search_text_pattern(i8* %38, i32 %39, i8* %37, i32 %60)
br label %67
65: ; preds = %59
%66 = tail call i32 @search_hex_pattern(i8* %38, i32 %39, i8* %37, i32 %60)
br label %67
67: ; preds = %65, %63
%68 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%69 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%70 = load i64, i64* %69
%71 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%72 = load i64, i64* %71
%73 = sub nsw i64 %70, %72
%74 = trunc i64 %73 to i32
%75 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %74)
br label %76
76: ; preds = %52, %67, %56, %48, %28
%77 = phi i32 [ 1, %28 ], [ -1, %48 ], [ -1, %56 ], [ 0, %67 ], [ 0, %52 ]
ret i32 %77
}