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

/* Variables and functions */
int getopt_long(int, char **, char *, struct option *, int *);
#define no_argument 129
char *optarg;
int optind;
int /*<<< orphan*/ printf(char *, ...);
#define required_argument 128
int main(int argc, char *argv[]) {
  int c;
  while (1) {
    static struct option long_options[] = {{"version", no_argument, 0, 'v'},
                                           {"opt1", required_argument, 0, 'o'},
                                           {0, 0, 0, 0}};
    int option_index = 0;
    c = getopt_long(argc, argv, "va:", long_options, &option_index);
    if (c == -1)
      break;
    switch (c) {
    case 'v':
      printf("set v option\n");
      break;
    case 'a':
      printf("set a option = %s\n", optarg);
      break;
    case '?':
      printf("error");
    }
  }
  while (optind < argc)
    printf("%s\n", argv[optind++]);
  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)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xec2(%rip),%rdx
lea    0x2eee(%rip),%rcx
lea    -0x18(%rbp),%r8
call   1030 <getopt_long@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    116d <main+0x4d>
jmp    11e6 <main+0xc6>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x3f,%eax
je     11d3 <main+0xb3>
jmp    1181 <main+0x61>
mov    -0x1c(%rbp),%eax
sub    $0x61,%eax
je     11b6 <main+0x96>
jmp    1192 <main+0x72>
mov    -0x1c(%rbp),%eax
sub    $0x76,%eax
jne    11e1 <main+0xc1>
jmp    11a3 <main+0x83>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11e1 <main+0xc1>
mov    0x2e3b(%rip),%rax
mov    (%rax),%rsi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11e1 <main+0xc1>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1136 <main+0x16>
jmp    11eb <main+0xcb>
mov    0x2dee(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    1232 <main+0x112>
mov    -0x10(%rbp),%rax
mov    0x2dd8(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    0x2dca(%rip),%rdx
mov    %esi,(%rdx)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11eb <main+0xcb>
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    0xec6(%rip),%r14
lea    0x2ef2(%rip),%r15
lea    0x4(%rsp),%r12
lea    0xed0(%rip),%r13
jmp    1178 <main+0x48>
nopl   0x0(%rax)
mov    0x2e91(%rip),%rax
mov    (%rax),%rsi
lea    0xea0(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x0,0x4(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %r12,%r8
call   1040 <getopt_long@plt>
cmp    $0x60,%eax
jle    11b0 <main+0x80>
cmp    $0x61,%eax
je     1160 <main+0x30>
cmp    $0x76,%eax
jne    1178 <main+0x48>
mov    %r13,%rdi
call   1030 <puts@plt>
jmp    1178 <main+0x48>
nopl   0x0(%rax)
cmp    $0x3f,%eax
jne    11c5 <main+0x95>
lea    0xe68(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1178 <main+0x48>
cmp    $0xffffffff,%eax
jne    1178 <main+0x48>
mov    0x2e0f(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14),%eax
cmp    %ebp,%eax
jge    11fa <main+0xca>
lea    0x1(%rax),%ecx
mov    %ecx,(%r14)
cltq
mov    (%rbx,%rax,8),%rdi
call   1030 <puts@plt>
jmp    11e0 <main+0xb0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.option = type { i8*, i8, i32, i32 }
@main.long_options = internal global [3 x %struct.option] [%struct.option { i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8 -127, i32 0, i32 118 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8 -128, i32 0, i32 111 }, %struct.option zeroinitializer]
@.str = [8 x i8] c"version\00"
@.str.1 = [5 x i8] c"opt1\00"
@.str.2 = [4 x i8] c"va:\00"
@.str.3 = [14 x i8] c"set v option\0A\00"
@.str.4 = [19 x i8] c"set a option = %s\0A\00"
@optarg = global i8* null
@.str.5 = [6 x i8] c"error\00"
@optind = global i32 0
@.str.6 = [4 x i8] c"%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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %8
8: ; preds = %2, %24
store i32 0, i32* %7
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call i32 @getopt_long(i32 %9, i8** %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %struct.option* getelementptr inbounds ([3 x %struct.option], [3 x %struct.option]* @main.long_options, i64 0, i64 0), i32* %7)
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 %25
15: ; preds = %8
%16 = load i32, i32* %6
switch i32 %16, label %24 [
i32 118, label %17
i32 97, label %19
i32 63, label %22
]
17: ; preds = %15
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %24
19: ; preds = %15
%20 = load i8*, i8** @optarg
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %20)
br label %24
22: ; preds = %15
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %24
24: ; preds = %22, %15, %19, %17
br label %8
25: ; preds = %14
br label %26
26: ; preds = %30, %25
%27 = load i32, i32* @optind
%28 = load i32, i32* %4
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %38
30: ; preds = %26
%31 = load i8**, i8*** %5
%32 = load i32, i32* @optind
%33 = add nsw i32 %32, 1
store i32 %33, i32* @optind
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds i8*, i8** %31, i64 %34
%36 = load i8*, i8** %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %36)
br label %26
38: ; preds = %26
ret i32 0
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32, i32 }
@main.long_options = internal global [3 x %struct.option] [%struct.option { i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8 -127, i32 0, i32 118 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8 -128, i32 0, i32 111 }, %struct.option zeroinitializer]
@.str = [8 x i8] c"version\00"
@.str.1 = [5 x i8] c"opt1\00"
@.str.2 = [4 x i8] c"va:\00"
@.str.4 = [19 x i8] c"set a option = %s\0A\00"
@optarg = global i8* null
@.str.5 = [6 x i8] c"error\00"
@optind = global i32 0
@str = [13 x i8] c"set v option\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
br label %5
5: ; preds = %14, %2
store i32 0, i32* %3
%6 = call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %struct.option* getelementptr inbounds ([3 x %struct.option], [3 x %struct.option]* @main.long_options, i64 0, i64 0), i32* %3)
switch i32 %6, label %14 [
i32 -1, label %15
i32 118, label %7
i32 97, label %9
i32 63, label %12
]
7: ; preds = %5
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %14
9: ; preds = %5
%10 = load i8*, i8** @optarg
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %10)
br label %14
12: ; preds = %5
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %14
14: ; preds = %5, %12, %9, %7
br label %5
15: ; preds = %5
%16 = load i32, i32* @optind
%17 = icmp slt i32 %16, %0
br i1 %17, label %18, label %27
18: ; preds = %15, %18
%19 = phi i32 [ %25, %18 ], [ %16, %15 ]
%20 = add nsw i32 %19, 1
store i32 %20, i32* @optind
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds i8*, i8** %1, i64 %21
%23 = load i8*, i8** %22
%24 = call i32 @puts(i8* dereferenceable(1) %23)
%25 = load i32, i32* @optind
%26 = icmp slt i32 %25, %0
br i1 %26, label %18, label %27
27: ; preds = %18, %15
ret i32 0
}