#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 */
char *malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
size_t strlen(char const *);
char *strstr(char const *, char *);
char *UWAPI_Board_Regular2D_GetAdditionalParam(char const *str,
                                               char const *key) {
  size_t key_query_len = strlen(key);
  char key_query[key_query_len + 3];
  key_query[0] = '_';
  memcpy(&(key_query[1]), key, key_query_len);
  key_query[1 + key_query_len] = '=';
  key_query[1 + key_query_len + 1] = '\0';
  char *start = strstr(str, key_query);
  if (start == NULL) {
    return start;
  }
  start += key_query_len + 2;
  size_t val_len;
  char *end = strstr(start, "_");
  if (end == NULL) {
    val_len = strlen(start);
  } else {
    val_len = end - start;
  }
  char *val = malloc(val_len + 1);
  memcpy(val, start, val_len);
  val[val_len] = '\0';
  return val;
}


x86 assembly (clang, -O0):
<UWAPI_Board_Regular2D_GetAdditionalParam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
mov    %rcx,%rax
add    $0x3,%rax
mov    %rsp,%rdx
mov    %rdx,-0x28(%rbp)
add    $0x12,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x60(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
movb   $0x5f,(%rdi)
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x60(%rbp),%rsi
mov    -0x20(%rbp),%rax
add    $0x1,%rax
movb   $0x3d,(%rsi,%rax,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
movb   $0x0,0x1(%rsi,%rax,1)
mov    -0x10(%rbp),%rdi
call   1060 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11e5 <UWAPI_Board_Regular2D_GetAdditionalParam+0xa5>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1272 <UWAPI_Board_Regular2D_GetAdditionalParam+0x132>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe00(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    1226 <UWAPI_Board_Regular2D_GetAdditionalParam+0xe6>
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x48(%rbp)
jmp    1235 <UWAPI_Board_Regular2D_GetAdditionalParam+0xf5>
mov    -0x50(%rbp),%rax
mov    -0x38(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x48(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x58(%rbp),%rax
mov    -0x48(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x58(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UWAPI_Board_Regular2D_GetAdditionalParam>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
mov    %rsp,%rax
lea    0x12(%r12),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rax,%rbx
sub    %rcx,%rbx
mov    %rbx,%rsp
neg    %rcx
movb   $0x5f,(%rax,%rcx,1)
lea    0x1(%rbx),%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1050 <memcpy@plt>
movw   $0x3d,0x1(%r12,%rbx,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     11d3 <UWAPI_Board_Regular2D_GetAdditionalParam+0x83>
mov    %rax,%r14
add    $0x2,%r12
add    %r12,%r14
mov    %r14,%rdi
mov    $0x5f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11d8 <UWAPI_Board_Regular2D_GetAdditionalParam+0x88>
mov    %rax,%rbx
sub    %r14,%rbx
jmp    11e3 <UWAPI_Board_Regular2D_GetAdditionalParam+0x93>
xor    %r15d,%r15d
jmp    1202 <UWAPI_Board_Regular2D_GetAdditionalParam+0xb2>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
lea    0x1(%rbx),%rdi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
movb   $0x0,(%r15,%rbx,1)
mov    %r15,%rax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @UWAPI_Board_Regular2D_GetAdditionalParam(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = add i64 %3, 3
%5 = alloca i8, i64 %4
store i8 95, i8* %5
%6 = getelementptr inbounds i8, i8* %5, i64 1
%7 = call i32 @memcpy(i8* %6, i8* %1, i64 %3)
%8 = add i64 %3, 1
%9 = getelementptr inbounds i8, i8* %5, i64 %8
store i8 61, i8* %9
%10 = add i64 %3, 2
%11 = getelementptr inbounds i8, i8* %5, i64 %10
store i8 0, i8* %11
%12 = call i8* @strstr(i8* dereferenceable(1) %0, i8* %5)
%13 = icmp eq i8* %12, null
br i1 %13, label %30, label %14
14: ; preds = %2
%15 = getelementptr inbounds i8, i8* %12, i64 %10
%16 = call i8* @strchr(i8* %15, i32 95)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i64 @strlen(i8* %15)
br label %24
20: ; preds = %14
%21 = ptrtoint i8* %16 to i64
%22 = ptrtoint i8* %15 to i64
%23 = sub i64 %21, %22
br label %24
24: ; preds = %20, %18
%25 = phi i64 [ %19, %18 ], [ %23, %20 ]
%26 = add i64 %25, 1
%27 = call i8* @malloc(i64 %26)
%28 = call i32 @memcpy(i8* %27, i8* %15, i64 %25)
%29 = getelementptr inbounds i8, i8* %27, i64 %25
store i8 0, i8* %29
br label %30
30: ; preds = %2, %24
%31 = phi i8* [ %27, %24 ], [ null, %2 ]
ret i8* %31
}