#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 strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int MatchString(char *str, char *substr) {
  int LenDiff;
  int Cnt;
  LenDiff = strlen(str) - strlen(substr);
  for (Cnt = 0; Cnt < LenDiff + 1; Cnt++) {
    if (!strncmp(str + Cnt, substr, strlen(substr))) {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<MatchString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11be <MatchString+0x9e>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11ab <MatchString+0x8b>
movl   $0x1,-0x4(%rbp)
jmp    11c5 <MatchString+0xa5>
jmp    11b0 <MatchString+0x90>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1156 <MatchString+0x36>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MatchString>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
xor    %r15d,%r15d
sub    %eax,%ebp
jl     117b <MatchString+0x5b>
add    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1175 <MatchString+0x55>
add    $0x1,%rbx
add    $0xffffffffffffffff,%rbp
jne    1150 <MatchString+0x30>
jmp    117b <MatchString+0x5b>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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