#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 */
scalar_t__ isvalidkey(char *);
char *strchr(char *, char);
int /*<<< orphan*/ transformkey(char *);
char *trim(char *);
int parsemetadata(char *line, char **key, char **value) {
  char *colon;
  colon = strchr(line, ':');
  if (colon && isvalidkey(line)) {
    *colon = '\0';
    *value = trim(colon + 1);
    transformkey(line);
    *key = line;
    return 0;
  }
  colon = trim(line);
  if (*colon != '\0') {
    *key = NULL;
    *value = colon;
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<parsemetadata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11c2 <parsemetadata+0x82>
mov    -0x10(%rbp),%rdi
call   1050 <isvalidkey@plt>
cmp    $0x0,%rax
je     11c2 <parsemetadata+0x82>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1040 <trim@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
call   1060 <transformkey@plt>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1208 <parsemetadata+0xc8>
mov    -0x10(%rbp),%rdi
call   1040 <trim@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1201 <parsemetadata+0xc1>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1208 <parsemetadata+0xc8>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parsemetadata>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     118f <parsemetadata+0x4f>
mov    %rax,%rbx
mov    %r12,%rdi
call   1050 <isvalidkey@plt>
test   %rax,%rax
je     118f <parsemetadata+0x4f>
movb   $0x0,(%rbx)
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <trim@plt>
mov    %rax,(%r15)
mov    %r12,%rdi
call   1060 <transformkey@plt>
mov    %r12,(%r14)
jmp    11a6 <parsemetadata+0x66>
mov    %r12,%rdi
call   1040 <trim@plt>
cmpb   $0x0,(%rax)
je     11aa <parsemetadata+0x6a>
movq   $0x0,(%r14)
mov    %rax,(%r15)
xor    %eax,%eax
jmp    11af <parsemetadata+0x6f>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @parsemetadata(i8* %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%9 = load i8*, i8** %5
%10 = call i8* @strchr(i8* %9, i8 signext 58)
store i8* %10, i8** %8
%11 = load i8*, i8** %8
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %27
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = call i64 @isvalidkey(i8* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %27
17: ; preds = %13
%18 = load i8*, i8** %8
store i8 0, i8* %18
%19 = load i8*, i8** %8
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = call i8* @trim(i8* %20)
%22 = load i8**, i8*** %7
store i8* %21, i8** %22
%23 = load i8*, i8** %5
%24 = call i32 @transformkey(i8* %23)
%25 = load i8*, i8** %5
%26 = load i8**, i8*** %6
store i8* %25, i8** %26
store i32 0, i32* %4
br label %39
27: ; preds = %13, %3
%28 = load i8*, i8** %5
%29 = call i8* @trim(i8* %28)
store i8* %29, i8** %8
%30 = load i8*, i8** %8
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %27
%35 = load i8**, i8*** %6
store i8* null, i8** %35
%36 = load i8*, i8** %8
%37 = load i8**, i8*** %7
store i8* %36, i8** %37
store i32 0, i32* %4
br label %39
38: ; preds = %27
store i32 1, i32* %4
br label %39
39: ; preds = %38, %34, %17
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
define i32 @parsemetadata(i8* %0, i8** nocapture writeonly %1, i8** nocapture writeonly %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%5 = icmp eq i8* %4, null
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = tail call i64 @isvalidkey(i8* %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %6
store i8 0, i8* %4
%10 = getelementptr inbounds i8, i8* %4, i64 1
%11 = tail call i8* @trim(i8* %10)
store i8* %11, i8** %2
%12 = tail call i32 @transformkey(i8* %0)
store i8* %0, i8** %1
br label %18
13: ; preds = %6, %3
%14 = tail call i8* @trim(i8* %0)
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %13
store i8* null, i8** %1
store i8* %14, i8** %2
br label %18
18: ; preds = %13, %17, %9
%19 = phi i32 [ 0, %9 ], [ 0, %17 ], [ 1, %13 ]
ret i32 %19
}