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

/* Variables and functions */
int EINVAL;
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 *, char *, int);
int getopt_try_long(int argl, char *const arg[], const struct option *longopts,
                    const struct option **out_lopt) {
  const struct option *lopt;
  if (strncmp(arg[0], "--", 2)) {
    return -EINVAL;
  }
  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    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xebb(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     116c <getopt_try_long+0x4c>
xor    %eax,%eax
mov    0x2e76(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1311 <getopt_try_long+0x1f1>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
je     1303 <getopt_try_long+0x1e3>
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    (%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    12ed <getopt_try_long+0x1cd>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x80,%eax
je     1245 <getopt_try_long+0x125>
jmp    11f3 <getopt_try_long+0xd3>
mov    -0x3c(%rbp),%eax
sub    $0x81,%eax
je     12a2 <getopt_try_long+0x182>
jmp    1206 <getopt_try_long+0xe6>
mov    -0x3c(%rbp),%eax
sub    $0x82,%eax
jne    12e8 <getopt_try_long+0x1c8>
jmp    1219 <getopt_try_long+0xf9>
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1240 <getopt_try_long+0x120>
mov    0x2dcb(%rip),%rax
movq   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1311 <getopt_try_long+0x1f1>
jmp    12e8 <getopt_try_long+0x1c8>
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
je     1270 <getopt_try_long+0x150>
mov    -0x38(%rbp),%rcx
add    $0x1,%rcx
mov    0x2d97(%rip),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1311 <getopt_try_long+0x1f1>
cmpl   $0x1,-0x8(%rbp)
jl     1298 <getopt_try_long+0x178>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    0x2d6f(%rip),%rax
mov    %rcx,(%rax)
movl   $0x2,-0x4(%rbp)
jmp    1311 <getopt_try_long+0x1f1>
jmp    129d <getopt_try_long+0x17d>
jmp    12e8 <getopt_try_long+0x1c8>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12c3 <getopt_try_long+0x1a3>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    12ce <getopt_try_long+0x1ae>
xor    %eax,%eax
mov    %rax,-0x48(%rbp)
jmp    12ce <getopt_try_long+0x1ae>
mov    -0x48(%rbp),%rcx
mov    0x2d1f(%rip),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1311 <getopt_try_long+0x1f1>
jmp    12ed <getopt_try_long+0x1cd>
jmp    12f2 <getopt_try_long+0x1d2>
mov    -0x28(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x28(%rbp)
jmp    1174 <getopt_try_long+0x54>
xor    %eax,%eax
mov    0x2cbc(%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
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %edi,%r12d
mov    (%rsi),%rdi
lea    0xebf(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1159 <getopt_try_long+0x39>
mov    0x2e81(%rip),%rcx
jmp    1166 <getopt_try_long+0x46>
cmpq   $0x0,(%rbx)
jne    118b <getopt_try_long+0x6b>
mov    0x2e62(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x81,%eax
je     11f8 <getopt_try_long+0xd8>
cmpq   $0x0,0x10(%rbx)
lea    0x10(%rbx),%rbx
je     115f <getopt_try_long+0x3f>
mov    (%r15),%rbp
add    $0x2,%rbp
mov    %rbp,%rdi
mov    $0x3d,%esi
call   1040 <strchrnul@plt>
mov    %rax,%r13
mov    %rbx,(%r14)
mov    (%rbx),%rsi
mov    %r13d,%edx
sub    %ebp,%edx
mov    %rbp,%rdi
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1180 <getopt_try_long+0x60>
mov    0x8(%rbx),%eax
cmp    $0x80,%eax
je     11d4 <getopt_try_long+0xb4>
cmp    $0x82,%eax
jne    1179 <getopt_try_long+0x59>
cmpb   $0x0,0x0(%r13)
jne    1180 <getopt_try_long+0x60>
jmp    121e <getopt_try_long+0xfe>
cmpb   $0x0,0x0(%r13)
jne    1236 <getopt_try_long+0x116>
test   %r12d,%r12d
jle    1180 <getopt_try_long+0x60>
mov    0x8(%r15),%rax
mov    0x2e0d(%rip),%rcx
mov    %rax,(%rcx)
mov    $0x2,%eax
jmp    116a <getopt_try_long+0x4a>
mov    %r13,%rax
add    $0x1,%rax
xor    %ecx,%ecx
cmpb   $0x0,0x0(%r13)
cmovne %rax,%rcx
mov    0x2de7(%rip),%rax
mov    %rcx,(%rax)
mov    $0x1,%eax
jmp    116a <getopt_try_long+0x4a>
mov    0x2dd3(%rip),%rax
movq   $0x0,(%rax)
mov    $0x1,%eax
jmp    116a <getopt_try_long+0x4a>
add    $0x1,%r13
mov    0x2db7(%rip),%rax
mov    %r13,(%rax)
mov    $0x1,%eax
jmp    116a <getopt_try_long+0x4a>

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

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