#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*/ const member_1;
};
typedef int /*<<< orphan*/ int64_t;
typedef int /*<<< orphan*/ int32_t;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int /*<<< orphan*/);
char getopt_long(int /*<<< orphan*/, char **, char *, struct option *, int *);
#define no_argument 129
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ print_help();
int /*<<< orphan*/ print_version();
#define required_argument 128
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strtol(int /*<<< orphan*/, int /*<<< orphan*/ *,
                          int /*<<< orphan*/);
int main(int32_t argc, char **argv) {
  int64_t opt_arg;
  char getopt_c;
  int getopt_i;
  while (1) {
    static struct option getopt_opts[] = {{"arg", required_argument, 0, 'a'},
                                          {"help", no_argument, 0, 'h'},
                                          {"version", no_argument, 0, 'v'},
                                          {0, 0, 0, 0}};
    getopt_c = getopt_long(argc, argv, "a:hv", getopt_opts, &getopt_i);
    if (getopt_c == -1)
      break;
    switch (getopt_c) {
    case 'a':
      opt_arg = strtol(optarg, NULL, 0);
      break;
    case 'h':
      print_help();
      return EXIT_SUCCESS;
    case 'v':
      print_version();
      return EXIT_SUCCESS;
    case '?':
      break;
    }
  }
  fprintf(stdout, "Ending program with arg %ld\n", opt_arg);
  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)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe9d(%rip),%rdx
lea    0x2ed5(%rip),%rcx
lea    -0x1c(%rbp),%r8
call   1040 <getopt_long@plt>
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%eax
cmp    $0xffffffff,%eax
jne    1199 <main+0x49>
jmp    1237 <main+0xe7>
movsbl -0x15(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x3f,%eax
je     122d <main+0xdd>
jmp    11ae <main+0x5e>
mov    -0x20(%rbp),%eax
sub    $0x61,%eax
je     11e1 <main+0x91>
jmp    11bf <main+0x6f>
mov    -0x20(%rbp),%eax
sub    $0x68,%eax
je     11fd <main+0xad>
jmp    11d0 <main+0x80>
mov    -0x20(%rbp),%eax
sub    $0x76,%eax
je     1215 <main+0xc5>
jmp    1232 <main+0xe2>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,-0x14(%rbp)
jmp    1232 <main+0xe2>
mov    $0x0,%al
call   1070 <print_help@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    125b <main+0x10b>
mov    $0x0,%al
call   1030 <print_version@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    125b <main+0x10b>
jmp    1232 <main+0xe2>
jmp    1166 <main+0x16>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xdcc(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%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    0xeaa(%rip),%r14
lea    0x2ee2(%rip),%r15
lea    0x4(%rsp),%r12
mov    %r14,%rdx
mov    %r15,%rcx
mov    %r12,%r8
call   1040 <getopt_long@plt>
jmp    11bc <main+0x6c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,%r13d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %r12,%r8
call   1040 <getopt_long@plt>
cmp    $0xff,%al
je     11d7 <main+0x87>
movsbl %al,%eax
cmp    $0x61,%eax
je     1190 <main+0x40>
cmp    $0x68,%eax
je     11f1 <main+0xa1>
cmp    $0x76,%eax
jne    11a5 <main+0x55>
xor    %eax,%eax
call   1030 <print_version@plt>
jmp    11f8 <main+0xa8>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
mov    %r13d,%edx
call   1050 <fprintf@plt>
jmp    11f8 <main+0xa8>
xor    %eax,%eax
call   1070 <print_help@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%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.getopt_opts = internal global [4 x %struct.option] [%struct.option { i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8 -128, i32 0, i32 97 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8 -127, i32 0, i32 104 }, %struct.option { i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i32 0, i32 0), i8 -127, i32 0, i32 118 }, %struct.option zeroinitializer]
@.str = [4 x i8] c"arg\00"
@.str.1 = [5 x i8] c"help\00"
@.str.2 = [8 x i8] c"version\00"
@.str.3 = [5 x i8] c"a:hv\00"
@optarg = global i32 0
@EXIT_SUCCESS = global i32 0
@stdout = global i32 0
@.str.4 = [29 x i8] c"Ending program with arg %ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %9
9: ; preds = %2, %30
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = call signext i8 @getopt_long(i32 %10, i8** %11, 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.getopt_opts, i64 0, i64 0), i32* %8)
store i8 %12, i8* %7
%13 = load i8, i8* %7
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %9
br label %31
17: ; preds = %9
%18 = load i8, i8* %7
%19 = sext i8 %18 to i32
switch i32 %19, label %30 [
i32 97, label %20
i32 104, label %23
i32 118, label %26
i32 63, label %29
]
20: ; preds = %17
%21 = load i32, i32* @optarg
%22 = call i32 @strtol(i32 %21, i32* null, i32 0)
store i32 %22, i32* %6
br label %30
23: ; preds = %17
%24 = call i32 (...) @print_help()
%25 = load i32, i32* @EXIT_SUCCESS
store i32 %25, i32* %3
br label %36
26: ; preds = %17
%27 = call i32 (...) @print_version()
%28 = load i32, i32* @EXIT_SUCCESS
store i32 %28, i32* %3
br label %36
29: ; preds = %17
br label %30
30: ; preds = %17, %29, %20
br label %9
31: ; preds = %16
%32 = load i32, i32* @stdout
%33 = load i32, i32* %6
%34 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %33)
%35 = load i32, i32* @EXIT_SUCCESS
store i32 %35, i32* %3
br label %36
36: ; preds = %31, %26, %23
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32, i32 }
@main.getopt_opts = internal global [4 x %struct.option] [%struct.option { i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8 -128, i32 0, i32 97 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8 -127, i32 0, i32 104 }, %struct.option { i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i32 0, i32 0), i8 -127, i32 0, i32 118 }, %struct.option zeroinitializer]
@.str = [4 x i8] c"arg\00"
@.str.1 = [5 x i8] c"help\00"
@.str.2 = [8 x i8] c"version\00"
@.str.3 = [5 x i8] c"a:hv\00"
@optarg = global i32 0
@EXIT_SUCCESS = global i32 0
@stdout = global i32 0
@.str.4 = [29 x i8] c"Ending program with arg %ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call signext i8 @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.getopt_opts, i64 0, i64 0), i32* %3)
%6 = icmp ne i8 %5, -1
br label %7
7: ; preds = %2, %18
%8 = phi i8 [ %20, %18 ], [ %5, %2 ]
%9 = phi i32 [ %19, %18 ], [ undef, %2 ]
%10 = sext i8 %8 to i32
switch i32 %10, label %18 [
i32 97, label %11
i32 104, label %14
i32 118, label %16
]
11: ; preds = %7
%12 = load i32, i32* @optarg
%13 = call i32 @strtol(i32 %12, i32* null, i32 0)
br label %18
14: ; preds = %7
%15 = call i32 (...) @print_help()
br label %25
16: ; preds = %7
%17 = call i32 (...) @print_version()
br label %25
18: ; preds = %7, %11
%19 = phi i32 [ %9, %7 ], [ %13, %11 ]
%20 = call signext i8 @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.getopt_opts, i64 0, i64 0), i32* %3)
%21 = icmp eq i8 %20, -1
br i1 %21, label %22, label %7
22: ; preds = %18
%23 = load i32, i32* @stdout
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %19)
br label %25
25: ; preds = %22, %16, %14
%26 = load i32, i32* @EXIT_SUCCESS
ret i32 %26
}