#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 {
  int has_arg;
  scalar_t__ name;
};

/* Variables and functions */
int ENOENT;
#define no_argument 130
char *optarg;
#define optional_argument 129
#define required_argument 128
char *strchrnul(char const *, char);
scalar_t__ strncmp(char const *, scalar_t__, int);
int getopt_try_long(int argl, char *const arg[], const struct option *longopts,
                    const struct option **out_lopt) {
  const struct option *lopt;
  for (lopt = longopts; lopt->name; lopt++) {
    const char *opt = arg[0] + 2;
    char *optarg_sep = strchrnul(opt, '=');
    *out_lopt = lopt;
    if (0 == strncmp(opt, lopt->name, optarg_sep - opt)) {
      switch (lopt->has_arg) {
      case no_argument:
        if (!*optarg_sep) {
          optarg = NULL;
          return 1;
        }
        break;
      case required_argument:
        if (*optarg_sep) {
          optarg = optarg_sep + 1;
          return 1;
        } else if (argl >= 1) {
          optarg = arg[1];
          return 2;
        }
        break;
      case optional_argument:
        optarg = *optarg_sep ? optarg_sep + 1 : NULL;
        return 1;
      }
    }
  }
  return -ENOENT;
}


x86 assembly (clang, -O0):
<getopt_try_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     12cf <getopt_try_long+0x1af>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
add    $0x2,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x3d,%esi
call   1040 <strchrnul@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12b9 <getopt_try_long+0x199>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x80,%eax
je     1211 <getopt_try_long+0xf1>
jmp    11bf <getopt_try_long+0x9f>
mov    -0x3c(%rbp),%eax
sub    $0x81,%eax
je     126e <getopt_try_long+0x14e>
jmp    11d2 <getopt_try_long+0xb2>
mov    -0x3c(%rbp),%eax
sub    $0x82,%eax
jne    12b4 <getopt_try_long+0x194>
jmp    11e5 <getopt_try_long+0xc5>
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
jne    120c <getopt_try_long+0xec>
mov    0x2dff(%rip),%rax
movq   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    12dd <getopt_try_long+0x1bd>
jmp    12b4 <getopt_try_long+0x194>
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
je     123c <getopt_try_long+0x11c>
mov    -0x38(%rbp),%rcx
add    $0x1,%rcx
mov    0x2dcb(%rip),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    12dd <getopt_try_long+0x1bd>
cmpl   $0x1,-0x8(%rbp)
jl     1264 <getopt_try_long+0x144>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    0x2da3(%rip),%rax
mov    %rcx,(%rax)
movl   $0x2,-0x4(%rbp)
jmp    12dd <getopt_try_long+0x1bd>
jmp    1269 <getopt_try_long+0x149>
jmp    12b4 <getopt_try_long+0x194>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     128f <getopt_try_long+0x16f>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    129a <getopt_try_long+0x17a>
xor    %eax,%eax
mov    %rax,-0x48(%rbp)
jmp    129a <getopt_try_long+0x17a>
mov    -0x48(%rbp),%rcx
mov    0x2d53(%rip),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    12dd <getopt_try_long+0x1bd>
jmp    12b9 <getopt_try_long+0x199>
jmp    12be <getopt_try_long+0x19e>
mov    -0x28(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x28(%rbp)
jmp    113f <getopt_try_long+0x1f>
xor    %eax,%eax
mov    0x2cf8(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getopt_try_long>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmpq   $0x0,0x8(%rdx)
je     11c5 <getopt_try_long+0xa5>
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %edi,%r12d
jmp    115b <getopt_try_long+0x3b>
cmp    $0x81,%eax
je     11df <getopt_try_long+0xbf>
nop
cmpq   $0x0,0x18(%rbx)
lea    0x10(%rbx),%rbx
je     11c5 <getopt_try_long+0xa5>
mov    (%r15),%rbp
add    $0x2,%rbp
mov    %rbp,%rdi
mov    $0x3d,%esi
call   1040 <strchrnul@plt>
mov    %rax,%r13
mov    %rbx,(%r14)
mov    0x8(%rbx),%rsi
mov    %r13d,%edx
sub    %ebp,%edx
mov    %rbp,%rdi
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1150 <getopt_try_long+0x30>
mov    (%rbx),%eax
cmp    $0x80,%eax
je     11a4 <getopt_try_long+0x84>
cmp    $0x82,%eax
jne    1144 <getopt_try_long+0x24>
cmpb   $0x0,0x0(%r13)
jne    1150 <getopt_try_long+0x30>
jmp    1202 <getopt_try_long+0xe2>
cmpb   $0x0,0x0(%r13)
jne    1217 <getopt_try_long+0xf7>
test   %r12d,%r12d
jle    1150 <getopt_try_long+0x30>
mov    0x8(%r15),%rax
mov    0x2e3d(%rip),%rcx
mov    %rax,(%rcx)
mov    $0x2,%eax
jmp    11d0 <getopt_try_long+0xb0>
mov    0x2e04(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13,%rax
add    $0x1,%rax
xor    %ecx,%ecx
cmpb   $0x0,0x0(%r13)
cmovne %rax,%rcx
mov    0x2e00(%rip),%rax
mov    %rcx,(%rax)
mov    $0x1,%eax
jmp    11d0 <getopt_try_long+0xb0>
mov    0x2def(%rip),%rax
movq   $0x0,(%rax)
mov    $0x1,%eax
jmp    11d0 <getopt_try_long+0xb0>
add    $0x1,%r13
mov    0x2dd6(%rip),%rax
mov    %r13,(%rax)
mov    $0x1,%eax
jmp    11d0 <getopt_try_long+0xb0>

LLVM IR (-O0):
%struct.option = type { i32, i64 }
@optarg = global i8* null
@ENOENT = global i32 0
define i32 @getopt_try_long(i32 %0, i8** %1, %struct.option* %2, %struct.option** %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca %struct.option*
%9 = alloca %struct.option**
%10 = alloca %struct.option*
%11 = alloca i8*
%12 = alloca i8*
store i32 %0, i32* %6
store i8** %1, i8*** %7
store %struct.option* %2, %struct.option** %8
store %struct.option** %3, %struct.option*** %9
%13 = load %struct.option*, %struct.option** %8
store %struct.option* %13, %struct.option** %10
br label %14
14: ; preds = %79, %4
%15 = load %struct.option*, %struct.option** %10
%16 = getelementptr inbounds %struct.option, %struct.option* %15, i32 0, i32 1
%17 = load i64, i64* %16
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %82
19: ; preds = %14
%20 = load i8**, i8*** %7
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = getelementptr inbounds i8, i8* %22, i64 2
store i8* %23, i8** %11
%24 = load i8*, i8** %11
%25 = call i8* @strchrnul(i8* %24, i8 signext 61)
store i8* %25, i8** %12
%26 = load %struct.option*, %struct.option** %10
%27 = load %struct.option**, %struct.option*** %9
store %struct.option* %26, %struct.option** %27
%28 = load i8*, i8** %11
%29 = load %struct.option*, %struct.option** %10
%30 = getelementptr inbounds %struct.option, %struct.option* %29, i32 0, i32 1
%31 = load i64, i64* %30
%32 = load i8*, i8** %12
%33 = load i8*, i8** %11
%34 = ptrtoint i8* %32 to i64
%35 = ptrtoint i8* %33 to i64
%36 = sub i64 %34, %35
%37 = trunc i64 %36 to i32
%38 = call i64 @strncmp(i8* %28, i64 %31, i32 %37)
%39 = icmp eq i64 0, %38
br i1 %39, label %40, label %78
40: ; preds = %19
%41 = load %struct.option*, %struct.option** %10
%42 = getelementptr inbounds %struct.option, %struct.option* %41, i32 0, i32 0
%43 = load i32, i32* %42
switch i32 %43, label %77 [
i32 130, label %44
i32 128, label %50
i32 129, label %66
]
44: ; preds = %40
%45 = load i8*, i8** %12
%46 = load i8, i8* %45
%47 = icmp ne i8 %46, 0
br i1 %47, label %49, label %48
48: ; preds = %44
store i8* null, i8** @optarg
store i32 1, i32* %5
br label %85
49: ; preds = %44
br label %77
50: ; preds = %40
%51 = load i8*, i8** %12
%52 = load i8, i8* %51
%53 = icmp ne i8 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = load i8*, i8** %12
%56 = getelementptr inbounds i8, i8* %55, i64 1
store i8* %56, i8** @optarg
store i32 1, i32* %5
br label %85
57: ; preds = %50
%58 = load i32, i32* %6
%59 = icmp sge i32 %58, 1
br i1 %59, label %60, label %64
60: ; preds = %57
%61 = load i8**, i8*** %7
%62 = getelementptr inbounds i8*, i8** %61, i64 1
%63 = load i8*, i8** %62
store i8* %63, i8** @optarg
store i32 2, i32* %5
br label %85
64: ; preds = %57
br label %65
65: ; preds = %64
br label %77
66: ; preds = %40
%67 = load i8*, i8** %12
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %66
%72 = load i8*, i8** %12
%73 = getelementptr inbounds i8, i8* %72, i64 1
br label %75
74: ; preds = %66
br label %75
75: ; preds = %74, %71
%76 = phi i8* [ %73, %71 ], [ null, %74 ]
store i8* %76, i8** @optarg
store i32 1, i32* %5
br label %85
77: ; preds = %40, %65, %49
br label %78
78: ; preds = %77, %19
br label %79
79: ; preds = %78
%80 = load %struct.option*, %struct.option** %10
%81 = getelementptr inbounds %struct.option, %struct.option* %80, i32 1
store %struct.option* %81, %struct.option** %10
br label %14
82: ; preds = %14
%83 = load i32, i32* @ENOENT
%84 = sub nsw i32 0, %83
store i32 %84, i32* %5
br label %85
85: ; preds = %82, %75, %60, %54, %48
%86 = load i32, i32* %5
ret i32 %86
}

LLVM IR (-O2):
%struct.option = type { i32, i64 }
@optarg = global i8* null
@ENOENT = global i32 0
define i32 @getopt_try_long(i32 %0, i8** nocapture %1, %struct.option* %2, %struct.option** nocapture writeonly %3) {
%5 = getelementptr inbounds %struct.option, %struct.option* %2, i64 0, i32 1
%6 = load i64, i64* %5
%7 = icmp eq i64 %6, 0
br i1 %7, label %49, label %8
8: ; preds = %4
%9 = icmp sgt i32 %0, 0
br label %10
10: ; preds = %8, %44
%11 = phi i64* [ %5, %8 ], [ %46, %44 ]
%12 = phi %struct.option* [ %2, %8 ], [ %45, %44 ]
%13 = load i8*, i8** %1
%14 = getelementptr inbounds i8, i8* %13, i64 2
%15 = tail call i8* @strchrnul(i8* %14, i8 signext 61)
store %struct.option* %12, %struct.option** %3
%16 = load i64, i64* %11
%17 = ptrtoint i8* %15 to i64
%18 = ptrtoint i8* %14 to i64
%19 = sub i64 %17, %18
%20 = trunc i64 %19 to i32
%21 = tail call i64 @strncmp(i8* %14, i64 %16, i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %44
23: ; preds = %10
%24 = getelementptr inbounds %struct.option, %struct.option* %12, i64 0, i32 0
%25 = load i32, i32* %24
switch i32 %25, label %44 [
i32 130, label %26
i32 128, label %30
i32 129, label %39
]
26: ; preds = %23
%27 = load i8, i8* %15
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %44
29: ; preds = %26
store i8* null, i8** @optarg
br label %52
30: ; preds = %23
%31 = load i8, i8* %15
%32 = icmp eq i8 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = getelementptr inbounds i8, i8* %15, i64 1
store i8* %34, i8** @optarg
br label %52
35: ; preds = %30
br i1 %9, label %36, label %44
36: ; preds = %35
%37 = getelementptr inbounds i8*, i8** %1, i64 1
%38 = load i8*, i8** %37
store i8* %38, i8** @optarg
br label %52
39: ; preds = %23
%40 = load i8, i8* %15
%41 = icmp eq i8 %40, 0
%42 = getelementptr inbounds i8, i8* %15, i64 1
%43 = select i1 %41, i8* null, i8* %42
store i8* %43, i8** @optarg
br label %52
44: ; preds = %23, %26, %35, %10
%45 = getelementptr inbounds %struct.option, %struct.option* %12, i64 1
%46 = getelementptr inbounds %struct.option, %struct.option* %12, i64 1, i32 1
%47 = load i64, i64* %46
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %10
49: ; preds = %44, %4
%50 = load i32, i32* @ENOENT
%51 = sub nsw i32 0, %50
br label %52
52: ; preds = %29, %33, %36, %39, %49
%53 = phi i32 [ %51, %49 ], [ 1, %39 ], [ 1, %33 ], [ 2, %36 ], [ 1, %29 ]
ret i32 %53
}