#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 */
scalar_t__ WpeStrnccmp(char *, char const *, int const);
int strlen(char const *);
char *WpeStrcstr(char *str, const char *substr) {
  const int len = strlen(substr);
  for (; *str; str++) {
    if (WpeStrnccmp(str, substr, len) == 0) {
      return (str);
    }
  }
  return (NULL);
}


x86 assembly (clang, -O0):
<WpeStrcstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1186 <WpeStrcstr+0x66>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <WpeStrnccmp@plt>
cmp    $0x0,%rax
jne    1170 <WpeStrcstr+0x50>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    118e <WpeStrcstr+0x6e>
jmp    1175 <WpeStrcstr+0x55>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    113c <WpeStrcstr+0x1c>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WpeStrcstr>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
cmpb   $0x0,(%rbx)
je     115c <WpeStrcstr+0x3c>
mov    %eax,%ebp
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <WpeStrnccmp@plt>
test   %rax,%rax
je     115e <WpeStrcstr+0x3e>
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
jne    1140 <WpeStrcstr+0x20>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @WpeStrcstr(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %6
br label %9
9: ; preds = %22, %2
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = load i8*, i8** %5
%16 = load i32, i32* %6
%17 = call i64 @WpeStrnccmp(i8* %14, i8* %15, i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = load i8*, i8** %4
store i8* %20, i8** %3
br label %26
21: ; preds = %13
br label %22
22: ; preds = %21
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
br label %9
25: ; preds = %9
store i8* null, i8** %3
br label %26
26: ; preds = %25, %19
%27 = load i8*, i8** %3
ret i8* %27
}

LLVM IR (-O2):
define i8* @WpeStrcstr(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %2, %10
%7 = phi i8* [ %11, %10 ], [ %0, %2 ]
%8 = tail call i64 @WpeStrnccmp(i8* %7, i8* %1, i32 %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %7, i64 1
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %6
14: ; preds = %6, %10, %2
%15 = phi i8* [ null, %2 ], [ null, %10 ], [ %7, %6 ]
ret i8* %15
}