#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);
char *strdup(char *);
size_t strlen(char *);
char *strndup(char *, int);
char *strstr(char *, char *);
char *getparam(char *str, char *param) {
  char *search = malloc((strlen(param) + 2) * sizeof(char));
  memcpy(search, param, strlen(param));
  search[strlen(param)] = '=';
  search[strlen(param) + 1] = '\0';
  char *begin = strstr(str, search);
  if (!begin) {
    free(search);
    return NULL;
  }
  begin += strlen(search);
  char *end = strstr(begin, "&");
  char *result;
  if (end)
    result = strndup(begin, end - begin);
  else
    result = strdup(begin);
  free(search);
  return result;
}


x86 assembly (clang, -O0):
<getparam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x2,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    %rax,%rdx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
movb   $0x3d,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
movb   $0x0,0x1(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1230 <getparam+0xc0>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    129d <getparam+0x12d>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xdb4(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     127f <getparam+0x10f>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1050 <strndup@plt>
mov    %rax,-0x38(%rbp)
jmp    128c <getparam+0x11c>
mov    -0x28(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getparam>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
lea    0x2(%rax),%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1070 <memcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movw   $0x3d,(%r14,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
call   10a0 <strstr@plt>
test   %rax,%rax
je     11ff <getparam+0x7f>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %rax,%rbx
mov    %rbx,%rdi
mov    $0x26,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1203 <getparam+0x83>
sub    %ebx,%eax
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <strndup@plt>
jmp    120b <getparam+0x8b>
xor    %ebx,%ebx
jmp    120e <getparam+0x8e>
mov    %rbx,%rdi
call   1090 <strdup@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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