#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 spec_params {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
scalar_t__ spec_param_parse(struct spec_params *, char *, char *);
int strcspn(char *, char const *);
char *strdup(char const *);
char *strsep(char **, char const *);
const char *spec_params_parse(struct spec_params *p, const char *options,
                              const char *key_val_sep, const char *pairs_sep) {
  const char *errindex = NULL;
  char *key, *buf = strdup(options), *string = buf;
  while ((key = strsep(&string, pairs_sep))) {
    if (!*key)
      continue;
    char *val = key + strcspn(key, key_val_sep);
    if (*val)
      *val++ = '\0';
    if (spec_param_parse(p, key, val))
      break;
  }
  if (key)
    errindex = options + (key - buf);
  free(buf);
  return errindex;
}


x86 assembly (clang, -O0):
<spec_params_parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rsi
lea    -0x40(%rbp),%rdi
call   1050 <strsep@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     121b <spec_params_parse+0xcb>
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11b2 <spec_params_parse+0x62>
jmp    1185 <spec_params_parse+0x35>
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcspn@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmpb   $0x0,(%rax)
je     11f6 <spec_params_parse+0xa6>
mov    -0x48(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x48(%rbp)
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x48(%rbp),%rdx
call   1060 <spec_param_parse@plt>
cmp    $0x0,%rax
je     1216 <spec_params_parse+0xc6>
jmp    121b <spec_params_parse+0xcb>
jmp    1185 <spec_params_parse+0x35>
cmpq   $0x0,-0x30(%rbp)
je     123c <spec_params_parse+0xec>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%rdx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spec_params_parse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r13
mov    %rsi,%rdi
call   1070 <strdup@plt>
mov    %rax,%r15
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   1050 <strsep@plt>
test   %rax,%rax
je     11ea <spec_params_parse+0x9a>
mov    %rax,%rbp
mov    %r14,0x10(%rsp)
lea    0x8(%rsp),%r14
jmp    11c3 <spec_params_parse+0x73>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbp,%rsi
call   1060 <spec_param_parse@plt>
test   %rax,%rax
jne    11ee <spec_params_parse+0x9e>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <strsep@plt>
mov    %rax,%rbp
test   %rax,%rax
je     11ea <spec_params_parse+0x9a>
cmpb   $0x0,0x0(%rbp)
je     11b0 <spec_params_parse+0x60>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1040 <strcspn@plt>
cltq
lea    (%rax,%rbp,1),%rdx
cmpb   $0x0,0x0(%rbp,%rax,1)
je     11a0 <spec_params_parse+0x50>
movb   $0x0,(%rdx)
add    $0x1,%rdx
jmp    11a0 <spec_params_parse+0x50>
xor    %ebx,%ebx
jmp    11f9 <spec_params_parse+0xa9>
sub    %r15,%rbp
mov    0x10(%rsp),%rbx
add    %rbp,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.spec_params = type { i32 }
define i8* @spec_params_parse(%struct.spec_params* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca %struct.spec_params*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
store %struct.spec_params* %0, %struct.spec_params** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store i8* null, i8** %9
%14 = load i8*, i8** %6
%15 = call i8* @strdup(i8* %14)
store i8* %15, i8** %11
%16 = load i8*, i8** %11
store i8* %16, i8** %12
br label %17
17: ; preds = %46, %25, %4
%18 = load i8*, i8** %8
%19 = call i8* @strsep(i8** %12, i8* %18)
store i8* %19, i8** %10
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %47
21: ; preds = %17
%22 = load i8*, i8** %10
%23 = load i8, i8* %22
%24 = icmp ne i8 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %21
br label %17
26: ; preds = %21
%27 = load i8*, i8** %10
%28 = load i8*, i8** %10
%29 = load i8*, i8** %7
%30 = call i32 @strcspn(i8* %28, i8* %29)
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %27, i64 %31
store i8* %32, i8** %13
%33 = load i8*, i8** %13
%34 = load i8, i8* %33
%35 = icmp ne i8 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %26
%37 = load i8*, i8** %13
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %13
store i8 0, i8* %37
br label %39
39: ; preds = %36, %26
%40 = load %struct.spec_params*, %struct.spec_params** %5
%41 = load i8*, i8** %10
%42 = load i8*, i8** %13
%43 = call i64 @spec_param_parse(%struct.spec_params* %40, i8* %41, i8* %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %39
br label %47
46: ; preds = %39
br label %17
47: ; preds = %45, %17
%48 = load i8*, i8** %10
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %58
50: ; preds = %47
%51 = load i8*, i8** %6
%52 = load i8*, i8** %10
%53 = load i8*, i8** %11
%54 = ptrtoint i8* %52 to i64
%55 = ptrtoint i8* %53 to i64
%56 = sub i64 %54, %55
%57 = getelementptr inbounds i8, i8* %51, i64 %56
store i8* %57, i8** %9
br label %58
58: ; preds = %50, %47
%59 = load i8*, i8** %11
%60 = call i32 @free(i8* %59)
%61 = load i8*, i8** %9
ret i8* %61
}

LLVM IR (-O2):
%struct.spec_params = type { i32 }
define i8* @spec_params_parse(%struct.spec_params* %0, i8* %1, i8* nocapture %2, i8* %3) {
%5 = alloca i8*
%6 = tail call i8* @strdup(i8* %1)
%7 = bitcast i8** %5 to i8*
store i8* %6, i8** %5
%8 = call i8* @strsep(i8** %5, i8* %3)
%9 = icmp eq i8* %8, null
br i1 %9, label %34, label %10
10: ; preds = %4, %14
%11 = phi i8* [ %15, %14 ], [ %8, %4 ]
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10, %25
%15 = call i8* @strsep(i8** %5, i8* %3)
%16 = icmp eq i8* %15, null
br i1 %16, label %34, label %10
17: ; preds = %10
%18 = call i32 @strcspn(i8* %11, i8* %2)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %11, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %17
%24 = getelementptr inbounds i8, i8* %20, i64 1
store i8 0, i8* %20
br label %25
25: ; preds = %23, %17
%26 = phi i8* [ %24, %23 ], [ %20, %17 ]
%27 = call i64 @spec_param_parse(%struct.spec_params* %0, i8* %11, i8* %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %14, label %29
29: ; preds = %25
%30 = ptrtoint i8* %11 to i64
%31 = ptrtoint i8* %6 to i64
%32 = sub i64 %30, %31
%33 = getelementptr inbounds i8, i8* %1, i64 %32
br label %34
34: ; preds = %14, %4, %29
%35 = phi i8* [ %33, %29 ], [ null, %4 ], [ null, %14 ]
%36 = call i32 @free(i8* %6)
ret i8* %35
}