#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 */
typedef size_t uint64_t;

/* Variables and functions */
size_t strlen(char *);
size_t startswith_matches(char *str, char *match) {
  uint64_t i;
  size_t n = strlen(match);
  for (i = 0; i < n && str[i] == match[i]; i++)
    ;
  return i;
}


x86 assembly (clang, -O0):
<startswith_matches>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x20(%rbp),%rcx
mov    %al,-0x21(%rbp)
jae    1168 <startswith_matches+0x58>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1178 <startswith_matches+0x68>
jmp    118e <startswith_matches+0x7e>
jmp    117d <startswith_matches+0x6d>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1135 <startswith_matches+0x25>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<startswith_matches>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     1148 <startswith_matches+0x38>
mov    %rax,%rcx
xor    %eax,%eax
nopl   0x0(%rax)
movzbl (%r14,%rax,1),%edx
cmp    (%rbx,%rax,1),%dl
jne    114a <startswith_matches+0x3a>
add    $0x1,%rax
cmp    %rax,%rcx
jne    1130 <startswith_matches+0x20>
mov    %rcx,%rax
jmp    114a <startswith_matches+0x3a>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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