#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 getopt(int, char **, char *);
int /*<<< orphan*/ help_and_exit(char *);
char *optarg;
int optind;
int optopt;
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  while (1) {
    int c = getopt(argc, argv, ":abf:o::");
    if (c == -1)
      break;
    switch (c) {
    case 'a':
      printf("Using the -a option\n");
      break;
    case 'b':
      printf("Using the -b option\n");
      break;
    case 'f':
      printf("f: %s\n", optarg);
      break;
    case 'o':
      printf("o: %s\n", optarg);
      break;
    case ':':
      printf("Missing argument to -%c\n", optopt);
      help_and_exit(argv[0]);
      break;
    case '?':
      printf("Used an argument unknown to getopt(): %c\n", optopt);
      help_and_exit(argv[0]);
      break;
    default:
      printf("Used an argument known to getopt() but not in our switch "
             "statement: %c\n",
             optopt);
      help_and_exit(argv[0]);
      break;
    }
  }
  for (int i = optind; i < argc; i++)
    printf("Parameters not handled by getopt(): argv[%d]=%s\n", i, argv[i]);
  printf("Program exited normally\n");
  return 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)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xf84(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    116b <main+0x3b>
jmp    126c <main+0x13c>
mov    -0x14(%rbp),%eax
add    $0xffffffc6,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x35,%eax
ja     1244 <main+0x114>
mov    -0x20(%rbp),%rax
lea    0xe75(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xf46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1267 <main+0x137>
lea    0xf48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1267 <main+0x137>
mov    0x2e37(%rip),%rax
mov    (%rax),%rsi
lea    0xf40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1267 <main+0x137>
mov    0x2e1a(%rip),%rax
mov    (%rax),%rsi
lea    0xf2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1267 <main+0x137>
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
lea    0xf15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <help_and_exit@plt>
jmp    1267 <main+0x137>
mov    0x2dbd(%rip),%rax
mov    (%rax),%esi
lea    0xf06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <help_and_exit@plt>
jmp    1267 <main+0x137>
mov    0x2d95(%rip),%rax
mov    (%rax),%esi
lea    0xf08(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <help_and_exit@plt>
jmp    1146 <main+0x16>
mov    0x2d65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12af <main+0x17f>
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xf0a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1278 <main+0x148>
lea    0xf1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%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
lea    0xf81(%rip),%r14
mov    0x2e82(%rip),%r12
lea    0xe9b(%rip),%r13
mov    0x2e8c(%rip),%r15
jmp    1188 <main+0x48>
mov    (%r12),%esi
lea    0xf76(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%rdi
call   1030 <help_and_exit@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1060 <getopt@plt>
lea    -0x3a(%rax),%ecx
cmp    $0x35,%ecx
ja     11ef <main+0xaf>
movslq 0x0(%r13,%rcx,4),%rax
add    %r13,%rax
jmp    *%rax
mov    (%r12),%esi
lea    0xf56(%rip),%rdi
jmp    1179 <main+0x39>
lea    0x101c(%rip),%rdi
call   1040 <puts@plt>
jmp    1188 <main+0x48>
lea    0xffa(%rip),%rdi
call   1040 <puts@plt>
jmp    1188 <main+0x48>
mov    (%r15),%rsi
lea    0xf07(%rip),%rdi
jmp    11e6 <main+0xa6>
mov    (%r15),%rsi
lea    0xf02(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1188 <main+0x48>
cmp    $0xffffffff,%eax
je     1204 <main+0xc4>
mov    (%r12),%esi
lea    0xf33(%rip),%rdi
jmp    1179 <main+0x39>
mov    0x2dcd(%rip),%rax
mov    (%rax),%r14d
cmp    %ebp,%r14d
jge    124d <main+0x10d>
movslq %r14d,%rax
lea    (%rbx,%rax,8),%rbx
lea    0xf59(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r14d
add    $0x8,%rbx
cmp    %r14d,%ebp
jne    1230 <main+0xf0>
lea    0xf57(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c":abf:o::\00"
@.str.1 = [21 x i8] c"Using the -a option\0A\00"
@.str.2 = [21 x i8] c"Using the -b option\0A\00"
@.str.3 = [7 x i8] c"f: %s\0A\00"
@optarg = global i8* null
@.str.4 = [7 x i8] c"o: %s\0A\00"
@.str.5 = [25 x i8] c"Missing argument to -%c\0A\00"
@optopt = global i32 0
@.str.6 = [42 x i8] c"Used an argument unknown to getopt(): %c\0A\00"
@.str.7 = [72 x i8] c"Used an argument known to getopt() but not in our switch statement: %c\0A\00"
@optind = global i32 0
@.str.8 = [49 x i8] c"Parameters not handled by getopt(): argv[%d]=%s\0A\00"
@.str.9 = [25 x i8] c"Program exited normally\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %8
8: ; preds = %2, %48
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call i32 @getopt(i32 %9, i8** %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %8
br label %49
15: ; preds = %8
%16 = load i32, i32* %6
switch i32 %16, label %41 [
i32 97, label %17
i32 98, label %19
i32 102, label %21
i32 111, label %24
i32 58, label %27
i32 63, label %34
]
17: ; preds = %15
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %48
19: ; preds = %15
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %48
21: ; preds = %15
%22 = load i8*, i8** @optarg
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %22)
br label %48
24: ; preds = %15
%25 = load i8*, i8** @optarg
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %25)
br label %48
27: ; preds = %15
%28 = load i32, i32* @optopt
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %28)
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 @help_and_exit(i8* %32)
br label %48
34: ; preds = %15
%35 = load i32, i32* @optopt
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i32 %35)
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 0
%39 = load i8*, i8** %38
%40 = call i32 @help_and_exit(i8* %39)
br label %48
41: ; preds = %15
%42 = load i32, i32* @optopt
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.7, i64 0, i64 0), i32 %42)
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 0
%46 = load i8*, i8** %45
%47 = call i32 @help_and_exit(i8* %46)
br label %48
48: ; preds = %41, %34, %27, %24, %21, %19, %17
br label %8
49: ; preds = %14
%50 = load i32, i32* @optind
store i32 %50, i32* %7
br label %51
51: ; preds = %63, %49
%52 = load i32, i32* %7
%53 = load i32, i32* %4
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %66
55: ; preds = %51
%56 = load i32, i32* %7
%57 = load i8**, i8*** %5
%58 = load i32, i32* %7
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8*, i8** %57, i64 %59
%61 = load i8*, i8** %60
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0), i32 %56, i8* %61)
br label %63
63: ; preds = %55
%64 = load i32, i32* %7
%65 = add nsw i32 %64, 1
store i32 %65, i32* %7
br label %51
66: ; preds = %51
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c":abf:o::\00"
@.str.3 = [7 x i8] c"f: %s\0A\00"
@optarg = global i8* null
@.str.4 = [7 x i8] c"o: %s\0A\00"
@.str.5 = [25 x i8] c"Missing argument to -%c\0A\00"
@optopt = global i32 0
@.str.6 = [42 x i8] c"Used an argument unknown to getopt(): %c\0A\00"
@.str.7 = [72 x i8] c"Used an argument known to getopt() but not in our switch statement: %c\0A\00"
@optind = global i32 0
@.str.8 = [49 x i8] c"Parameters not handled by getopt(): argv[%d]=%s\0A\00"
@str = [24 x i8] c"Program exited normally\00"
@str.10 = [20 x i8] c"Using the -b option\00"
@str.11 = [20 x i8] c"Using the -a option\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %7, %2
%4 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
switch i32 %4, label %26 [
i32 -1, label %31
i32 97, label %5
i32 98, label %8
i32 102, label %10
i32 111, label %13
i32 58, label %16
i32 63, label %21
]
5: ; preds = %3
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.11, i64 0, i64 0))
br label %7
7: ; preds = %5, %8, %10, %13, %16, %21, %26
br label %3
8: ; preds = %3
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.10, i64 0, i64 0))
br label %7
10: ; preds = %3
%11 = load i8*, i8** @optarg
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %11)
br label %7
13: ; preds = %3
%14 = load i8*, i8** @optarg
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %14)
br label %7
16: ; preds = %3
%17 = load i32, i32* @optopt
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %17)
%19 = load i8*, i8** %1
%20 = tail call i32 @help_and_exit(i8* %19)
br label %7
21: ; preds = %3
%22 = load i32, i32* @optopt
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i32 %22)
%24 = load i8*, i8** %1
%25 = tail call i32 @help_and_exit(i8* %24)
br label %7
26: ; preds = %3
%27 = load i32, i32* @optopt
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @.str.7, i64 0, i64 0), i32 %27)
%29 = load i8*, i8** %1
%30 = tail call i32 @help_and_exit(i8* %29)
br label %7
31: ; preds = %3
%32 = load i32, i32* @optind
%33 = icmp slt i32 %32, %0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = sext i32 %32 to i64
br label %38
36: ; preds = %38, %31
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
ret i32 0
38: ; preds = %34, %38
%39 = phi i64 [ %35, %34 ], [ %44, %38 ]
%40 = getelementptr inbounds i8*, i8** %1, i64 %39
%41 = load i8*, i8** %40
%42 = trunc i64 %39 to i32
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0), i32 %42, i8* %41)
%44 = add nsw i64 %39, 1
%45 = trunc i64 %44 to i32
%46 = icmp eq i32 %45, %0
br i1 %46, label %36, label %38
}