#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 */
size_t strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char const *, int);
int substr_eq(const char *src, const char *dest, int size) {
  int offset;
  size_t len;
  len = strlen(dest);
  for (offset = 0; offset + size < len; offset++) {
    if (!strncmp(src, dest + offset, size))
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<substr_eq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
cltq
cmp    -0x28(%rbp),%rax
jae    1198 <substr_eq+0x78>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1185 <substr_eq+0x65>
movl   $0x1,-0x4(%rbp)
jmp    119f <substr_eq+0x7f>
jmp    118a <substr_eq+0x6a>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1147 <substr_eq+0x27>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<substr_eq>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1040 <strlen@plt>
movslq %r12d,%rbp
xor    %r14d,%r14d
cmp    %rbp,%rax
jbe    1177 <substr_eq+0x57>
mov    %rax,%r13
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1171 <substr_eq+0x51>
add    $0x1,%rbx
add    $0x1,%rbp
cmp    %rbp,%r13
ja     1150 <substr_eq+0x30>
jmp    1177 <substr_eq+0x57>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @substr_eq(i8* %0, i8* %1, i32 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = sext i32 %2 to i64
%6 = icmp ugt i64 %4, %5
br i1 %6, label %10, label %16
7: ; preds = %10
%8 = add nsw i64 %15, %5
%9 = icmp ugt i64 %4, %8
br i1 %9, label %10, label %16
10: ; preds = %3, %7
%11 = phi i64 [ %15, %7 ], [ 0, %3 ]
%12 = getelementptr inbounds i8, i8* %1, i64 %11
%13 = tail call i32 @strncmp(i8* %0, i8* %12, i32 %2)
%14 = icmp eq i32 %13, 0
%15 = add nuw i64 %11, 1
br i1 %14, label %16, label %7
16: ; preds = %10, %7, %3
%17 = phi i32 [ 0, %3 ], [ 0, %7 ], [ 1, %10 ]
ret i32 %17
}