#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 option {
  char *member_0;
  int member_1;
  char member_3;
  int /*<<< orphan*/ *member_2;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int getopt_long(int, char **, char *, struct option const *,
                int /*<<< orphan*/ *);
char *optarg;
int optind;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  static const struct option options[] = {{"required", 1, NULL, 'r'},
                                          {"optional", 2, NULL, 'o'},
                                          {"none", 0, NULL, 'n'},
                                          {NULL, 0, NULL, 0}};
  int aflag = 0;
  int bflag = 0;
  char *cvalue = NULL;
  int index;
  int c;
  while ((c = getopt_long(argc, argv, "abc:", options, NULL)) >= 0)
    switch (c) {
    case 'a':
      aflag = 1;
      break;
    case 'b':
      bflag = 1;
      break;
    case 'c':
      cvalue = optarg;
      break;
    case '?':
      fputs("Unknown option.\n", stderr);
      return 1;
    default:
      fprintf(stderr, "This should never happen!\n");
      return 1;
    case 'r':
      printf("--required %s\n", optarg);
      break;
    case 'o':
      printf("--optional %s\n", optarg);
      break;
    case 'n':
      puts("--none");
      break;
    }
  printf("aflag = %d, bflag = %d, cvalue = %s\n", aflag, bflag, cvalue);
  for (index = optind; index < argc; index++)
    printf("Non-option argument %s\n", argv[index]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xf58(%rip),%rdx
lea    0x2c0f(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1040 <getopt_long@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jl     1288 <main+0x138>
mov    -0x28(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x33,%eax
ja     121c <main+0xcc>
mov    -0x30(%rbp),%rax
lea    0xe39(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x14(%rbp)
jmp    1283 <main+0x133>
movl   $0x1,-0x18(%rbp)
jmp    1283 <main+0x133>
mov    0x2e01(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1283 <main+0x133>
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
lea    0xedc(%rip),%rdi
call   1060 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e7 <main+0x197>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
lea    0xecc(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e7 <main+0x197>
mov    0x2dac(%rip),%rax
mov    (%rax),%rsi
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1283 <main+0x133>
mov    0x2d8f(%rip),%rax
mov    (%rax),%rsi
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1283 <main+0x133>
lea    0xeb3(%rip),%rdi
call   1030 <puts@plt>
jmp    117c <main+0x2c>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12e0 <main+0x190>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12ac <main+0x15c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%r15d
lea    0xf77(%rip),%rdx
lea    0x2c2e(%rip),%rcx
xor    %r8d,%r8d
call   1040 <getopt_long@plt>
mov    $0x0,%r12d
movl   $0x0,0xc(%rsp)
mov    $0x0,%ecx
mov    %rcx,0x10(%rsp)
test   %eax,%eax
js     1259 <main+0x109>
lea    0xe5f(%rip),%r13
lea    0x2bf8(%rip),%r14
xor    %ecx,%ecx
mov    %rcx,0x10(%rsp)
movl   $0x0,0xc(%rsp)
xor    %ebp,%ebp
jmp    11f2 <main+0xa2>
lea    0xf6f(%rip),%rdi
call   1030 <puts@plt>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%r12d
mov    %r15d,%edi
mov    %rbx,%rsi
lea    0xf02(%rip),%rdx
mov    %r14,%rcx
xor    %r8d,%r8d
call   1040 <getopt_long@plt>
mov    %r12d,%ebp
test   %eax,%eax
js     1259 <main+0x109>
add    $0xffffffc1,%eax
cmp    $0x33,%eax
ja     12e7 <main+0x197>
mov    $0x1,%r12d
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
movl   $0x1,0xc(%rsp)
jmp    11d0 <main+0x80>
mov    0x2dd1(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
jmp    11d0 <main+0x80>
mov    0x2dc0(%rip),%rax
mov    (%rax),%rsi
lea    0xee8(%rip),%rdi
jmp    124d <main+0xfd>
mov    0x2dad(%rip),%rax
mov    (%rax),%rsi
lea    0xec6(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11d0 <main+0x80>
lea    0xed8(%rip),%rdi
mov    %r12d,%esi
mov    0xc(%rsp),%edx
mov    0x10(%rsp),%rcx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d5e(%rip),%rax
movslq (%rax),%rax
cmp    %r15d,%eax
mov    $0x0,%r12d
jge    12b8 <main+0x168>
lea    (%rbx,%rax,8),%rbp
sub    %eax,%r15d
xor    %r12d,%r12d
lea    0xec4(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp,%rbx,8),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %ebx,%r15d
jne    12a0 <main+0x150>
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cf7(%rip),%rax
mov    (%rax),%esi
lea    0xe0d(%rip),%rdi
call   1060 <fputs@plt>
mov    $0x1,%r12d
jmp    12b8 <main+0x168>
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%r12d
jmp    12b8 <main+0x168>

LLVM IR (-O0):
%struct.option = type { i8*, i32, i8, i32* }
@main.options = internal constant [4 x %struct.option] [%struct.option { i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0), i32 1, i8 0, i32* inttoptr (i64 114 to i32*) }, %struct.option { i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i32 0, i32 0), i32 2, i8 0, i32* inttoptr (i64 111 to i32*) }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i32 0, i8 0, i32* inttoptr (i64 110 to i32*) }, %struct.option zeroinitializer]
@.str = [9 x i8] c"required\00"
@.str.1 = [9 x i8] c"optional\00"
@.str.2 = [5 x i8] c"none\00"
@.str.3 = [5 x i8] c"abc:\00"
@optarg = global i8* null
@.str.4 = [17 x i8] c"Unknown option.\0A\00"
@stderr = global i32 0
@.str.5 = [27 x i8] c"This should never happen!\0A\00"
@.str.6 = [15 x i8] c"--required %s\0A\00"
@.str.7 = [15 x i8] c"--optional %s\0A\00"
@.str.8 = [7 x i8] c"--none\00"
@.str.9 = [37 x i8] c"aflag = %d, bflag = %d, cvalue = %s\0A\00"
@optind = global i32 0
@.str.10 = [24 x i8] c"Non-option argument %s\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 i8*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i8* null, i8** %8
br label %11
11: ; preds = %36, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt_long(i32 %12, i8** %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %struct.option* getelementptr inbounds ([4 x %struct.option], [4 x %struct.option]* @main.options, i64 0, i64 0), i32* null)
store i32 %14, i32* %10
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %37
16: ; preds = %11
%17 = load i32, i32* %10
switch i32 %17, label %25 [
i32 97, label %18
i32 98, label %19
i32 99, label %20
i32 63, label %22
i32 114, label %28
i32 111, label %31
i32 110, label %34
]
18: ; preds = %16
store i32 1, i32* %6
br label %36
19: ; preds = %16
store i32 1, i32* %7
br label %36
20: ; preds = %16
%21 = load i8*, i8** @optarg
store i8* %21, i8** %8
br label %36
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = call i32 @fputs(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %23)
store i32 1, i32* %3
br label %58
25: ; preds = %16
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %58
28: ; preds = %16
%29 = load i8*, i8** @optarg
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %29)
br label %36
31: ; preds = %16
%32 = load i8*, i8** @optarg
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* %32)
br label %36
34: ; preds = %16
%35 = call i32 @puts(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %36
36: ; preds = %34, %31, %28, %20, %19, %18
br label %11
37: ; preds = %11
%38 = load i32, i32* %6
%39 = load i32, i32* %7
%40 = load i8*, i8** %8
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0), i32 %38, i32 %39, i8* %40)
%42 = load i32, i32* @optind
store i32 %42, i32* %9
br label %43
43: ; preds = %54, %37
%44 = load i32, i32* %9
%45 = load i32, i32* %4
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %57
47: ; preds = %43
%48 = load i8**, i8*** %5
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i8* %52)
br label %54
54: ; preds = %47
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 1
store i32 %56, i32* %9
br label %43
57: ; preds = %43
store i32 0, i32* %3
br label %58
58: ; preds = %57, %25, %22
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
%struct.option = type { i8*, i32, i8, i32* }
@main.options = internal constant [4 x %struct.option] [%struct.option { i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0), i32 1, i8 0, i32* inttoptr (i64 114 to i32*) }, %struct.option { i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i32 0, i32 0), i32 2, i8 0, i32* inttoptr (i64 111 to i32*) }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i32 0, i8 0, i32* inttoptr (i64 110 to i32*) }, %struct.option zeroinitializer]
@.str = [9 x i8] c"required\00"
@.str.1 = [9 x i8] c"optional\00"
@.str.2 = [5 x i8] c"none\00"
@.str.3 = [5 x i8] c"abc:\00"
@optarg = global i8* null
@.str.4 = [17 x i8] c"Unknown option.\0A\00"
@stderr = global i32 0
@.str.5 = [27 x i8] c"This should never happen!\0A\00"
@.str.6 = [15 x i8] c"--required %s\0A\00"
@.str.7 = [15 x i8] c"--optional %s\0A\00"
@.str.8 = [7 x i8] c"--none\00"
@.str.9 = [37 x i8] c"aflag = %d, bflag = %d, cvalue = %s\0A\00"
@optind = global i32 0
@.str.10 = [24 x i8] c"Non-option argument %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %struct.option* getelementptr inbounds ([4 x %struct.option], [4 x %struct.option]* @main.options, i64 0, i64 0), i32* null)
%4 = icmp sgt i32 %3, -1
br i1 %4, label %5, label %33
5: ; preds = %2, %27
%6 = phi i32 [ %31, %27 ], [ %3, %2 ]
%7 = phi i8* [ %30, %27 ], [ null, %2 ]
%8 = phi i32 [ %29, %27 ], [ 0, %2 ]
%9 = phi i32 [ %28, %27 ], [ 0, %2 ]
switch i32 %6, label %16 [
i32 97, label %27
i32 98, label %10
i32 99, label %11
i32 63, label %13
i32 114, label %19
i32 111, label %22
i32 110, label %25
]
10: ; preds = %5
br label %27
11: ; preds = %5
%12 = load i8*, i8** @optarg
br label %27
13: ; preds = %5
%14 = load i32, i32* @stderr
%15 = tail call i32 @fputs(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %14)
br label %50
16: ; preds = %5
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %50
19: ; preds = %5
%20 = load i8*, i8** @optarg
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %20)
br label %27
22: ; preds = %5
%23 = load i8*, i8** @optarg
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* %23)
br label %27
25: ; preds = %5
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %27
27: ; preds = %5, %25, %22, %19, %11, %10
%28 = phi i32 [ %9, %25 ], [ %9, %22 ], [ %9, %19 ], [ %9, %11 ], [ %9, %10 ], [ 1, %5 ]
%29 = phi i32 [ %8, %25 ], [ %8, %22 ], [ %8, %19 ], [ %8, %11 ], [ 1, %10 ], [ %8, %5 ]
%30 = phi i8* [ %7, %25 ], [ %7, %22 ], [ %7, %19 ], [ %12, %11 ], [ %7, %10 ], [ %7, %5 ]
%31 = tail call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %struct.option* getelementptr inbounds ([4 x %struct.option], [4 x %struct.option]* @main.options, i64 0, i64 0), i32* null)
%32 = icmp sgt i32 %31, -1
br i1 %32, label %5, label %33
33: ; preds = %27, %2
%34 = phi i32 [ 0, %2 ], [ %28, %27 ]
%35 = phi i32 [ 0, %2 ], [ %29, %27 ]
%36 = phi i8* [ null, %2 ], [ %30, %27 ]
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0), i32 %34, i32 %35, i8* %36)
%38 = load i32, i32* @optind
%39 = icmp slt i32 %38, %0
br i1 %39, label %40, label %50
40: ; preds = %33
%41 = sext i32 %38 to i64
br label %42
42: ; preds = %40, %42
%43 = phi i64 [ %41, %40 ], [ %47, %42 ]
%44 = getelementptr inbounds i8*, i8** %1, i64 %43
%45 = load i8*, i8** %44
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i8* %45)
%47 = add nsw i64 %43, 1
%48 = trunc i64 %47 to i32
%49 = icmp eq i32 %48, %0
br i1 %49, label %50, label %42
50: ; preds = %42, %33, %16, %13
%51 = phi i32 [ 1, %16 ], [ 1, %13 ], [ 0, %33 ], [ 0, %42 ]
ret i32 %51
}