#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 libc_strlen(char *);
int /*<<< orphan*/ libc_strncat(char *, char *, int);
char *libc_strstr(char *, char *);
char *malloc(int);
char *libc_strpstr(char *str, char *ser) {
  int len_ser = libc_strlen(ser), len_str = libc_strlen(str), len_nstr;
  char *buff_strn = malloc(len_str);
  if (libc_strstr(str, ser)) {
    char *estr = libc_strstr(str, ser) + len_ser;
    int iestr = libc_strlen(estr);
    len_nstr = len_str - iestr - len_ser;
    libc_strncat(buff_strn, str, len_nstr);
  }
  return buff_strn;
}


x86 assembly (clang, -O0):
<libc_strpstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <libc_strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <libc_strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <libc_strstr@plt>
cmp    $0x0,%rax
je     11cb <libc_strpstr+0x8b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <libc_strstr@plt>
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <libc_strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x34(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <libc_strncat@plt>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<libc_strpstr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1050 <libc_strlen@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1050 <libc_strlen@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <libc_strstr@plt>
test   %rax,%rax
je     11a5 <libc_strpstr+0x65>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <libc_strstr@plt>
movslq %r12d,%rbx
lea    (%rax,%rbx,1),%rdi
call   1050 <libc_strlen@plt>
add    %eax,%ebx
sub    %ebx,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1060 <libc_strncat@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @libc_strpstr(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%11 = load i8*, i8** %4
%12 = call i32 @libc_strlen(i8* %11)
store i32 %12, i32* %5
%13 = load i8*, i8** %3
%14 = call i32 @libc_strlen(i8* %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %8
%17 = load i8*, i8** %3
%18 = load i8*, i8** %4
%19 = call i8* @libc_strstr(i8* %17, i8* %18)
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %39
21: ; preds = %2
%22 = load i8*, i8** %3
%23 = load i8*, i8** %4
%24 = call i8* @libc_strstr(i8* %22, i8* %23)
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8* %27, i8** %9
%28 = load i8*, i8** %9
%29 = call i32 @libc_strlen(i8* %28)
store i32 %29, i32* %10
%30 = load i32, i32* %6
%31 = load i32, i32* %10
%32 = sub nsw i32 %30, %31
%33 = load i32, i32* %5
%34 = sub nsw i32 %32, %33
store i32 %34, i32* %7
%35 = load i8*, i8** %8
%36 = load i8*, i8** %3
%37 = load i32, i32* %7
%38 = call i32 @libc_strncat(i8* %35, i8* %36, i32 %37)
br label %39
39: ; preds = %21, %2
%40 = load i8*, i8** %8
ret i8* %40
}

LLVM IR (-O2):
define i8* @libc_strpstr(i8* %0, i8* %1) {
%3 = tail call i32 @libc_strlen(i8* %1)
%4 = tail call i32 @libc_strlen(i8* %0)
%5 = tail call i8* @malloc(i32 %4)
%6 = tail call i8* @libc_strstr(i8* %0, i8* %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %16, label %8
8: ; preds = %2
%9 = tail call i8* @libc_strstr(i8* %0, i8* %1)
%10 = sext i32 %3 to i64
%11 = getelementptr inbounds i8, i8* %9, i64 %10
%12 = tail call i32 @libc_strlen(i8* %11)
%13 = add i32 %3, %12
%14 = sub i32 %4, %13
%15 = tail call i32 @libc_strncat(i8* %5, i8* %0, i32 %14)
br label %16
16: ; preds = %8, %2
ret i8* %5
}