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

/* Variables and functions */
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
int /*<<< orphan*/ isprint(char);
int /*<<< orphan*/ optarg;
char optopt;
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int get_option(int argc, char **argv) {
  int option, ret;
  while ((option = getopt(argc, argv, "hn:")) != -1) {
    switch (option) {
    case 'h':
      fprintf(
          stdout,
          "Usage:\t./main [OPTION]\n\nOption:\n\t-n [NUMBER]:\tthe nubmer of "
          "captured packet (default is 5)\n\t-h:\t\tdisplay information\n");
      ret = 0;
      break;
    case 'n':
      ret = atoi(optarg);
      break;
    case '?':
      if (optopt == 'n') {
        fprintf(stderr, "Format: ./main -n [NUMBER]\n");
      } else if (isprint(optopt)) {
        fprintf(stderr, "[!] Error: Unkown option is %c\n", optopt);
      } else {
        fprintf(stderr, "[!] Error: Unkown option\n");
      }
      ret = -1;
      break;
    default:
      fprintf(stderr, "[!] Error: Unknown error occurred\n");
      ret = -2;
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<get_option>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xea3(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1295 <get_option+0x155>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x3f,%eax
je     11dd <get_option+0x9d>
jmp    1182 <get_option+0x42>
mov    -0x1c(%rbp),%eax
sub    $0x68,%eax
je     11a4 <get_option+0x64>
jmp    1193 <get_option+0x53>
mov    -0x1c(%rbp),%eax
sub    $0x6e,%eax
je     11c7 <get_option+0x87>
jmp    1272 <get_option+0x132>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x18(%rbp)
jmp    1290 <get_option+0x150>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    1290 <get_option+0x150>
mov    0x2dfc(%rip),%rax
movsbl (%rax),%eax
cmp    $0x6e,%eax
jne    120c <get_option+0xcc>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1266 <get_option+0x126>
mov    0x2dcd(%rip),%rax
movsbl (%rax),%edi
call   1040 <isprint@plt>
cmp    $0x0,%eax
je     124a <get_option+0x10a>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
mov    0x2dac(%rip),%rax
movsbl (%rax),%edx
lea    0xe58(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1261 <get_option+0x121>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1266 <get_option+0x126>
movl   $0xffffffff,-0x18(%rbp)
jmp    1290 <get_option+0x150>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xfffffffe,-0x18(%rbp)
jmp    114f <get_option+0xf>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_option>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xea9(%rip),%r14
mov    0x2e82(%rip),%r12
mov    0x2e6b(%rip),%r13
jmp    1181 <get_option+0x41>
nopw   0x0(%rax,%rax,1)
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,%r15d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <getopt@plt>
cmp    $0x67,%eax
jle    11c0 <get_option+0x80>
cmp    $0x6e,%eax
je     1170 <get_option+0x30>
cmp    $0x68,%eax
jne    11e0 <get_option+0xa0>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
xor    %r15d,%r15d
lea    0xe54(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    1181 <get_option+0x41>
nopl   0x0(%rax)
cmp    $0x3f,%eax
jne    11db <get_option+0x9b>
movzbl (%r12),%eax
cmp    $0x6e,%al
jne    11fa <get_option+0xba>
mov    0x0(%r13),%edi
lea    0xea1(%rip),%rsi
jmp    122f <get_option+0xef>
cmp    $0xffffffff,%eax
je     1241 <get_option+0x101>
mov    0x0(%r13),%edi
lea    0xee5(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xfffffffe,%r15d
jmp    1181 <get_option+0x41>
movsbl %al,%edi
call   1040 <isprint@plt>
mov    0x0(%r13),%edi
test   %eax,%eax
je     1228 <get_option+0xe8>
movsbl (%r12),%edx
lea    0xe80(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%r15d
jmp    1181 <get_option+0x41>
lea    0xe87(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%r15d
jmp    1181 <get_option+0x41>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"hn:\00"
@stdout = global i32 0
@.str.1 = [118 x i8] c"Usage:\09./main [OPTION]\0A\0AOption:\0A\09-n [NUMBER]:\09the nubmer of captured packet (default is 5)\0A\09-h:\09\09display information\0A\00"
@optarg = global i32 0
@optopt = global i8 0
@stderr = global i32 0
@.str.2 = [28 x i8] c"Format: ./main -n [NUMBER]\0A\00"
@.str.3 = [32 x i8] c"[!] Error: Unkown option is %c\0A\00"
@.str.4 = [26 x i8] c"[!] Error: Unkown option\0A\00"
@.str.5 = [35 x i8] c"[!] Error: Unknown error occurred\0A\00"
define i32 @get_option(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
br label %7
7: ; preds = %44, %2
%8 = load i32, i32* %3
%9 = load i8**, i8*** %4
%10 = call i32 @getopt(i32 %8, i8** %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %10, i32* %5
%11 = icmp ne i32 %10, -1
br i1 %11, label %12, label %45
12: ; preds = %7
%13 = load i32, i32* %5
switch i32 %13, label %41 [
i32 104, label %14
i32 110, label %17
i32 63, label %20
]
14: ; preds = %12
%15 = load i32, i32* @stdout
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([118 x i8], [118 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %6
br label %44
17: ; preds = %12
%18 = load i32, i32* @optarg
%19 = call i32 @atoi(i32 %18)
store i32 %19, i32* %6
br label %44
20: ; preds = %12
%21 = load i8, i8* @optopt
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 110
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %40
27: ; preds = %20
%28 = load i8, i8* @optopt
%29 = call i32 @isprint(i8 signext %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = load i8, i8* @optopt
%34 = sext i8 %33 to i32
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %34)
br label %39
36: ; preds = %27
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %39
39: ; preds = %36, %31
br label %40
40: ; preds = %39, %24
store i32 -1, i32* %6
br label %44
41: ; preds = %12
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
store i32 -2, i32* %6
br label %44
44: ; preds = %41, %40, %17, %14
br label %7
45: ; preds = %7
%46 = load i32, i32* %6
ret i32 %46
}

LLVM IR (-O2):
@.str = [4 x i8] c"hn:\00"
@stdout = global i32 0
@.str.1 = [118 x i8] c"Usage:\09./main [OPTION]\0A\0AOption:\0A\09-n [NUMBER]:\09the nubmer of captured packet (default is 5)\0A\09-h:\09\09display information\0A\00"
@optarg = global i32 0
@optopt = global i8 0
@stderr = global i32 0
@.str.2 = [28 x i8] c"Format: ./main -n [NUMBER]\0A\00"
@.str.3 = [32 x i8] c"[!] Error: Unkown option is %c\0A\00"
@.str.4 = [26 x i8] c"[!] Error: Unkown option\0A\00"
@.str.5 = [35 x i8] c"[!] Error: Unknown error occurred\0A\00"
define i32 @get_option(i32 %0, i8** %1) {
br label %3
3: ; preds = %18, %2
%4 = phi i32 [ undef, %2 ], [ %19, %18 ]
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %5, label %30 [
i32 -1, label %33
i32 104, label %6
i32 110, label %9
i32 63, label %12
]
6: ; preds = %3
%7 = load i32, i32* @stdout
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([118 x i8], [118 x i8]* @.str.1, i64 0, i64 0))
br label %18
9: ; preds = %3
%10 = load i32, i32* @optarg
%11 = tail call i32 @atoi(i32 %10)
br label %18
12: ; preds = %3
%13 = load i8, i8* @optopt
%14 = icmp eq i8 %13, 110
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %15, %28, %24, %30, %9, %6
%19 = phi i32 [ -2, %30 ], [ %11, %9 ], [ 0, %6 ], [ -1, %24 ], [ -1, %28 ], [ -1, %15 ]
br label %3
20: ; preds = %12
%21 = tail call i32 @isprint(i8 signext %13)
%22 = icmp eq i32 %21, 0
%23 = load i32, i32* @stderr
br i1 %22, label %28, label %24
24: ; preds = %20
%25 = load i8, i8* @optopt
%26 = sext i8 %25 to i32
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %26)
br label %18
28: ; preds = %20
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %18
30: ; preds = %3
%31 = load i32, i32* @stderr
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
br label %18
33: ; preds = %3
ret i32 %4
}