#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 *);
int /*<<< orphan*/ strncmp(char *, char *, size_t);
size_t str_match(char *input, char *match) {
  size_t i_l = strlen(input), m_l = strlen(match);
  size_t i;
  for (i = 0; i < i_l - m_l + 1; i++) {
    if (!strncmp(&input[i], match, m_l)) {
      return i;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<str_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    -0x28(%rbp),%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
jae    11ac <str_match+0x8c>
mov    -0x10(%rbp),%rdi
add    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1196 <str_match+0x76>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b4 <str_match+0x94>
jmp    119b <str_match+0x7b>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1152 <str_match+0x32>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_match>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
sub    %rax,%rbx
mov    $0xffffffffffffffff,%r12
inc    %rbx
je     1181 <str_match+0x61>
mov    %rax,%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%r15,%rbp,1),%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1030 <strncmp@plt>
test   %eax,%eax
je     117e <str_match+0x5e>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1160 <str_match+0x40>
jmp    1181 <str_match+0x61>
mov    %rbp,%r12
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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