#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 */
struct cymkd_parser {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ match(struct cymkd_parser *, char);
int strlen(char const *);
int match_string(struct cymkd_parser *parser, const char *str) {
  int i;
  char ch;
  int matched = 0;
  for (i = 0; i < strlen(str); i++) {
    ch = str[i];
    if (!match(parser, ch)) {
      break;
    }
    matched++;
  }
  return matched;
}


x86 assembly (clang, -O0):
<match_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    119a <match_string+0x7a>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
mov    -0x8(%rbp),%rdi
movsbl -0x15(%rbp),%esi
call   1040 <match@plt>
cmp    $0x0,%eax
jne    1183 <match_string+0x63>
jmp    119a <match_string+0x7a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113e <match_string+0x1e>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match_string>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
xor    %ebx,%ebx
test   %eax,%eax
jle    1164 <match_string+0x44>
nopl   0x0(%rax)
movsbl (%r14,%rbx,1),%esi
mov    %r15,%rdi
call   1040 <match@plt>
test   %eax,%eax
je     1164 <match_string+0x44>
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1140 <match_string+0x20>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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