#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 */
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
scalar_t__ strlen(char *);
char *strstr(char *, char *);
void parse_json(char *json, char **key, char **val) {
  char *json_pre_key = "{\"";
  char *json_post_key = "\":\"";
  char *json_end = "\"}";
  char *temp = strstr(json, json_pre_key);
  int index_key_start = (temp - json) + (int)strlen(json_pre_key);
  temp = strstr(json, json_post_key);
  int index_key_end = temp - json;
  int index_val_start = index_key_end + (int)strlen(json_post_key);
  temp = strstr(json, json_end);
  int index_val_end = temp - json;
  size_t key_length = (size_t)(index_key_end - index_key_start);
  size_t val_length = (size_t)(index_val_end - index_val_start);
  *key = malloc((sizeof(char) * key_length) + sizeof(char));
  *val = malloc((sizeof(char) * val_length) + sizeof(char));
  memcpy(*key, &json[index_key_start], key_length);
  memcpy(*val, &json[index_val_start], val_length);
  free(json);
  (*key)[key_length] = '\0';
  (*val)[val_length] = '\0';
}


x86 assembly (clang, -O0):
<parse_json>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xe95(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe8d(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe86(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x5c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x48(%rbp)
mov    -0x40(%rbp),%eax
sub    -0x3c(%rbp),%eax
cltq
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%eax
sub    -0x44(%rbp),%eax
cltq
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x58(%rbp),%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x3c(%rbp),%rax
add    %rax,%rsi
mov    -0x50(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x44(%rbp),%rax
add    %rax,%rsi
mov    -0x58(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x50(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x58(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_json>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xea0(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,%r12
sub    %ebx,%r12d
add    $0x2,%r12d
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strstr@plt>
mov    %rax,%r13
sub    %rbx,%r13
lea    0xe7c(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strstr@plt>
mov    %rax,%r15
sub    %ebx,%r15d
mov    %r13d,%eax
sub    %r12d,%eax
movslq %eax,%rcx
mov    %rcx,(%rsp)
sub    %r13d,%r15d
lea    -0x3(%r15),%eax
cltq
mov    %rax,0x8(%rsp)
lea    0x1(%rcx),%edi
call   1050 <malloc@plt>
mov    %rax,(%r14)
add    $0xfffffffe,%r15d
mov    %r15d,%edi
call   1050 <malloc@plt>
mov    0x10(%rsp),%rbp
mov    %rax,0x0(%rbp)
mov    %r14,%r15
mov    (%r14),%rdi
movslq %r12d,%rsi
add    %rbx,%rsi
mov    (%rsp),%r12
mov    %r12,%rdx
call   1040 <memcpy@plt>
mov    0x0(%rbp),%rdi
movslq %r13d,%rax
lea    (%rax,%rbx,1),%rsi
add    $0x3,%rsi
mov    0x8(%rsp),%r14
mov    %r14,%rdx
call   1040 <memcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    (%r15),%rax
movb   $0x0,(%rax,%r12,1)
mov    0x0(%rbp),%rax
movb   $0x0,(%rax,%r14,1)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"{\22\00"
@.str.1 = [4 x i8] c"\22:\22\00"
@.str.2 = [3 x i8] c"\22}\00"
define void @parse_json(i8* %0, i8** %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i64
%16 = alloca i64
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i8** %2, i8*** %6
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %8
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %9
%17 = load i8*, i8** %4
%18 = load i8*, i8** %7
%19 = call i8* @strstr(i8* %17, i8* %18)
store i8* %19, i8** %10
%20 = load i8*, i8** %10
%21 = load i8*, i8** %4
%22 = ptrtoint i8* %20 to i64
%23 = ptrtoint i8* %21 to i64
%24 = sub i64 %22, %23
%25 = load i8*, i8** %7
%26 = call i64 @strlen(i8* %25)
%27 = trunc i64 %26 to i32
%28 = sext i32 %27 to i64
%29 = add nsw i64 %24, %28
%30 = trunc i64 %29 to i32
store i32 %30, i32* %11
%31 = load i8*, i8** %4
%32 = load i8*, i8** %8
%33 = call i8* @strstr(i8* %31, i8* %32)
store i8* %33, i8** %10
%34 = load i8*, i8** %10
%35 = load i8*, i8** %4
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = trunc i64 %38 to i32
store i32 %39, i32* %12
%40 = load i32, i32* %12
%41 = load i8*, i8** %8
%42 = call i64 @strlen(i8* %41)
%43 = trunc i64 %42 to i32
%44 = add nsw i32 %40, %43
store i32 %44, i32* %13
%45 = load i8*, i8** %4
%46 = load i8*, i8** %9
%47 = call i8* @strstr(i8* %45, i8* %46)
store i8* %47, i8** %10
%48 = load i8*, i8** %10
%49 = load i8*, i8** %4
%50 = ptrtoint i8* %48 to i64
%51 = ptrtoint i8* %49 to i64
%52 = sub i64 %50, %51
%53 = trunc i64 %52 to i32
store i32 %53, i32* %14
%54 = load i32, i32* %12
%55 = load i32, i32* %11
%56 = sub nsw i32 %54, %55
%57 = sext i32 %56 to i64
store i64 %57, i64* %15
%58 = load i32, i32* %14
%59 = load i32, i32* %13
%60 = sub nsw i32 %58, %59
%61 = sext i32 %60 to i64
store i64 %61, i64* %16
%62 = load i64, i64* %15
%63 = mul i64 1, %62
%64 = add i64 %63, 1
%65 = trunc i64 %64 to i32
%66 = call i8* @malloc(i32 %65)
%67 = load i8**, i8*** %5
store i8* %66, i8** %67
%68 = load i64, i64* %16
%69 = mul i64 1, %68
%70 = add i64 %69, 1
%71 = trunc i64 %70 to i32
%72 = call i8* @malloc(i32 %71)
%73 = load i8**, i8*** %6
store i8* %72, i8** %73
%74 = load i8**, i8*** %5
%75 = load i8*, i8** %74
%76 = load i8*, i8** %4
%77 = load i32, i32* %11
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8, i8* %76, i64 %78
%80 = load i64, i64* %15
%81 = call i32 @memcpy(i8* %75, i8* %79, i64 %80)
%82 = load i8**, i8*** %6
%83 = load i8*, i8** %82
%84 = load i8*, i8** %4
%85 = load i32, i32* %13
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8, i8* %84, i64 %86
%88 = load i64, i64* %16
%89 = call i32 @memcpy(i8* %83, i8* %87, i64 %88)
%90 = load i8*, i8** %4
%91 = call i32 @free(i8* %90)
%92 = load i8**, i8*** %5
%93 = load i8*, i8** %92
%94 = load i64, i64* %15
%95 = getelementptr inbounds i8, i8* %93, i64 %94
store i8 0, i8* %95
%96 = load i8**, i8*** %6
%97 = load i8*, i8** %96
%98 = load i64, i64* %16
%99 = getelementptr inbounds i8, i8* %97, i64 %98
store i8 0, i8* %99
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"{\22\00"
@.str.1 = [4 x i8] c"\22:\22\00"
@.str.2 = [3 x i8] c"\22}\00"
define void @parse_json(i8* %0, i8** nocapture %1, i8** nocapture %2) {
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = ptrtoint i8* %4 to i64
%6 = ptrtoint i8* %0 to i64
%7 = sub i64 %5, %6
%8 = trunc i64 %7 to i32
%9 = add i32 %8, 2
%10 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%11 = ptrtoint i8* %10 to i64
%12 = sub i64 %11, %6
%13 = trunc i64 %12 to i32
%14 = add nsw i32 %13, 3
%15 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%16 = ptrtoint i8* %15 to i64
%17 = sub i64 %16, %6
%18 = trunc i64 %17 to i32
%19 = sub nsw i32 %13, %9
%20 = sext i32 %19 to i64
%21 = sub nsw i32 %18, %14
%22 = sext i32 %21 to i64
%23 = add i32 %19, 1
%24 = tail call i8* @malloc(i32 %23)
store i8* %24, i8** %1
%25 = add i32 %21, 1
%26 = tail call i8* @malloc(i32 %25)
store i8* %26, i8** %2
%27 = load i8*, i8** %1
%28 = sext i32 %9 to i64
%29 = getelementptr inbounds i8, i8* %0, i64 %28
%30 = tail call i32 @memcpy(i8* %27, i8* %29, i64 %20)
%31 = load i8*, i8** %2
%32 = sext i32 %14 to i64
%33 = getelementptr inbounds i8, i8* %0, i64 %32
%34 = tail call i32 @memcpy(i8* %31, i8* %33, i64 %22)
%35 = tail call i32 @free(i8* %0)
%36 = load i8*, i8** %1
%37 = getelementptr inbounds i8, i8* %36, i64 %20
store i8 0, i8* %37
%38 = load i8*, i8** %2
%39 = getelementptr inbounds i8, i8* %38, i64 %22
store i8 0, i8* %39
ret void
}