#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 min(int, int);
int ntlibc_strlen(char const *);
int matches_filter(const char *valueToTest, const char *filter) {
  int value_len = ntlibc_strlen(valueToTest);
  if (value_len == 0) {
    return 0;
  }
  int filter_len = ntlibc_strlen(filter);
  if (filter_len == 0) {
    return 1;
  }
  if (filter_len > value_len) {
    return 0;
  }
  int smallest_len = min(value_len, filter_len);
  int i;
  for (i = 0; i < smallest_len; ++i) {
    if (valueToTest[i] != filter[i]) {
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<matches_filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ntlibc_strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1152 <matches_filter+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <matches_filter+0xd3>
mov    -0x18(%rbp),%rdi
call   1030 <ntlibc_strlen@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    1174 <matches_filter+0x54>
movl   $0x1,-0x4(%rbp)
jmp    11f3 <matches_filter+0xd3>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    118c <matches_filter+0x6c>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <matches_filter+0xd3>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1040 <min@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11ec <matches_filter+0xcc>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
movslq -0x28(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     11d9 <matches_filter+0xb9>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <matches_filter+0xd3>
jmp    11de <matches_filter+0xbe>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11a1 <matches_filter+0x81>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matches_filter>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <ntlibc_strlen@plt>
xor    %r15d,%r15d
test   %eax,%eax
je     1179 <matches_filter+0x59>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <ntlibc_strlen@plt>
test   %eax,%eax
je     1173 <matches_filter+0x53>
cmp    %ebp,%eax
jg     1179 <matches_filter+0x59>
mov    %ebp,%edi
mov    %eax,%esi
call   1040 <min@plt>
test   %eax,%eax
jle    1173 <matches_filter+0x53>
mov    %eax,%eax
xor    %r15d,%r15d
xor    %ecx,%ecx
nop
movzbl (%rbx,%rcx,1),%edx
cmp    (%r14,%rcx,1),%dl
jne    1179 <matches_filter+0x59>
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1160 <matches_filter+0x40>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @matches_filter(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = call i32 @ntlibc_strlen(i8* %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 0, i32* %3
br label %54
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = call i32 @ntlibc_strlen(i8* %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 1, i32* %3
br label %54
21: ; preds = %15
%22 = load i32, i32* %7
%23 = load i32, i32* %6
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 0, i32* %3
br label %54
26: ; preds = %21
%27 = load i32, i32* %6
%28 = load i32, i32* %7
%29 = call i32 @min(i32 %27, i32 %28)
store i32 %29, i32* %8
store i32 0, i32* %9
br label %30
30: ; preds = %50, %26
%31 = load i32, i32* %9
%32 = load i32, i32* %8
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %53
34: ; preds = %30
%35 = load i8*, i8** %4
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = load i8*, i8** %5
%42 = load i32, i32* %9
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %40, %46
br i1 %47, label %48, label %49
48: ; preds = %34
store i32 0, i32* %3
br label %54
49: ; preds = %34
br label %50
50: ; preds = %49
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
br label %30
53: ; preds = %30
store i32 1, i32* %3
br label %54
54: ; preds = %53, %48, %25, %20, %14
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
define i32 @matches_filter(i8* %0, i8* %1) {
%3 = tail call i32 @ntlibc_strlen(i8* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %25, label %5
5: ; preds = %2
%6 = tail call i32 @ntlibc_strlen(i8* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %25, label %8
8: ; preds = %5
%9 = icmp sgt i32 %6, %3
br i1 %9, label %25, label %10
10: ; preds = %8
%11 = tail call i32 @min(i32 %3, i32 %6)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %10
%14 = zext i32 %11 to i64
br label %17
15: ; preds = %17
%16 = icmp eq i64 %24, %14
br i1 %16, label %25, label %17
17: ; preds = %13, %15
%18 = phi i64 [ 0, %13 ], [ %24, %15 ]
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = getelementptr inbounds i8, i8* %1, i64 %18
%22 = load i8, i8* %21
%23 = icmp eq i8 %20, %22
%24 = add nuw nsw i64 %18, 1
br i1 %23, label %15, label %25
25: ; preds = %17, %15, %10, %5, %8, %2
%26 = phi i32 [ 0, %2 ], [ 1, %5 ], [ 0, %8 ], [ 1, %10 ], [ 0, %17 ], [ 1, %15 ]
ret i32 %26
}