#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*/ libc_strcpy(char *, char *);
int libc_strlen(char *);
int /*<<< orphan*/ libc_strncat(char *, char *, int);
char *libc_strstr(char *, char *);
char *malloc(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
char *libc_strpstr_nomo(char *str, char *ser) {
  if (libc_strstr(str, ser)) {
    int len_ser = libc_strlen(ser), len_str = libc_strlen(str), len_nstr;
    char *buff_strn = malloc(strlen(str));
    libc_strcpy(buff_strn, "\0");
    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;
  } else {
    return str;
  }
}


x86 assembly (clang, -O0):
<libc_strpstr_nomo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <libc_strstr@plt>
cmp    $0x0,%rax
je     1210 <libc_strpstr_nomo+0xb0>
mov    -0x18(%rbp),%rdi
call   1060 <libc_strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <libc_strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1080 <libc_strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <libc_strstr@plt>
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <libc_strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%eax
sub    -0x3c(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1070 <libc_strncat@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1218 <libc_strpstr_nomo+0xb8>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<libc_strpstr_nomo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <libc_strstr@plt>
test   %rax,%rax
je     11df <libc_strpstr_nomo+0x7f>
mov    %r14,%rdi
call   1060 <libc_strlen@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   1060 <libc_strlen@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%r13
lea    0xe56(%rip),%rsi
mov    %rax,%rdi
call   1080 <libc_strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <libc_strstr@plt>
movslq %r12d,%rbp
lea    (%rax,%rbp,1),%rdi
call   1060 <libc_strlen@plt>
add    %eax,%ebp
sub    %ebp,%r15d
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1070 <libc_strncat@plt>
mov    %r13,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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