#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 130
char *optarg;
int optind;
#define optional_argument 129
int /*<<< orphan*/ printf(char *, ...);
#define required_argument 128
int main(int argc, char **argv) {
  int opt;
  int digit_optind = 0;
  int option_index = 0;
  char *optstring = "a:b:c:d";
  static struct option long_options[] = {
      {"reqarg", required_argument, NULL, 'r'},
      {"noarg", no_argument, NULL, 'n'},
      {"optarg", optional_argument, NULL, 'o'},
      {0, 0, 0, 0}};
  while ((opt = getopt_long(argc - 2, argv + 2, optstring, long_options,
                            &option_index)) != -1) {
    printf("opt = %c\n", opt);
    printf("optarg = %s\n", optarg);
    printf("optind = %d\n", optind);
    printf("argv[optind - 1] = %s\n", argv[optind - 1]);
    printf("option_index = %d\n", option_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,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xeb5(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x2,%edi
mov    -0x10(%rbp),%rsi
add    $0x10,%rsi
mov    -0x28(%rbp),%rdx
lea    0x2ed8(%rip),%rcx
lea    -0x1c(%rbp),%r8
call   1030 <getopt_long@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11f8 <main+0xd8>
mov    -0x14(%rbp),%esi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%rsi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x2e18(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    114f <main+0x2f>
xor    %eax,%eax
add    $0x30,%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,%ebp
movl   $0x0,0x4(%rsp)
add    $0xfffffffe,%ebp
lea    0x10(%rsi),%rbx
lea    0xeba(%rip),%rdx
lea    0x2ef3(%rip),%rcx
lea    0x4(%rsp),%r8
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <getopt_long@plt>
cmp    $0xffffffff,%eax
je     11ff <main+0xdf>
mov    0x2e74(%rip),%r13
lea    0x2ecd(%rip),%r15
lea    0x4(%rsp),%r12
nopl   0x0(%rax,%rax,1)
lea    0xe95(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e61(%rip),%rax
mov    (%rax),%rsi
lea    0xe85(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%esi
lea    0xe80(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movslq 0x0(%r13),%rax
mov    -0x8(%r14,%rax,8),%rsi
lea    0xe76(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%esi
lea    0xe7b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
lea    0xe11(%rip),%rdx
mov    %r15,%rcx
mov    %r12,%r8
call   1030 <getopt_long@plt>
cmp    $0xffffffff,%eax
jne    1180 <main+0x60>
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 }
@.str = [8 x i8] c"a:b:c:d\00"
@main.long_options = internal global [4 x %struct.option] [%struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i8 -128, i32* null, i32 114 }, %struct.option { i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8 -126, i32* null, i32 110 }, %struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i32 0, i32 0), i8 -127, i32* null, i32 111 }, %struct.option zeroinitializer]
@.str.1 = [7 x i8] c"reqarg\00"
@.str.2 = [6 x i8] c"noarg\00"
@.str.3 = [7 x i8] c"optarg\00"
@.str.4 = [10 x i8] c"opt = %c\0A\00"
@.str.5 = [13 x i8] c"optarg = %s\0A\00"
@optarg = global i8* null
@.str.6 = [13 x i8] c"optind = %d\0A\00"
@optind = global i32 0
@.str.7 = [23 x i8] c"argv[optind - 1] = %s\0A\00"
@.str.8 = [19 x i8] c"option_index = %d\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
%9 = alloca i8*
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
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %9
br label %10
10: ; preds = %18, %2
%11 = load i32, i32* %4
%12 = sub nsw i32 %11, 2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %9
%16 = call i32 @getopt_long(i32 %12, i8** %14, i8* %15, %struct.option* getelementptr inbounds ([4 x %struct.option], [4 x %struct.option]* @main.long_options, i64 0, i64 0), i32* %8)
store i32 %16, i32* %6
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %34
18: ; preds = %10
%19 = load i32, i32* %6
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%21 = load i8*, i8** @optarg
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @optind
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 %23)
%25 = load i8**, i8*** %5
%26 = load i32, i32* @optind
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %25, i64 %28
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %30)
%32 = load i32, i32* %8
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i32 %32)
br label %10
34: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32*, i32 }
@.str = [8 x i8] c"a:b:c:d\00"
@main.long_options = internal global [4 x %struct.option] [%struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i8 -128, i32* null, i32 114 }, %struct.option { i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8 -126, i32* null, i32 110 }, %struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i32 0, i32 0), i8 -127, i32* null, i32 111 }, %struct.option zeroinitializer]
@.str.1 = [7 x i8] c"reqarg\00"
@.str.2 = [6 x i8] c"noarg\00"
@.str.3 = [7 x i8] c"optarg\00"
@.str.4 = [10 x i8] c"opt = %c\0A\00"
@.str.5 = [13 x i8] c"optarg = %s\0A\00"
@optarg = global i8* null
@.str.6 = [13 x i8] c"optind = %d\0A\00"
@optind = global i32 0
@.str.7 = [23 x i8] c"argv[optind - 1] = %s\0A\00"
@.str.8 = [19 x i8] c"option_index = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = add nsw i32 %0, -2
%6 = getelementptr inbounds i8*, i8** %1, i64 2
%7 = call i32 @getopt_long(i32 %5, i8** %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %struct.option* getelementptr inbounds ([4 x %struct.option], [4 x %struct.option]* @main.long_options, i64 0, i64 0), i32* %3)
%8 = icmp eq i32 %7, -1
br i1 %8, label %26, label %9
9: ; preds = %2, %9
%10 = phi i32 [ %24, %9 ], [ %7, %2 ]
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %10)
%12 = load i8*, i8** @optarg
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @optind
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 %14)
%16 = load i32, i32* @optind
%17 = add nsw i32 %16, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %20)
%22 = load i32, i32* %3
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i32 %22)
%24 = call i32 @getopt_long(i32 %5, i8** %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %struct.option* getelementptr inbounds ([4 x %struct.option], [4 x %struct.option]* @main.long_options, i64 0, i64 0), i32* %3)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %9
26: ; preds = %9, %2
ret i32 0
}