#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int rm_eo;
  int rm_so;
};
typedef TYPE_1__ regmatch_t;
typedef int /*<<< orphan*/ regex_t;

/* Variables and functions */
int /*<<< orphan*/ REG_EXTENDED;
int REG_NOMATCH;
int /*<<< orphan*/ bee_fnprint(int /*<<< orphan*/, int, char *);
int bee_regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ ferror(int /*<<< orphan*/);
int /*<<< orphan*/ print_escaped(char *, int);
int regexec(int /*<<< orphan*/ *, char *, int, TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int strlen(char *);
int /*<<< orphan*/ warnx(char *, char *);
short do_separation(char *str) {
  int res = 0;
  int r;
  int start, end;
  char *key, *value;
  int keylen, vallen;
  regex_t regex_first;
  regex_t regex_next;
  regmatch_t pmatch;
  r = bee_regcomp(&regex_first, "^[[:alnum:]]+=", REG_EXTENDED);
  if (!r)
    return 0;
  r = bee_regcomp(&regex_next, ":[[:alnum:]]+=", REG_EXTENDED);
  if (!r)
    goto out_first;
  r = regexec(&regex_first, str, 1, &pmatch, 0);
  if (r == REG_NOMATCH) {
    warnx("String '%s' does not start with a key\n", str);
    goto out;
  }
  end = pmatch.rm_eo;
  key = str;
  value = str + end;
  str = value;
  while (regexec(&regex_next, str, 1, &pmatch, 0) != REG_NOMATCH) {
    start = pmatch.rm_so;
    end = pmatch.rm_eo;
    keylen = value - key - 1;
    vallen = start;
    bee_fnprint(stdout, keylen + 1, key);
    print_escaped(value, vallen);
    key = str + start + 1;
    value = str + end;
    str = value;
  }
  keylen = value - key - 1;
  bee_fnprint(stdout, keylen + 1, key);
  print_escaped(value, strlen(value));
  res = !ferror(stdout);
out:
  regfree(&regex_next);
out_first:
  regfree(&regex_first);
  return res;
}


x86 assembly (clang, -O0):
<do_separation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
lea    -0x3c(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1090 <bee_regcomp@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11c4 <do_separation+0x44>
movw   $0x0,-0x2(%rbp)
jmp    1373 <do_separation+0x1f3>
mov    0x2e05(%rip),%rax
mov    (%rax),%edx
lea    -0x40(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1090 <bee_regcomp@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11ef <do_separation+0x6f>
jmp    1363 <do_separation+0x1e3>
mov    -0x10(%rbp),%rsi
lea    -0x3c(%rbp),%rdi
mov    $0x1,%edx
lea    -0x48(%rbp),%rcx
xor    %r8d,%r8d
call   1080 <regexec@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2dd3(%rip),%rcx
cmp    (%rcx),%eax
jne    1232 <do_separation+0xb2>
mov    -0x10(%rbp),%rsi
lea    0xdf6(%rip),%rdi
call   1070 <warnx@plt>
jmp    135a <do_separation+0x1da>
mov    -0x48(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x40(%rbp),%rdi
mov    $0x1,%edx
lea    -0x48(%rbp),%rcx
xor    %r8d,%r8d
call   1080 <regexec@plt>
mov    0x2d71(%rip),%rcx
cmp    (%rcx),%eax
je     12f6 <do_separation+0x176>
mov    -0x44(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
mov    -0x34(%rbp),%esi
add    $0x1,%esi
mov    -0x28(%rbp),%rdx
call   1060 <bee_fnprint@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%esi
call   10a0 <print_escaped@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1257 <do_separation+0xd7>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,-0x34(%rbp)
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
mov    -0x34(%rbp),%esi
add    $0x1,%esi
mov    -0x28(%rbp),%rdx
call   1060 <bee_fnprint@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
call   10a0 <print_escaped@plt>
mov    0x2c95(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
call   1040 <regfree@plt>
lea    -0x3c(%rbp),%rdi
call   1040 <regfree@plt>
mov    -0x14(%rbp),%eax
mov    %ax,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_separation>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
mov    0x2e38(%rip),%rbx
mov    (%rbx),%edx
lea    0xe5f(%rip),%rsi
lea    0x14(%rsp),%rdi
call   1090 <bee_regcomp@plt>
test   %eax,%eax
je     1202 <do_separation+0x82>
mov    (%rbx),%edx
lea    0xe57(%rip),%rsi
lea    0x4(%rsp),%rdi
call   1090 <bee_regcomp@plt>
test   %eax,%eax
je     1209 <do_separation+0x89>
lea    0x14(%rsp),%rdi
lea    0x8(%rsp),%rcx
mov    %r14,%rsi
mov    $0x1,%edx
xor    %r8d,%r8d
call   1080 <regexec@plt>
mov    0x2e01(%rip),%rbp
cmp    0x0(%rbp),%eax
jne    1210 <do_separation+0x90>
lea    0xe2b(%rip),%rdi
mov    %r14,%rsi
call   1070 <warnx@plt>
xor    %ebx,%ebx
jmp    12cb <do_separation+0x14b>
xor    %ebx,%ebx
jmp    12df <do_separation+0x15f>
xor    %ebx,%ebx
jmp    12d5 <do_separation+0x155>
movslq 0x8(%rsp),%rbx
add    %r14,%rbx
lea    0x4(%rsp),%rdi
lea    0x8(%rsp),%rcx
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %r8d,%r8d
call   1080 <regexec@plt>
cmp    0x0(%rbp),%eax
je     1293 <do_separation+0x113>
lea    0x8(%rsp),%r12
nopl   0x0(%rax)
movslq 0xc(%rsp),%r13
movslq 0x8(%rsp),%r15
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
mov    %ebx,%esi
sub    %r14d,%esi
mov    %r14,%rdx
call   1060 <bee_fnprint@plt>
mov    %rbx,%rdi
mov    %r13d,%esi
call   10a0 <print_escaped@plt>
lea    (%rbx,%r13,1),%r14
add    $0x1,%r14
add    %r15,%rbx
lea    0x4(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    %r12,%rcx
xor    %r8d,%r8d
call   1080 <regexec@plt>
cmp    0x0(%rbp),%eax
jne    1240 <do_separation+0xc0>
mov    0x2d3e(%rip),%rbp
mov    0x0(%rbp),%edi
mov    %ebx,%esi
sub    %r14d,%esi
mov    %r14,%rdx
call   1060 <bee_fnprint@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   10a0 <print_escaped@plt>
mov    0x0(%rbp),%edi
call   1030 <ferror@plt>
xor    %ebx,%ebx
test   %eax,%eax
sete   %bl
lea    0x4(%rsp),%rdi
call   1040 <regfree@plt>
lea    0x14(%rsp),%rdi
call   1040 <regfree@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
@.str = [15 x i8] c"^[[:alnum:]]+=\00"
@REG_EXTENDED = global i32 0
@.str.1 = [15 x i8] c":[[:alnum:]]+=\00"
@REG_NOMATCH = global i32 0
@.str.2 = [39 x i8] c"String '%s' does not start with a key\0A\00"
@stdout = global i32 0
define signext i16 @do_separation(i8* %0) {
%2 = alloca i16
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.TYPE_3__
store i8* %0, i8** %3
store i32 0, i32* %4
%15 = load i32, i32* @REG_EXTENDED
%16 = call i32 @bee_regcomp(i32* %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = icmp ne i32 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %1
store i16 0, i16* %2
br label %108
20: ; preds = %1
%21 = load i32, i32* @REG_EXTENDED
%22 = call i32 @bee_regcomp(i32* %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %21)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %20
br label %104
26: ; preds = %20
%27 = load i8*, i8** %3
%28 = call i32 @regexec(i32* %12, i8* %27, i32 1, %struct.TYPE_3__* %14, i32 0)
store i32 %28, i32* %5
%29 = load i32, i32* %5
%30 = load i32, i32* @REG_NOMATCH
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = load i8*, i8** %3
%34 = call i32 @warnx(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %33)
br label %102
35: ; preds = %26
%36 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %14, i32 0, i32 0
%37 = load i32, i32* %36
store i32 %37, i32* %7
%38 = load i8*, i8** %3
store i8* %38, i8** %8
%39 = load i8*, i8** %3
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8* %42, i8** %9
%43 = load i8*, i8** %9
store i8* %43, i8** %3
br label %44
44: ; preds = %49, %35
%45 = load i8*, i8** %3
%46 = call i32 @regexec(i32* %13, i8* %45, i32 1, %struct.TYPE_3__* %14, i32 0)
%47 = load i32, i32* @REG_NOMATCH
%48 = icmp ne i32 %46, %47
br i1 %48, label %49, label %80
49: ; preds = %44
%50 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %14, i32 0, i32 1
%51 = load i32, i32* %50
store i32 %51, i32* %6
%52 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %14, i32 0, i32 0
%53 = load i32, i32* %52
store i32 %53, i32* %7
%54 = load i8*, i8** %9
%55 = load i8*, i8** %8
%56 = ptrtoint i8* %54 to i64
%57 = ptrtoint i8* %55 to i64
%58 = sub i64 %56, %57
%59 = sub nsw i64 %58, 1
%60 = trunc i64 %59 to i32
store i32 %60, i32* %10
%61 = load i32, i32* %6
store i32 %61, i32* %11
%62 = load i32, i32* @stdout
%63 = load i32, i32* %10
%64 = add nsw i32 %63, 1
%65 = load i8*, i8** %8
%66 = call i32 @bee_fnprint(i32 %62, i32 %64, i8* %65)
%67 = load i8*, i8** %9
%68 = load i32, i32* %11
%69 = call i32 @print_escaped(i8* %67, i32 %68)
%70 = load i8*, i8** %3
%71 = load i32, i32* %6
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %70, i64 %72
%74 = getelementptr inbounds i8, i8* %73, i64 1
store i8* %74, i8** %8
%75 = load i8*, i8** %3
%76 = load i32, i32* %7
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %75, i64 %77
store i8* %78, i8** %9
%79 = load i8*, i8** %9
store i8* %79, i8** %3
br label %44
80: ; preds = %44
%81 = load i8*, i8** %9
%82 = load i8*, i8** %8
%83 = ptrtoint i8* %81 to i64
%84 = ptrtoint i8* %82 to i64
%85 = sub i64 %83, %84
%86 = sub nsw i64 %85, 1
%87 = trunc i64 %86 to i32
store i32 %87, i32* %10
%88 = load i32, i32* @stdout
%89 = load i32, i32* %10
%90 = add nsw i32 %89, 1
%91 = load i8*, i8** %8
%92 = call i32 @bee_fnprint(i32 %88, i32 %90, i8* %91)
%93 = load i8*, i8** %9
%94 = load i8*, i8** %9
%95 = call i32 @strlen(i8* %94)
%96 = call i32 @print_escaped(i8* %93, i32 %95)
%97 = load i32, i32* @stdout
%98 = call i32 @ferror(i32 %97)
%99 = icmp ne i32 %98, 0
%100 = xor i1 %99, true
%101 = zext i1 %100 to i32
store i32 %101, i32* %4
br label %102
102: ; preds = %80, %32
%103 = call i32 @regfree(i32* %13)
br label %104
104: ; preds = %102, %25
%105 = call i32 @regfree(i32* %12)
%106 = load i32, i32* %4
%107 = trunc i32 %106 to i16
store i16 %107, i16* %2
br label %108
108: ; preds = %104, %19
%109 = load i16, i16* %2
ret i16 %109
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
@.str = [15 x i8] c"^[[:alnum:]]+=\00"
@REG_EXTENDED = global i32 0
@.str.1 = [15 x i8] c":[[:alnum:]]+=\00"
@REG_NOMATCH = global i32 0
@.str.2 = [39 x i8] c"String '%s' does not start with a key\0A\00"
@stdout = global i32 0
define signext i16 @do_separation(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.TYPE_3__
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = bitcast %struct.TYPE_3__* %4 to i8*
%8 = load i32, i32* @REG_EXTENDED
%9 = call i32 @bee_regcomp(i32* %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %76, label %11
11: ; preds = %1
%12 = load i32, i32* @REG_EXTENDED
%13 = call i32 @bee_regcomp(i32* %3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %73, label %15
15: ; preds = %11
%16 = call i32 @regexec(i32* %2, i8* %0, i32 1, %struct.TYPE_3__* %4, i32 0)
%17 = load i32, i32* @REG_NOMATCH
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @warnx(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %70
21: ; preds = %15
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i64 0, i32 0
%23 = load i32, i32* %22
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %0, i64 %24
%26 = call i32 @regexec(i32* %3, i8* %25, i32 1, %struct.TYPE_3__* %4, i32 0)
%27 = load i32, i32* @REG_NOMATCH
%28 = icmp eq i32 %26, %27
br i1 %28, label %53, label %29
29: ; preds = %21
%30 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i64 0, i32 1
br label %31
31: ; preds = %29, %31
%32 = phi i8* [ %25, %29 ], [ %49, %31 ]
%33 = phi i8* [ %0, %29 ], [ %47, %31 ]
%34 = load i32, i32* %30
%35 = load i32, i32* %22
%36 = ptrtoint i8* %32 to i64
%37 = ptrtoint i8* %33 to i64
%38 = xor i64 %37, -1
%39 = add i64 %36, %38
%40 = trunc i64 %39 to i32
%41 = load i32, i32* @stdout
%42 = add nsw i32 %40, 1
%43 = call i32 @bee_fnprint(i32 %41, i32 %42, i8* %33)
%44 = call i32 @print_escaped(i8* %32, i32 %34)
%45 = sext i32 %34 to i64
%46 = getelementptr inbounds i8, i8* %32, i64 1
%47 = getelementptr inbounds i8, i8* %46, i64 %45
%48 = sext i32 %35 to i64
%49 = getelementptr inbounds i8, i8* %32, i64 %48
%50 = call i32 @regexec(i32* %3, i8* %49, i32 1, %struct.TYPE_3__* %4, i32 0)
%51 = load i32, i32* @REG_NOMATCH
%52 = icmp eq i32 %50, %51
br i1 %52, label %53, label %31
53: ; preds = %31, %21
%54 = phi i8* [ %0, %21 ], [ %47, %31 ]
%55 = phi i8* [ %25, %21 ], [ %49, %31 ]
%56 = ptrtoint i8* %55 to i64
%57 = ptrtoint i8* %54 to i64
%58 = xor i64 %57, -1
%59 = add i64 %56, %58
%60 = trunc i64 %59 to i32
%61 = load i32, i32* @stdout
%62 = add nsw i32 %60, 1
%63 = call i32 @bee_fnprint(i32 %61, i32 %62, i8* %54)
%64 = call i32 @strlen(i8* %55)
%65 = call i32 @print_escaped(i8* %55, i32 %64)
%66 = load i32, i32* @stdout
%67 = call i32 @ferror(i32 %66)
%68 = icmp eq i32 %67, 0
%69 = zext i1 %68 to i16
br label %70
70: ; preds = %53, %19
%71 = phi i16 [ 0, %19 ], [ %69, %53 ]
%72 = call i32 @regfree(i32* %3)
br label %73
73: ; preds = %11, %70
%74 = phi i16 [ %71, %70 ], [ 0, %11 ]
%75 = call i32 @regfree(i32* %2)
br label %76
76: ; preds = %1, %73
%77 = phi i16 [ %74, %73 ], [ 0, %1 ]
ret i16 %77
}