#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 /*<<< orphan*/ exit(int);
int getopt(int, char **, char *);
char *optarg;
int optind;
int optopt;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  int opt;
  if (argc < 2) {
    usage(argv[0]);
    exit(1);
  }
  while ((opt = getopt(argc, argv, ":if:lr")) != -1) {
    switch (opt) {
    case 'i':
    case 'l':
    case 'r':
      printf("option: %c\n", opt);
      break;
    case 'f':
      printf("filename: %s\n", optarg);
      break;
    case ':':
      printf("option needs a value\n");
      break;
    case '?':
      printf("unknown option: %c\n", optopt);
      usage(argv[0]);
      break;
    }
  }
  for (; optind < argc; optind++)
    printf("argument: %s\n", argv[optind]);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1176 <main+0x36>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <usage@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    117b <main+0x3b>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xf5b(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1231 <main+0xf1>
mov    -0x14(%rbp),%eax
add    $0xffffffc6,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x38,%eax
ja     122c <main+0xec>
mov    -0x20(%rbp),%rax
lea    0xe46(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x14(%rbp),%esi
lea    0xf4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122c <main+0xec>
mov    0x2e18(%rip),%rax
mov    (%rax),%rsi
lea    0xf01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122c <main+0xec>
lea    0xefc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122c <main+0xec>
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
lea    0xef6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <usage@plt>
jmp    117b <main+0x3b>
jmp    1236 <main+0xf6>
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    1282 <main+0x142>
mov    -0x10(%rbp),%rax
mov    0x2d85(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    0x2d5d(%rip),%rax
mov    %ecx,(%rax)
jmp    1236 <main+0xf6>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jge    1175 <main+0x25>
mov    (%rbx),%rdi
call   1050 <usage@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    %edi,%ebp
lea    0xf66(%rip),%r14
lea    0xe7b(%rip),%r12
lea    0xf5f(%rip),%r13
lea    0xf6e(%rip),%r15
jmp    11c0 <main+0x70>
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
lea    0xf54(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rdi
call   1050 <usage@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1060 <getopt@plt>
lea    -0x3a(%rax),%ecx
cmp    $0x38,%ecx
ja     1210 <main+0xc0>
movslq (%r12,%rcx,4),%rcx
add    %r12,%rcx
jmp    *%rcx
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c0 <main+0x70>
lea    0xf28(%rip),%rdi
call   1030 <puts@plt>
jmp    11c0 <main+0x70>
mov    0x2df7(%rip),%rax
mov    (%rax),%rsi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c0 <main+0x70>
cmp    $0xffffffff,%eax
jne    11c0 <main+0x70>
mov    0x2dbc(%rip),%r15
mov    (%r15),%eax
cmp    %ebp,%eax
jge    124d <main+0xfd>
lea    0xee3(%rip),%r14
nopw   0x0(%rax,%rax,1)
cltq
mov    (%rbx,%rax,8),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15),%eax
add    $0x1,%eax
mov    %eax,(%r15)
cmp    %ebp,%eax
jl     1230 <main+0xe0>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c":if:lr\00"
@.str.1 = [12 x i8] c"option: %c\0A\00"
@.str.2 = [14 x i8] c"filename: %s\0A\00"
@optarg = global i8* null
@.str.3 = [22 x i8] c"option needs a value\0A\00"
@.str.4 = [20 x i8] c"unknown option: %c\0A\00"
@optopt = global i32 0
@optind = global i32 0
@.str.5 = [14 x i8] c"argument: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 @usage(i8* %12)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
br label %16
16: ; preds = %38, %15
%17 = load i32, i32* %4
%18 = load i8**, i8*** %5
%19 = call i32 @getopt(i32 %17, i8** %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %19, i32* %6
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %39
21: ; preds = %16
%22 = load i32, i32* %6
switch i32 %22, label %38 [
i32 105, label %23
i32 108, label %23
i32 114, label %23
i32 102, label %26
i32 58, label %29
i32 63, label %31
]
23: ; preds = %21, %21, %21
%24 = load i32, i32* %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %38
26: ; preds = %21
%27 = load i8*, i8** @optarg
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %27)
br label %38
29: ; preds = %21
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %38
31: ; preds = %21
%32 = load i32, i32* @optopt
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 0
%36 = load i8*, i8** %35
%37 = call i32 @usage(i8* %36)
br label %38
38: ; preds = %21, %31, %29, %26, %23
br label %16
39: ; preds = %16
br label %40
40: ; preds = %51, %39
%41 = load i32, i32* @optind
%42 = load i32, i32* %4
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %54
44: ; preds = %40
%45 = load i8**, i8*** %5
%46 = load i32, i32* @optind
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %49)
br label %51
51: ; preds = %44
%52 = load i32, i32* @optind
%53 = add nsw i32 %52, 1
store i32 %53, i32* @optind
br label %40
54: ; preds = %40
%55 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [7 x i8] c":if:lr\00"
@.str.1 = [12 x i8] c"option: %c\0A\00"
@.str.2 = [14 x i8] c"filename: %s\0A\00"
@optarg = global i8* null
@.str.4 = [20 x i8] c"unknown option: %c\0A\00"
@optopt = global i32 0
@optind = global i32 0
@.str.5 = [14 x i8] c"argument: %s\0A\00"
@str = [21 x i8] c"option needs a value\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @usage(i8* %5)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2, %10
%9 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
switch i32 %9, label %10 [
i32 -1, label %11
i32 105, label %14
i32 108, label %14
i32 114, label %14
i32 102, label %16
i32 58, label %19
i32 63, label %21
]
10: ; preds = %8, %21, %19, %16, %14
br label %8
11: ; preds = %8
%12 = load i32, i32* @optind
%13 = icmp slt i32 %12, %0
br i1 %13, label %26, label %35
14: ; preds = %8, %8, %8
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %10
16: ; preds = %8
%17 = load i8*, i8** @optarg
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %17)
br label %10
19: ; preds = %8
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %10
21: ; preds = %8
%22 = load i32, i32* @optopt
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %22)
%24 = load i8*, i8** %1
%25 = tail call i32 @usage(i8* %24)
br label %10
26: ; preds = %11, %26
%27 = phi i32 [ %33, %26 ], [ %12, %11 ]
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %1, i64 %28
%30 = load i8*, i8** %29
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @optind
%33 = add nsw i32 %32, 1
store i32 %33, i32* @optind
%34 = icmp slt i32 %33, %0
br i1 %34, label %26, label %35
35: ; preds = %26, %11
%36 = tail call i32 @exit(i32 0)
unreachable
}