#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*/ strncmp(char const *, char const *, size_t);
const char *ueStrStr(const char *str, size_t lstr, const char *substr,
                     size_t lsub) {
  const char *p = str;
  size_t ub;
  if (lstr < lsub)
    return NULL;
  ub = lstr - lsub;
  for (; (size_t)(p - str) <= ub; p++) {
    if (!strncmp(p, substr, lsub))
      return p;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<ueStrStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    114b <ueStrStr+0x3b>
movq   $0x0,-0x8(%rbp)
jmp    11b1 <ueStrStr+0xa1>
mov    -0x18(%rbp),%rax
sub    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
cmp    -0x38(%rbp),%rax
ja     11a9 <ueStrStr+0x99>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1193 <ueStrStr+0x83>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b1 <ueStrStr+0xa1>
jmp    1198 <ueStrStr+0x88>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1157 <ueStrStr+0x47>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ueStrStr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
sub    %rcx,%r13
jb     114f <ueStrStr+0x3f>
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rdi,%r12
xor    %ebp,%ebp
xchg   %ax,%ax
lea    (%r12,%rbp,1),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1151 <ueStrStr+0x41>
add    $0x1,%rbp
cmp    %r13,%rbp
jbe    1130 <ueStrStr+0x20>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @ueStrStr(i8* %0, i64 %1, i8* nocapture %2, i64 %3) {
%5 = icmp ult i64 %1, %3
br i1 %5, label %18, label %6
6: ; preds = %4
%7 = sub i64 %1, %3
%8 = ptrtoint i8* %0 to i64
br label %9
9: ; preds = %6, %13
%10 = phi i8* [ %0, %6 ], [ %14, %13 ]
%11 = tail call i32 @strncmp(i8* %10, i8* %2, i64 %3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %9
%14 = getelementptr inbounds i8, i8* %10, i64 1
%15 = ptrtoint i8* %14 to i64
%16 = sub i64 %15, %8
%17 = icmp ugt i64 %16, %7
br i1 %17, label %18, label %9
18: ; preds = %13, %9, %4
%19 = phi i8* [ null, %4 ], [ null, %13 ], [ %10, %9 ]
ret i8* %19
}