#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 getKeyByValue(char *, char *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ system(char *);
int main(void) {
  char keyval[] = "key1 =    valude1";
  char *pkey = "key1";
  char buf[128] = {0};
  int len = 0;
  int ret = getKeyByValue(keyval, pkey, buf, &len);
  if (ret != 0) {
    printf("getKeyByValue: %d\n", ret);
    return ret;
  }
  printf("value: %s\nlen = %d\n", buf, len);
  printf("\n");
  system("pause");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xea7(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xea4(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xea1(%rip),%ax
mov    %ax,-0x10(%rbp)
lea    0xe98(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
movl   $0x0,-0xb4(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0xb0(%rbp),%rdx
lea    -0xb4(%rbp),%rcx
call   1030 <getKeyByValue@plt>
mov    %eax,-0xb8(%rbp)
cmpl   $0x0,-0xb8(%rbp)
je     11eb <main+0xab>
mov    -0xb8(%rbp),%esi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xb8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1227 <main+0xe7>
lea    -0xb0(%rbp),%rsi
mov    -0xb4(%rbp),%edx
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe23(%rip),%rdi
call   1040 <system@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xb0,%rsp
movaps 0xeb1(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movw   $0x31,0x20(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movl   $0x0,0xc(%rsp)
lea    0xe74(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0x30(%rsp),%rdx
lea    0xc(%rsp),%rcx
call   1030 <getKeyByValue@plt>
mov    %eax,%ebx
test   %eax,%eax
je     11ca <main+0x8a>
lea    0xe58(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11f7 <main+0xb7>
mov    0xc(%rsp),%edx
lea    0xe55(%rip),%rdi
lea    0x30(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xe4c(%rip),%rdi
call   1050 <system@plt>
mov    %ebx,%eax
add    $0xb0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.keyval = [18 x i8] c"key1 = valude1\00"
@.str = [5 x i8] c"key1\00"
@.str.1 = [19 x i8] c"getKeyByValue: %d\0A\00"
@.str.2 = [20 x i8] c"value: %s\0Alen = %d\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [18 x i8]
%3 = alloca i8*
%4 = alloca [128 x i8]
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = bitcast [18 x i8]* %2 to i8*
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %3
%8 = bitcast [128 x i8]* %4 to i8*
store i32 0, i32* %5
%9 = getelementptr inbounds [18 x i8], [18 x i8]* %2, i64 0, i64 0
%10 = load i8*, i8** %3
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%12 = call i32 @getKeyByValue(i8* %9, i8* %10, i8* %11, i32* %5)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %0
%16 = load i32, i32* %6
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %6
store i32 %18, i32* %1
br label %25
19: ; preds = %0
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%21 = load i32, i32* %5
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %20, i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %25
25: ; preds = %19, %15
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@__const.main.keyval = [18 x i8] c"key1 = valude1\00"
@.str = [5 x i8] c"key1\00"
@.str.1 = [19 x i8] c"getKeyByValue: %d\0A\00"
@.str.2 = [20 x i8] c"value: %s\0Alen = %d\0A\00"
@.str.4 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca [18 x i8]
%2 = alloca [128 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [18 x i8], [18 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = call i32 @getKeyByValue(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %5, i32* %3)
%8 = icmp eq i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %7)
br label %16
11: ; preds = %0
%12 = load i32, i32* %3
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %5, i32 %12)
%14 = call i32 @putchar(i32 10)
%15 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %16
16: ; preds = %11, %9
ret i32 %7
}