#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 *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int strlen(char *);
char *strstr(char *, char *);
char *stripoh(char *input) {
  char *begin = NULL;
  if ((begin = strstr(input, "P_DATA=")) != NULL) {
    int strlength = strlen(begin) - 6;
    char *payload = (char *)malloc(strlength * sizeof(char));
    memset(payload, 0, strlength);
    memcpy(payload, begin + 7, strlength);
    free(input);
    return payload;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<stripoh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11ec <stripoh+0x8c>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x6,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x7,%rsi
mov    -0x1c(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11f4 <stripoh+0x94>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stripoh>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe8f(%rip),%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     11ba <stripoh+0x5a>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    -0x6(%rax),%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1050 <memset@plt>
add    $0x7,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1060 <memcpy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    11bd <stripoh+0x5d>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"P_DATA=\00"
define i8* @stripoh(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %4
%7 = load i8*, i8** %3
%8 = call i8* @strstr(i8* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %31
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
%13 = sub nsw i32 %12, 6
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 1
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = load i32, i32* %5
%22 = call i32 @memset(i8* %20, i32 0, i32 %21)
%23 = load i8*, i8** %6
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i64 7
%26 = load i32, i32* %5
%27 = call i32 @memcpy(i8* %23, i8* %25, i32 %26)
%28 = load i8*, i8** %3
%29 = call i32 @free(i8* %28)
%30 = load i8*, i8** %6
store i8* %30, i8** %2
br label %32
31: ; preds = %1
store i8* null, i8** %2
br label %32
32: ; preds = %31, %10
%33 = load i8*, i8** %2
ret i8* %33
}

LLVM IR (-O2):
@.str = [8 x i8] c"P_DATA=\00"
define i8* @stripoh(i8* %0) {
%2 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %2)
%6 = add nsw i32 %5, -6
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @memset(i8* %8, i32 0, i32 %6)
%10 = getelementptr inbounds i8, i8* %2, i64 7
%11 = tail call i32 @memcpy(i8* %8, i8* %10, i32 %6)
%12 = tail call i32 @free(i8* %0)
br label %13
13: ; preds = %1, %4
%14 = phi i8* [ %8, %4 ], [ null, %1 ]
ret i8* %14
}