#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 */
typedef int wchar_t;

/* Variables and functions */
int /*<<< orphan*/ extract_name(int **, int **);
int *malloc(int);
int mywcscspn(int const *, char *, int);
int *unquote(int const *, int);
int /*<<< orphan*/ wmemcpy(int *, int const *, int);
int read_kv(const wchar_t **text, wchar_t **key, wchar_t **name,
            wchar_t **value) {
  int len_k = mywcscspn(*text, L" \t\r\n:{}", 0x01 | 0x02);
  if ((*text)[len_k] != L':' || len_k == 0)
    return 0;
  *key = malloc((len_k + 1) * sizeof(wchar_t));
  wmemcpy(*key, *text, len_k);
  (*key)[len_k] = 0;
  *text += len_k + 1;
  extract_name(key, name);
  int qval_len = mywcscspn(*text, L" \t\r\n{}", 0x01);
  *value = unquote(*text, qval_len);
  *text += qval_len;
  return 1;
}


x86 assembly (clang, -O0):
<read_kv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe8a(%rip),%rsi
mov    $0x3,%edx
call   1030 <mywcscspn@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x2c(%rbp),%rcx
cmpl   $0x3a,(%rax,%rcx,4)
jne    11a2 <read_kv+0x52>
cmpl   $0x0,-0x2c(%rbp)
jne    11ae <read_kv+0x5e>
movl   $0x0,-0x4(%rbp)
jmp    126c <read_kv+0x11c>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x2c(%rbp),%edx
call   1040 <wmemcpy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x2c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x2c(%rbp),%edx
add    $0x1,%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
movslq %edx,%rdx
shl    $0x2,%rdx
add    %rdx,%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <extract_name@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xdf8(%rip),%rsi
mov    $0x1,%edx
call   1030 <mywcscspn@plt>
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%esi
call   1050 <unquote@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
movslq %edx,%rdx
shl    $0x2,%rdx
add    %rdx,%rcx
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_kv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
mov    (%rdi),%rdi
lea    0xe8f(%rip),%rsi
mov    $0x3,%edx
call   1030 <mywcscspn@plt>
mov    (%rbx),%rcx
movslq %eax,%rbp
xor    %r13d,%r13d
cmpl   $0x3a,(%rcx,%rbp,4)
jne    1202 <read_kv+0xb2>
test   %eax,%eax
je     1202 <read_kv+0xb2>
lea    0x4(,%rax,4),%edi
call   1070 <malloc@plt>
mov    %rax,(%r12)
mov    (%rbx),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1040 <wmemcpy@plt>
mov    (%r12),%rax
movl   $0x0,(%rax,%rbp,4)
mov    (%rbx),%rax
lea    (%rax,%rbp,4),%rax
add    $0x4,%rax
mov    %rax,(%rbx)
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <extract_name@plt>
mov    (%rbx),%rdi
lea    0xe47(%rip),%rsi
mov    $0x1,%r13d
mov    $0x1,%edx
call   1030 <mywcscspn@plt>
mov    %eax,%ebp
mov    (%rbx),%rdi
mov    %eax,%esi
call   1050 <unquote@plt>
mov    %rax,(%r14)
movslq %ebp,%rax
shl    $0x2,%rax
add    %rax,(%rbx)
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i32] [i32 32, i32 9, i32 13, i32 10, i32 58, i32 123, i32 125, i32 0]
@.str.1 = [7 x i32] [i32 32, i32 9, i32 13, i32 10, i32 123, i32 125, i32 0]
define i32 @read_kv(i32** %0, i32** %1, i32** %2, i32** %3) {
%5 = alloca i32
%6 = alloca i32**
%7 = alloca i32**
%8 = alloca i32**
%9 = alloca i32**
%10 = alloca i32
%11 = alloca i32
store i32** %0, i32*** %6
store i32** %1, i32*** %7
store i32** %2, i32*** %8
store i32** %3, i32*** %9
%12 = load i32**, i32*** %6
%13 = load i32*, i32** %12
%14 = call i32 @mywcscspn(i32* %13, i8* bitcast ([8 x i32]* @.str to i8*), i32 3)
store i32 %14, i32* %10
%15 = load i32**, i32*** %6
%16 = load i32*, i32** %15
%17 = load i32, i32* %10
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
%21 = icmp ne i32 %20, 58
br i1 %21, label %25, label %22
22: ; preds = %4
%23 = load i32, i32* %10
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22, %4
store i32 0, i32* %5
br label %67
26: ; preds = %22
%27 = load i32, i32* %10
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = mul i64 %29, 4
%31 = trunc i64 %30 to i32
%32 = call i32* @malloc(i32 %31)
%33 = load i32**, i32*** %7
store i32* %32, i32** %33
%34 = load i32**, i32*** %7
%35 = load i32*, i32** %34
%36 = load i32**, i32*** %6
%37 = load i32*, i32** %36
%38 = load i32, i32* %10
%39 = call i32 @wmemcpy(i32* %35, i32* %37, i32 %38)
%40 = load i32**, i32*** %7
%41 = load i32*, i32** %40
%42 = load i32, i32* %10
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
store i32 0, i32* %44
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 1
%47 = load i32**, i32*** %6
%48 = load i32*, i32** %47
%49 = sext i32 %46 to i64
%50 = getelementptr inbounds i32, i32* %48, i64 %49
store i32* %50, i32** %47
%51 = load i32**, i32*** %7
%52 = load i32**, i32*** %8
%53 = call i32 @extract_name(i32** %51, i32** %52)
%54 = load i32**, i32*** %6
%55 = load i32*, i32** %54
%56 = call i32 @mywcscspn(i32* %55, i8* bitcast ([7 x i32]* @.str.1 to i8*), i32 1)
store i32 %56, i32* %11
%57 = load i32**, i32*** %6
%58 = load i32*, i32** %57
%59 = load i32, i32* %11
%60 = call i32* @unquote(i32* %58, i32 %59)
%61 = load i32**, i32*** %9
store i32* %60, i32** %61
%62 = load i32, i32* %11
%63 = load i32**, i32*** %6
%64 = load i32*, i32** %63
%65 = sext i32 %62 to i64
%66 = getelementptr inbounds i32, i32* %64, i64 %65
store i32* %66, i32** %63
store i32 1, i32* %5
br label %67
67: ; preds = %26, %25
%68 = load i32, i32* %5
ret i32 %68
}

LLVM IR (-O2):
@.str = [8 x i32] [i32 32, i32 9, i32 13, i32 10, i32 58, i32 123, i32 125, i32 0]
@.str.1 = [7 x i32] [i32 32, i32 9, i32 13, i32 10, i32 123, i32 125, i32 0]
define i32 @read_kv(i32** nocapture %0, i32** %1, i32** %2, i32** nocapture writeonly %3) {
%5 = load i32*, i32** %0
%6 = tail call i32 @mywcscspn(i32* %5, i8* bitcast ([8 x i32]* @.str to i8*), i32 3)
%7 = load i32*, i32** %0
%8 = sext i32 %6 to i64
%9 = getelementptr inbounds i32, i32* %7, i64 %8
%10 = load i32, i32* %9
%11 = icmp ne i32 %10, 58
%12 = icmp eq i32 %6, 0
%13 = select i1 %11, i1 true, i1 %12
br i1 %13, label %33, label %14
14: ; preds = %4
%15 = add nsw i32 %6, 1
%16 = sext i32 %15 to i64
%17 = shl i32 %15, 2
%18 = tail call i32* @malloc(i32 %17)
store i32* %18, i32** %1
%19 = load i32*, i32** %0
%20 = tail call i32 @wmemcpy(i32* %18, i32* %19, i32 %6)
%21 = load i32*, i32** %1
%22 = getelementptr inbounds i32, i32* %21, i64 %8
store i32 0, i32* %22
%23 = load i32*, i32** %0
%24 = getelementptr inbounds i32, i32* %23, i64 %16
store i32* %24, i32** %0
%25 = tail call i32 @extract_name(i32** %1, i32** %2)
%26 = load i32*, i32** %0
%27 = tail call i32 @mywcscspn(i32* %26, i8* bitcast ([7 x i32]* @.str.1 to i8*), i32 1)
%28 = load i32*, i32** %0
%29 = tail call i32* @unquote(i32* %28, i32 %27)
store i32* %29, i32** %3
%30 = load i32*, i32** %0
%31 = sext i32 %27 to i64
%32 = getelementptr inbounds i32, i32* %30, i64 %31
store i32* %32, i32** %0
br label %33
33: ; preds = %4, %14
%34 = phi i32 [ 1, %14 ], [ 0, %4 ]
ret i32 %34
}