#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 strlen(char *);
char *strstr(char *, char *);
int trimSpace(char *, char *);
int getKeyByValue(char *keyval, char *pkey, char *buf, int *len) {
  if (keyval == NULL || pkey == NULL || buf == NULL || len == NULL) {
    return -1;
  }
  char *p = keyval;
  p = strstr(p, pkey);
  if (NULL == p) {
    return -2;
  }
  p = p + strlen(pkey);
  p = strstr(p, "=");
  if (NULL == p) {
    return -3;
  }
  p = p + strlen("=");
  int ret = trimSpace(p, buf);
  if (ret != 0) {
    return ret;
  }
  *len = strlen(buf);
  return 0;
}


x86 assembly (clang, -O0):
<getKeyByValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1174 <getKeyByValue+0x44>
cmpq   $0x0,-0x18(%rbp)
je     1174 <getKeyByValue+0x44>
cmpq   $0x0,-0x20(%rbp)
je     1174 <getKeyByValue+0x44>
cmpq   $0x0,-0x28(%rbp)
jne    1180 <getKeyByValue+0x50>
movl   $0xffffffff,-0x4(%rbp)
jmp    125f <getKeyByValue+0x12f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
jne    11b1 <getKeyByValue+0x81>
movl   $0xfffffffe,-0x4(%rbp)
jmp    125f <getKeyByValue+0x12f>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
jne    11fe <getKeyByValue+0xce>
movl   $0xfffffffd,-0x4(%rbp)
jmp    125f <getKeyByValue+0x12f>
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    0xdf3(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <trimSpace@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1247 <getKeyByValue+0x117>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    125f <getKeyByValue+0x12f>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getKeyByValue>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     11db <getKeyByValue+0x9b>
mov    %rsi,%rbx
test   %rsi,%rsi
je     11db <getKeyByValue+0x9b>
mov    %rdx,%r15
test   %rdx,%rdx
je     11db <getKeyByValue+0x9b>
mov    %rcx,%r14
test   %rcx,%rcx
je     11db <getKeyByValue+0x9b>
mov    %rbx,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     11cf <getKeyByValue+0x8f>
mov    %rax,%r12
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%r12
mov    %r12,%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11d6 <getKeyByValue+0x96>
mov    %rax,%rbx
lea    0xe59(%rip),%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <trimSpace@plt>
test   %eax,%eax
jne    11db <getKeyByValue+0x9b>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,(%r14)
xor    %eax,%eax
jmp    11db <getKeyByValue+0x9b>
mov    $0xfffffffe,%eax
jmp    11db <getKeyByValue+0x9b>
mov    $0xfffffffd,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"=\00"
define i32 @getKeyByValue(i8* %0, i8* %1, i8* %2, i32* writeonly %3) {
%5 = icmp eq i8* %0, null
%6 = icmp eq i8* %1, null
%7 = or i1 %5, %6
%8 = icmp eq i8* %2, null
%9 = or i1 %7, %8
%10 = icmp eq i32* %3, null
%11 = or i1 %9, %10
br i1 %11, label %29, label %12
12: ; preds = %4
%13 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%14 = icmp eq i8* %13, null
br i1 %14, label %29, label %15
15: ; preds = %12
%16 = tail call i32 @strlen(i8* %1)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %13, i64 %17
%19 = tail call i8* @strchr(i8* %18, i32 61)
%20 = icmp eq i8* %19, null
br i1 %20, label %29, label %21
21: ; preds = %15
%22 = tail call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %19, i64 %23
%25 = tail call i32 @trimSpace(i8* %24, i8* %2)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = tail call i32 @strlen(i8* %2)
store i32 %28, i32* %3
br label %29
29: ; preds = %12, %15, %21, %27, %4
%30 = phi i32 [ -1, %4 ], [ -2, %12 ], [ -3, %15 ], [ 0, %27 ], [ %25, %21 ]
ret i32 %30
}