#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 */

/* Variables and functions */
int /*<<< orphan*/ add_longopt(char *, int);
int no_argument;
int optional_argument;
int /*<<< orphan*/ parse_error(char *);
int required_argument;
int strlen(char *);
char *strtok(char *, char *);
void add_long_options(char *options) {
  int arg_opt;
  char *tokptr = strtok(options, ", \t\n");
  while (tokptr) {
    arg_opt = no_argument;
    if (strlen(tokptr) > 0) {
      if (tokptr[strlen(tokptr) - 1] == ':') {
        if (tokptr[strlen(tokptr) - 2] == ':') {
          tokptr[strlen(tokptr) - 2] = '\0';
          arg_opt = optional_argument;
        } else {
          tokptr[strlen(tokptr) - 1] = '\0';
          arg_opt = required_argument;
        }
        if (strlen(tokptr) == 0)
          parse_error("empty long option after "
                      "-l or --long argument");
      }
      add_longopt(tokptr, arg_opt);
    }
    tokptr = strtok(NULL, ", \t\n");
  }
}


x86 assembly (clang, -O0):
<add_long_options>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1284 <add_long_options+0x144>
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jle    126b <add_long_options+0x12b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    125f <add_long_options+0x11f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    120f <add_long_options+0xcf>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    0x2de3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
jmp    123c <add_long_options+0xfc>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jne    125a <add_long_options+0x11a>
lea    0xdb0(%rip),%rdi
call   1060 <parse_error@plt>
jmp    125f <add_long_options+0x11f>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <add_longopt@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd8a(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    1160 <add_long_options+0x20>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_long_options>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeae(%rip),%rsi
call   1050 <strtok@plt>
test   %rax,%rax
je     1225 <add_long_options+0xe5>
mov    %rax,%rbx
mov    0x2e66(%rip),%r12
mov    0x2e6f(%rip),%r13
mov    0x2e70(%rip),%r14
lea    0xe81(%rip),%r15
jmp    11c8 <add_long_options+0x88>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %sil,%cl
not    %ecx
add    %eax,%ecx
movslq %ecx,%rax
movb   $0x0,(%rbx,%rax,1)
mov    (%rdx),%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     1217 <add_long_options+0xd7>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <add_longopt@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1225 <add_long_options+0xe5>
mov    (%r12),%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11b6 <add_long_options+0x76>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x3a,-0x1(%rax,%rbx,1)
jne    11ac <add_long_options+0x6c>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movzbl -0x2(%rax,%rbx,1),%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
xor    %ecx,%ecx
mov    %r13,%rdx
cmp    $0x3a,%bpl
sete   %sil
jne    1190 <add_long_options+0x50>
mov    %r14,%rdx
jmp    1190 <add_long_options+0x50>
lea    0xde7(%rip),%rdi
call   1060 <parse_error@plt>
jmp    11ac <add_long_options+0x6c>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c", \09\0A\00"
@no_argument = global i32 0
@optional_argument = global i32 0
@required_argument = global i32 0
@.str.1 = [46 x i8] c"empty long option after -l or --long argument\00"
define void @add_long_options(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i8* @strtok(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %4
br label %7
7: ; preds = %62, %1
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %64
10: ; preds = %7
%11 = load i32, i32* @no_argument
store i32 %11, i32* %3
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* %12)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %62
15: ; preds = %10
%16 = load i8*, i8** %4
%17 = load i8*, i8** %4
%18 = call i32 @strlen(i8* %17)
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %16, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 58
br i1 %24, label %25, label %58
25: ; preds = %15
%26 = load i8*, i8** %4
%27 = load i8*, i8** %4
%28 = call i32 @strlen(i8* %27)
%29 = sub nsw i32 %28, 2
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %26, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 58
br i1 %34, label %35, label %43
35: ; preds = %25
%36 = load i8*, i8** %4
%37 = load i8*, i8** %4
%38 = call i32 @strlen(i8* %37)
%39 = sub nsw i32 %38, 2
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %36, i64 %40
store i8 0, i8* %41
%42 = load i32, i32* @optional_argument
store i32 %42, i32* %3
br label %51
43: ; preds = %25
%44 = load i8*, i8** %4
%45 = load i8*, i8** %4
%46 = call i32 @strlen(i8* %45)
%47 = sub nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %44, i64 %48
store i8 0, i8* %49
%50 = load i32, i32* @required_argument
store i32 %50, i32* %3
br label %51
51: ; preds = %43, %35
%52 = load i8*, i8** %4
%53 = call i32 @strlen(i8* %52)
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %51
%56 = call i32 @parse_error(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
br label %57
57: ; preds = %55, %51
br label %58
58: ; preds = %57, %15
%59 = load i8*, i8** %4
%60 = load i32, i32* %3
%61 = call i32 @add_longopt(i8* %59, i32 %60)
br label %62
62: ; preds = %58, %10
%63 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %63, i8** %4
br label %7
64: ; preds = %7
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c", \09\0A\00"
@no_argument = global i32 0
@optional_argument = global i32 0
@required_argument = global i32 0
@.str.1 = [46 x i8] c"empty long option after -l or --long argument\00"
define void @add_long_options(i8* %0) {
%2 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %41, label %4
4: ; preds = %1, %38
%5 = phi i8* [ %39, %38 ], [ %2, %1 ]
%6 = load i32, i32* @no_argument
%7 = tail call i32 @strlen(i8* %5)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %38
9: ; preds = %4
%10 = tail call i32 @strlen(i8* %5)
%11 = add nsw i32 %10, -1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %5, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 58
br i1 %15, label %16, label %35
16: ; preds = %9
%17 = tail call i32 @strlen(i8* %5)
%18 = add nsw i32 %17, -2
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %5, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 58
%23 = tail call i32 @strlen(i8* %5)
%24 = select i1 %22, i32 -2, i32 -1
%25 = add nsw i32 %23, %24
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %5, i64 %26
store i8 0, i8* %27
%28 = load i32, i32* @optional_argument
%29 = load i32, i32* @required_argument
%30 = select i1 %22, i32 %28, i32 %29
%31 = tail call i32 @strlen(i8* %5)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %16
%34 = tail call i32 @parse_error(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %16, %33, %9
%36 = phi i32 [ %30, %33 ], [ %30, %16 ], [ %6, %9 ]
%37 = tail call i32 @add_longopt(i8* %5, i32 %36)
br label %38
38: ; preds = %35, %4
%39 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %4
41: ; preds = %38, %1
ret void
}