#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_so;
  size_t rm_eo;
};
typedef TYPE_1__ regmatch_t;
typedef int /*<<< orphan*/ regex_t;

/* Variables and functions */
int /*<<< orphan*/ bsd_strlcpy(char *, char *, size_t);
int /*<<< orphan*/ bzero(char *, size_t);
char *calloc(int, size_t);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ regexec(int /*<<< orphan*/ *, char *, int, TYPE_1__ *,
                   int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strdup(char *);
int strlen(char *);
int edge_parse_line(regex_t *rp, char *line, char **k, char **v) {
  regmatch_t mgroups[10];
  size_t len;
  char *copy;
  if (regexec(rp, line, 10, mgroups, 0)) {
    *k = *v = NULL;
    return (-1);
  }
  if (mgroups[3].rm_so != -1) {
    *k = *v = NULL;
    return (-1);
  }
  len = strlen(line) + 1;
  copy = calloc(1, len);
  if (copy == NULL) {
    (void)fprintf(stderr, "calloc failed\n");
    *k = *v = NULL;
    return (-1);
  }
  bsd_strlcpy(copy, line, len - 1);
  copy[mgroups[1].rm_eo] = '\0';
  *k = strdup(copy + mgroups[1].rm_so);
  bzero(copy, len);
  bsd_strlcpy(copy, line, len - 1);
  copy[mgroups[2].rm_eo] = '\0';
  *v = strdup(copy + mgroups[2].rm_so);
  free(copy);
  return (0);
}


x86 assembly (clang, -O0):
<edge_parse_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0xd0(%rbp),%rcx
mov    $0xa,%edx
xor    %r8d,%r8d
call   1070 <regexec@plt>
cmp    $0x0,%rax
je     11e3 <edge_parse_line+0x63>
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1344 <edge_parse_line+0x1c4>
cmpl   $0xffffffff,-0xa0(%rbp)
je     1212 <edge_parse_line+0x92>
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1344 <edge_parse_line+0x1c4>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0xd8(%rbp)
mov    -0xd8(%rbp),%rsi
mov    $0x1,%edi
call   1050 <calloc@plt>
mov    %rax,-0xe0(%rbp)
cmpq   $0x0,-0xe0(%rbp)
jne    1284 <edge_parse_line+0x104>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
lea    0xda3(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1344 <edge_parse_line+0x1c4>
mov    -0xe0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xd8(%rbp),%rdx
sub    $0x1,%rdx
call   1090 <bsd_strlcpy@plt>
mov    -0xe0(%rbp),%rax
mov    -0xb8(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xe0(%rbp),%rdi
movslq -0xc0(%rbp),%rax
add    %rax,%rdi
call   10a0 <strdup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0xe0(%rbp),%rdi
mov    -0xd8(%rbp),%rsi
call   1080 <bzero@plt>
mov    -0xe0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xd8(%rbp),%rdx
sub    $0x1,%rdx
call   1090 <bsd_strlcpy@plt>
mov    -0xe0(%rbp),%rax
mov    -0xa8(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xe0(%rbp),%rdi
movslq -0xb0(%rbp),%rax
add    %rax,%rdi
call   10a0 <strdup@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0xe0(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<edge_parse_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rsp,%rcx
mov    $0xa,%edx
xor    %r8d,%r8d
call   1070 <regexec@plt>
test   %rax,%rax
jne    11b6 <edge_parse_line+0x36>
cmpl   $0xffffffff,0x30(%rsp)
je     11db <edge_parse_line+0x5b>
movq   $0x0,(%r14)
movq   $0x0,(%r15)
mov    $0xffffffff,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
movslq %eax,%r13
mov    $0x1,%edi
mov    %r13,%rsi
call   1050 <calloc@plt>
test   %rax,%rax
je     126c <edge_parse_line+0xec>
mov    %rax,%r12
lea    -0x1(%r13),%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1090 <bsd_strlcpy@plt>
mov    0x18(%rsp),%rax
movb   $0x0,(%r12,%rax,1)
movslq 0x10(%rsp),%rdi
add    %r12,%rdi
call   10a0 <strdup@plt>
mov    %rax,(%r15)
mov    %r12,%rdi
mov    %r13,%rsi
call   1080 <bzero@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1090 <bsd_strlcpy@plt>
mov    0x28(%rsp),%rax
movb   $0x0,(%r12,%rax,1)
movslq 0x20(%rsp),%rdi
add    %r12,%rdi
call   10a0 <strdup@plt>
mov    %rax,(%r14)
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    11c9 <edge_parse_line+0x49>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
lea    0xd84(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11b6 <edge_parse_line+0x36>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i64 }
@stderr = global i32 0
@.str = [15 x i8] c"calloc failed\0A\00"
define i32 @edge_parse_line(i32* %0, i8* %1, i8** %2, i8** %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca i8**
%10 = alloca [10 x %struct.TYPE_3__]
%11 = alloca i64
%12 = alloca i8*
store i32* %0, i32** %6
store i8* %1, i8** %7
store i8** %2, i8*** %8
store i8** %3, i8*** %9
%13 = load i32*, i32** %6
%14 = load i8*, i8** %7
%15 = getelementptr inbounds [10 x %struct.TYPE_3__], [10 x %struct.TYPE_3__]* %10, i64 0, i64 0
%16 = call i64 @regexec(i32* %13, i8* %14, i32 10, %struct.TYPE_3__* %15, i32 0)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %4
%19 = load i8**, i8*** %9
store i8* null, i8** %19
%20 = load i8**, i8*** %8
store i8* null, i8** %20
store i32 -1, i32* %5
br label %85
21: ; preds = %4
%22 = getelementptr inbounds [10 x %struct.TYPE_3__], [10 x %struct.TYPE_3__]* %10, i64 0, i64 3
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = icmp ne i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i8**, i8*** %9
store i8* null, i8** %27
%28 = load i8**, i8*** %8
store i8* null, i8** %28
store i32 -1, i32* %5
br label %85
29: ; preds = %21
%30 = load i8*, i8** %7
%31 = call i32 @strlen(i8* %30)
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
store i64 %33, i64* %11
%34 = load i64, i64* %11
%35 = call i8* @calloc(i32 1, i64 %34)
store i8* %35, i8** %12
%36 = load i8*, i8** %12
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %43
38: ; preds = %29
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%41 = load i8**, i8*** %9
store i8* null, i8** %41
%42 = load i8**, i8*** %8
store i8* null, i8** %42
store i32 -1, i32* %5
br label %85
43: ; preds = %29
%44 = load i8*, i8** %12
%45 = load i8*, i8** %7
%46 = load i64, i64* %11
%47 = sub i64 %46, 1
%48 = call i32 @bsd_strlcpy(i8* %44, i8* %45, i64 %47)
%49 = load i8*, i8** %12
%50 = getelementptr inbounds [10 x %struct.TYPE_3__], [10 x %struct.TYPE_3__]* %10, i64 0, i64 1
%51 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %50, i32 0, i32 1
%52 = load i64, i64* %51
%53 = getelementptr inbounds i8, i8* %49, i64 %52
store i8 0, i8* %53
%54 = load i8*, i8** %12
%55 = getelementptr inbounds [10 x %struct.TYPE_3__], [10 x %struct.TYPE_3__]* %10, i64 0, i64 1
%56 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %55, i32 0, i32 0
%57 = load i32, i32* %56
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %54, i64 %58
%60 = call i8* @strdup(i8* %59)
%61 = load i8**, i8*** %8
store i8* %60, i8** %61
%62 = load i8*, i8** %12
%63 = load i64, i64* %11
%64 = call i32 @bzero(i8* %62, i64 %63)
%65 = load i8*, i8** %12
%66 = load i8*, i8** %7
%67 = load i64, i64* %11
%68 = sub i64 %67, 1
%69 = call i32 @bsd_strlcpy(i8* %65, i8* %66, i64 %68)
%70 = load i8*, i8** %12
%71 = getelementptr inbounds [10 x %struct.TYPE_3__], [10 x %struct.TYPE_3__]* %10, i64 0, i64 2
%72 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %71, i32 0, i32 1
%73 = load i64, i64* %72
%74 = getelementptr inbounds i8, i8* %70, i64 %73
store i8 0, i8* %74
%75 = load i8*, i8** %12
%76 = getelementptr inbounds [10 x %struct.TYPE_3__], [10 x %struct.TYPE_3__]* %10, i64 0, i64 2
%77 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %76, i32 0, i32 0
%78 = load i32, i32* %77
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %75, i64 %79
%81 = call i8* @strdup(i8* %80)
%82 = load i8**, i8*** %9
store i8* %81, i8** %82
%83 = load i8*, i8** %12
%84 = call i32 @free(i8* %83)
store i32 0, i32* %5
br label %85
85: ; preds = %43, %38, %26, %18
%86 = load i32, i32* %5
ret i32 %86
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i64 }
@stderr = global i32 0
@.str = [15 x i8] c"calloc failed\0A\00"
define i32 @edge_parse_line(i32* %0, i8* %1, i8** nocapture writeonly %2, i8** nocapture writeonly %3) {
%5 = alloca [10 x %struct.TYPE_3__]
%6 = bitcast [10 x %struct.TYPE_3__]* %5 to i8*
%7 = getelementptr inbounds [10 x %struct.TYPE_3__], [10 x %struct.TYPE_3__]* %5, i64 0, i64 0
%8 = call i64 @regexec(i32* %0, i8* %1, i32 10, %struct.TYPE_3__* %7, i32 0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %4
store i8* null, i8** %3
store i8* null, i8** %2
br label %47
11: ; preds = %4
%12 = getelementptr inbounds [10 x %struct.TYPE_3__], [10 x %struct.TYPE_3__]* %5, i64 0, i64 3, i32 0
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, -1
br i1 %14, label %16, label %15
15: ; preds = %11
store i8* null, i8** %3
store i8* null, i8** %2
br label %47
16: ; preds = %11
%17 = call i32 @strlen(i8* %1)
%18 = add nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = call i8* @calloc(i32 1, i64 %19)
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %3
store i8* null, i8** %2
br label %47
25: ; preds = %16
%26 = add nsw i64 %19, -1
%27 = call i32 @bsd_strlcpy(i8* %20, i8* %1, i64 %26)
%28 = getelementptr inbounds [10 x %struct.TYPE_3__], [10 x %struct.TYPE_3__]* %5, i64 0, i64 1, i32 1
%29 = load i64, i64* %28
%30 = getelementptr inbounds i8, i8* %20, i64 %29
store i8 0, i8* %30
%31 = getelementptr inbounds [10 x %struct.TYPE_3__], [10 x %struct.TYPE_3__]* %5, i64 0, i64 1, i32 0
%32 = load i32, i32* %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %20, i64 %33
%35 = call i8* @strdup(i8* %34)
store i8* %35, i8** %2
%36 = call i32 @bzero(i8* %20, i64 %19)
%37 = call i32 @bsd_strlcpy(i8* %20, i8* %1, i64 %26)
%38 = getelementptr inbounds [10 x %struct.TYPE_3__], [10 x %struct.TYPE_3__]* %5, i64 0, i64 2, i32 1
%39 = load i64, i64* %38
%40 = getelementptr inbounds i8, i8* %20, i64 %39
store i8 0, i8* %40
%41 = getelementptr inbounds [10 x %struct.TYPE_3__], [10 x %struct.TYPE_3__]* %5, i64 0, i64 2, i32 0
%42 = load i32, i32* %41
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %20, i64 %43
%45 = call i8* @strdup(i8* %44)
store i8* %45, i8** %3
%46 = call i32 @free(i8* %20)
br label %47
47: ; preds = %25, %22, %15, %10
%48 = phi i32 [ -1, %10 ], [ -1, %15 ], [ -1, %22 ], [ 0, %25 ]
ret i32 %48
}