#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 *);
scalar_t__ strncmp(char const *, char const *, size_t);
int greatest_name_match(const char *name, const char *filter) {
  size_t offset = 0;
  size_t filter_len = strlen(filter);
  while (name[offset] != '\0') {
    if (name[offset] == filter[0]) {
      if (0 == strncmp(&name[offset], filter, filter_len)) {
        return 1;
      }
    }
    offset++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<greatest_name_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11ba <greatest_name_match+0x9a>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11a9 <greatest_name_match+0x89>
mov    -0x10(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11a4 <greatest_name_match+0x84>
movl   $0x1,-0x4(%rbp)
jmp    11c1 <greatest_name_match+0xa1>
jmp    11a9 <greatest_name_match+0x89>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1145 <greatest_name_match+0x25>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<greatest_name_match>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    0x0(%rbp),%al
xor    %r14d,%r14d
jmp    1148 <greatest_name_match+0x28>
movzbl 0x1(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
je     1169 <greatest_name_match+0x49>
cmp    (%rbx),%al
jne    1140 <greatest_name_match+0x20>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1140 <greatest_name_match+0x20>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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