#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 /*<<< orphan*/ error();
int getopt_long_only(int, char **, char *, struct option *, int *);
char *optarg;
scalar_t__ optind;
int /*<<< orphan*/ printf(char *, char *);
#define required_argument 128
int main(int argc, char *argv[]) {
  int c;
  int counter = 0;
  int option_index = 0;
  static struct option long_options[] = {{"name", required_argument, 0, 'a'},
                                         {0, 0, 0, 0}};
  while ((c = getopt_long_only(argc, argv, "a:", long_options,
                               &option_index)) != -1)
    switch (c) {
    case 'a':
      printf("-name %s\n", optarg);
      break;
    case '?':
      error();
    }
  argv += optind;
  argc -= optind;
  while (counter < argc)
    printf("Remaining arg:  %s\n", argv[counter++]);
  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)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xea3(%rip),%rdx
lea    0x2ed7(%rip),%rcx
lea    -0x1c(%rbp),%r8
call   1040 <getopt_long_only@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11ca <main+0x9a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x3f,%eax
je     11be <main+0x8e>
jmp    1192 <main+0x62>
mov    -0x20(%rbp),%eax
sub    $0x61,%eax
jne    11c5 <main+0x95>
jmp    11a3 <main+0x73>
mov    0x2e4e(%rip),%rax
mov    (%rax),%rsi
lea    0xe54(%rip),%rdi
call   1030 <printf@plt>
jmp    11c5 <main+0x95>
mov    $0x0,%al
call   1050 <error@plt>
jmp    1154 <main+0x24>
mov    0x2e0f(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0x2df9(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1227 <main+0xf7>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdf5(%rip),%rdi
call   1030 <printf@plt>
jmp    11f4 <main+0xc4>
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,%r14
mov    %edi,%ebx
movl   $0x0,0x4(%rsp)
lea    0xeb6(%rip),%r15
lea    0x2eea(%rip),%r12
lea    0x4(%rsp),%r13
lea    0xea6(%rip),%rbp
jmp    1182 <main+0x52>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x2e81(%rip),%rax
mov    (%rax),%rsi
mov    %rbp,%rdi
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
call   1040 <getopt_long_only@plt>
cmp    $0x3f,%eax
je     11b0 <main+0x80>
cmp    $0x61,%eax
je     1170 <main+0x40>
cmp    $0xffffffff,%eax
jne    1182 <main+0x52>
jmp    11b9 <main+0x89>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <error@plt>
jmp    1182 <main+0x52>
mov    0x2e20(%rip),%rax
mov    (%rax),%rax
sub    %eax,%ebx
test   %ebx,%ebx
jle    11f5 <main+0xc5>
lea    (%r14,%rax,8),%r15
mov    %ebx,%ebx
xor    %ebp,%ebp
lea    0xe3a(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbp,8),%rsi
add    $0x1,%rbp
mov    %r14,%rdi
call   1030 <printf@plt>
cmp    %rbp,%rbx
jne    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 [2 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8 -128, i32 0, i32 97 }, %struct.option zeroinitializer]
@.str = [5 x i8] c"name\00"
@.str.1 = [3 x i8] c"a:\00"
@.str.2 = [10 x i8] c"-name %s\0A\00"
@optarg = global i8* null
@optind = global i64 0
@.str.3 = [20 x i8] c"Remaining arg: %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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %21, %2
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = call i32 @getopt_long_only(i32 %10, i8** %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.option* getelementptr inbounds ([2 x %struct.option], [2 x %struct.option]* @main.long_options, i64 0, i64 0), i32* %8)
store i32 %12, i32* %6
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %22
14: ; preds = %9
%15 = load i32, i32* %6
switch i32 %15, label %21 [
i32 97, label %16
i32 63, label %19
]
16: ; preds = %14
%17 = load i8*, i8** @optarg
%18 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %17)
br label %21
19: ; preds = %14
%20 = call i32 (...) @error()
br label %21
21: ; preds = %19, %14, %16
br label %9
22: ; preds = %9
%23 = load i64, i64* @optind
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 %23
store i8** %25, i8*** %5
%26 = load i64, i64* @optind
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = sub nsw i64 %28, %26
%30 = trunc i64 %29 to i32
store i32 %30, i32* %4
br label %31
31: ; preds = %35, %22
%32 = load i32, i32* %7
%33 = load i32, i32* %4
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %43
35: ; preds = %31
%36 = load i8**, i8*** %5
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds i8*, i8** %36, i64 %39
%41 = load i8*, i8** %40
%42 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %41)
br label %31
43: ; preds = %31
ret i32 0
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32, i32 }
@main.long_options = internal global [2 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8 -128, i32 0, i32 97 }, %struct.option zeroinitializer]
@.str = [5 x i8] c"name\00"
@.str.1 = [3 x i8] c"a:\00"
@.str.2 = [10 x i8] c"-name %s\0A\00"
@optarg = global i8* null
@optind = global i64 0
@.str.3 = [20 x i8] c"Remaining arg: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
br label %5
5: ; preds = %7, %2
%6 = call i32 @getopt_long_only(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.option* getelementptr inbounds ([2 x %struct.option], [2 x %struct.option]* @main.long_options, i64 0, i64 0), i32* %3)
switch i32 %6, label %7 [
i32 -1, label %13
i32 97, label %8
i32 63, label %11
]
7: ; preds = %5, %11, %8
br label %5
8: ; preds = %5
%9 = load i8*, i8** @optarg
%10 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %9)
br label %7
11: ; preds = %5
%12 = call i32 (...) @error()
br label %7
13: ; preds = %5
%14 = load i64, i64* @optind
%15 = getelementptr inbounds i8*, i8** %1, i64 %14
%16 = trunc i64 %14 to i32
%17 = sub i32 %0, %16
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %13
%20 = zext i32 %17 to i64
br label %21
21: ; preds = %19, %21
%22 = phi i64 [ 0, %19 ], [ %23, %21 ]
%23 = add nuw nsw i64 %22, 1
%24 = getelementptr inbounds i8*, i8** %15, i64 %22
%25 = load i8*, i8** %24
%26 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = icmp eq i64 %23, %20
br i1 %27, label %28, label %21
28: ; preds = %21, %13
ret i32 0
}