#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 EXIT_SUCCESS;
int getopt(int, char **, char *);
char *optarg;
int optind;
int optopt;
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  int c;
  int verbose = 0;
  while ((c = getopt(argc, argv, "af:v")) != -1) {
    switch (c) {
    case 'a':
      printf("option a\n");
      break;
    case 'f':
      printf("option f with %s.\n", optarg);
      break;
    case 'v':
      verbose = 1;
      break;
    default:
      printf("unknown option = %c = ascii(0%x)\n", optopt, optopt);
      printf("return value of getopt() = %c\n", c);
    }
  }
  printf("verbose mode = %i\n", verbose);
  if (optind < argc) {
    int j = 1;
    while (optind < argc) {
      printf("argument[%i]=%s\n", j, argv[optind++]);
      j++;
    }
  }
  return EXIT_SUCCESS;
}


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)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xeb5(%rip),%rdx
call   1040 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1204 <main+0xe4>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x61,%eax
je     1192 <main+0x72>
jmp    1170 <main+0x50>
mov    -0x20(%rbp),%eax
sub    $0x66,%eax
je     11a5 <main+0x85>
jmp    1181 <main+0x61>
mov    -0x20(%rbp),%eax
sub    $0x76,%eax
je     11c2 <main+0xa2>
jmp    11ce <main+0xae>
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ff <main+0xdf>
mov    0x2e4c(%rip),%rax
mov    (%rax),%rsi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ff <main+0xdf>
movl   $0x1,-0x18(%rbp)
jmp    11ff <main+0xdf>
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
mov    0x2e02(%rip),%rax
mov    (%rax),%edx
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    113d <main+0x1d>
mov    -0x18(%rbp),%esi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    1286 <main+0x166>
movl   $0x1,-0x1c(%rbp)
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    1281 <main+0x161>
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    0x2d8a(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%edi
add    $0x1,%edi
mov    0x2d7c(%rip),%rdx
mov    %edi,(%rdx)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    122e <main+0x10e>
jmp    1286 <main+0x166>
mov    0x2d3b(%rip),%rax
mov    (%rax),%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,%r12
mov    %edi,%ebp
lea    0xeb9(%rip),%r14
mov    0x2eaa(%rip),%rbx
lea    0xeb0(%rip),%r15
movl   $0x0,0x4(%rsp)
jmp    1173 <main+0x43>
nop
cmp    $0x66,%r13d
jne    119c <main+0x6c>
mov    (%rbx),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r14,%rdx
call   1050 <getopt@plt>
mov    %eax,%r13d
cmp    $0x65,%eax
jg     1160 <main+0x30>
cmp    $0x61,%r13d
jne    11ac <main+0x7c>
lea    0xee8(%rip),%rdi
call   1030 <puts@plt>
jmp    1173 <main+0x43>
cmp    $0x76,%r13d
jne    11b2 <main+0x82>
movl   $0x1,0x4(%rsp)
jmp    1173 <main+0x43>
cmp    $0xffffffff,%r13d
je     11de <main+0xae>
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
lea    0xe56(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe68(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1173 <main+0x43>
lea    0xe74(%rip),%rdi
mov    0x4(%rsp),%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2de1(%rip),%r15
mov    (%r15),%eax
cmp    %ebp,%eax
jge    1232 <main+0x102>
mov    $0x1,%ebx
lea    0xe62(%rip),%r14
nopw   0x0(%rax,%rax,1)
lea    0x1(%rax),%ecx
mov    %ecx,(%r15)
cltq
mov    (%r12,%rax,8),%rdx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
mov    (%r15),%eax
cmp    %ebp,%eax
jl     1210 <main+0xe0>
mov    0x2d8f(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"af:v\00"
@.str.1 = [10 x i8] c"option a\0A\00"
@.str.2 = [19 x i8] c"option f with %s.\0A\00"
@optarg = global i8* null
@.str.3 = [34 x i8] c"unknown option = %c = ascii(0%x)\0A\00"
@optopt = global i32 0
@.str.4 = [31 x i8] c"return value of getopt() = %c\0A\00"
@.str.5 = [19 x i8] c"verbose mode = %i\0A\00"
@optind = global i32 0
@.str.6 = [17 x i8] c"argument[%i]=%s\0A\00"
@EXIT_SUCCESS = global i32 0
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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
br label %9
9: ; preds = %28, %2
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = call i32 @getopt(i32 %10, i8** %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %12, i32* %6
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %29
14: ; preds = %9
%15 = load i32, i32* %6
switch i32 %15, label %22 [
i32 97, label %16
i32 102, label %18
i32 118, label %21
]
16: ; preds = %14
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %28
18: ; preds = %14
%19 = load i8*, i8** @optarg
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %28
21: ; preds = %14
store i32 1, i32* %7
br label %28
22: ; preds = %14
%23 = load i32, i32* @optopt
%24 = load i32, i32* @optopt
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %23, i32 %24)
%26 = load i32, i32* %6
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %22, %21, %18, %16
br label %9
29: ; preds = %9
%30 = load i32, i32* %7
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %30)
%32 = load i32, i32* @optind
%33 = load i32, i32* %4
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %52
35: ; preds = %29
store i32 1, i32* %8
br label %36
36: ; preds = %40, %35
%37 = load i32, i32* @optind
%38 = load i32, i32* %4
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %51
40: ; preds = %36
%41 = load i32, i32* %8
%42 = load i8**, i8*** %5
%43 = load i32, i32* @optind
%44 = add nsw i32 %43, 1
store i32 %44, i32* @optind
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds i8*, i8** %42, i64 %45
%47 = load i8*, i8** %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %41, i8* %47)
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
br label %36
51: ; preds = %36
br label %52
52: ; preds = %51, %29
%53 = load i32, i32* @EXIT_SUCCESS
ret i32 %53
}

LLVM IR (-O2):
@.str = [5 x i8] c"af:v\00"
@.str.2 = [19 x i8] c"option f with %s.\0A\00"
@optarg = global i8* null
@.str.3 = [34 x i8] c"unknown option = %c = ascii(0%x)\0A\00"
@optopt = global i32 0
@.str.4 = [31 x i8] c"return value of getopt() = %c\0A\00"
@.str.5 = [19 x i8] c"verbose mode = %i\0A\00"
@optind = global i32 0
@.str.6 = [17 x i8] c"argument[%i]=%s\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [9 x i8] c"option a\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %5, %2
%4 = phi i32 [ 0, %2 ], [ 1, %5 ]
br label %5
5: ; preds = %16, %3
%6 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %6, label %12 [
i32 -1, label %17
i32 97, label %7
i32 102, label %9
i32 118, label %3
]
7: ; preds = %5
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %16
9: ; preds = %5
%10 = load i8*, i8** @optarg
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %10)
br label %16
12: ; preds = %5
%13 = load i32, i32* @optopt
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %13, i32 %13)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %6)
br label %16
16: ; preds = %12, %9, %7
br label %5
17: ; preds = %5
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %4)
%19 = load i32, i32* @optind
%20 = icmp slt i32 %19, %0
br i1 %20, label %21, label %32
21: ; preds = %17, %21
%22 = phi i32 [ %30, %21 ], [ %19, %17 ]
%23 = phi i32 [ %29, %21 ], [ 1, %17 ]
%24 = add nsw i32 %22, 1
store i32 %24, i32* @optind
%25 = sext i32 %22 to i64
%26 = getelementptr inbounds i8*, i8** %1, i64 %25
%27 = load i8*, i8** %26
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %23, i8* %27)
%29 = add nuw nsw i32 %23, 1
%30 = load i32, i32* @optind
%31 = icmp slt i32 %30, %0
br i1 %31, label %21, label %32
32: ; preds = %21, %17
%33 = load i32, i32* @EXIT_SUCCESS
ret i32 %33
}