#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__ malloc(int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char const *, char *);
char *getKey(const char *pKeyVal) {
  char *pKey;
  if (pKeyVal == NULL)
    return NULL;
  char *pPosColon1 = strstr(pKeyVal, "\"") + 1;
  if (pPosColon1 == NULL)
    return NULL;
  char *pPosColon2 = strstr(pPosColon1, "\"");
  if (pPosColon2 == NULL)
    return NULL;
  pKey = (char *)malloc(sizeof(char *) * (pPosColon2 - pPosColon1 + 5));
  strncpy(pKey, pPosColon1, pPosColon2 - pPosColon1);
  pKey[pPosColon2 - pPosColon1] = '\0';
  return pKey;
}


x86 assembly (clang, -O0):
<getKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1154 <getKey+0x24>
movq   $0x0,-0x8(%rbp)
jmp    1203 <getKey+0xd3>
mov    -0x10(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1050 <strstr@plt>
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1184 <getKey+0x54>
movq   $0x0,-0x8(%rbp)
jmp    1203 <getKey+0xd3>
mov    -0x20(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b0 <getKey+0x80>
movq   $0x0,-0x8(%rbp)
jmp    1203 <getKey+0xd3>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
add    $0x5,%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getKey>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1186 <getKey+0x56>
mov    $0x22,%esi
call   1040 <strchr@plt>
mov    %rax,%r14
add    $0x1,%r14
mov    %r14,%rdi
mov    $0x22,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1186 <getKey+0x56>
mov    %rax,%rbx
sub    %r14,%rbx
lea    0x28(,%rbx,8),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r15,%rbx,1)
jmp    1189 <getKey+0x59>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\22\00"
define i8* @getKey(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* null, i8** %2
br label %51
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i8* @strstr(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds i8, i8* %12, i64 1
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %10
store i8* null, i8** %2
br label %51
17: ; preds = %10
%18 = load i8*, i8** %5
%19 = call i8* @strstr(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %17
store i8* null, i8** %2
br label %51
23: ; preds = %17
%24 = load i8*, i8** %6
%25 = load i8*, i8** %5
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
%29 = add nsw i64 %28, 5
%30 = mul i64 8, %29
%31 = trunc i64 %30 to i32
%32 = call i64 @malloc(i32 %31)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %4
%34 = load i8*, i8** %4
%35 = load i8*, i8** %5
%36 = load i8*, i8** %6
%37 = load i8*, i8** %5
%38 = ptrtoint i8* %36 to i64
%39 = ptrtoint i8* %37 to i64
%40 = sub i64 %38, %39
%41 = trunc i64 %40 to i32
%42 = call i32 @strncpy(i8* %34, i8* %35, i32 %41)
%43 = load i8*, i8** %4
%44 = load i8*, i8** %6
%45 = load i8*, i8** %5
%46 = ptrtoint i8* %44 to i64
%47 = ptrtoint i8* %45 to i64
%48 = sub i64 %46, %47
%49 = getelementptr inbounds i8, i8* %43, i64 %48
store i8 0, i8* %49
%50 = load i8*, i8** %4
store i8* %50, i8** %2
br label %51
51: ; preds = %23, %22, %16, %9
%52 = load i8*, i8** %2
ret i8* %52
}

LLVM IR (-O2):
define i8* @getKey(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %19, label %3
3: ; preds = %1
%4 = tail call i8* @strchr(i8* %0, i32 34)
%5 = getelementptr inbounds i8, i8* %4, i64 1
%6 = tail call i8* @strchr(i8* %5, i32 34)
%7 = icmp eq i8* %6, null
br i1 %7, label %19, label %8
8: ; preds = %3
%9 = ptrtoint i8* %6 to i64
%10 = ptrtoint i8* %5 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = shl i32 %12, 3
%14 = add i32 %13, 40
%15 = tail call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
%17 = tail call i32 @strncpy(i8* %16, i8* %5, i32 %12)
%18 = getelementptr inbounds i8, i8* %16, i64 %11
store i8 0, i8* %18
br label %19
19: ; preds = %3, %8, %1
%20 = phi i8* [ null, %1 ], [ %16, %8 ], [ null, %3 ]
ret i8* %20
}