#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 strlen(char const *);
scalar_t__ strncasecmp(char const *, char const *, int);
int matchkeyword(const char *cp, const char *kw, int min) {
  int i;
  for (i = strlen(kw); i >= min; i--)
    if (strncasecmp(cp, kw, i) == 0)
      return (i);
  return (0);
}


x86 assembly (clang, -O0):
<matchkeyword>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     1183 <matchkeyword+0x63>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%rax
jne    1170 <matchkeyword+0x50>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118a <matchkeyword+0x6a>
jmp    1175 <matchkeyword+0x55>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    113f <matchkeyword+0x1f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matchkeyword>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
xor    %r14d,%r14d
cmp    %r12d,%eax
jl     1171 <matchkeyword+0x51>
mov    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <strncasecmp@plt>
test   %rax,%rax
je     116e <matchkeyword+0x4e>
lea    -0x1(%rbp),%eax
cmp    %r12d,%ebp
mov    %eax,%ebp
jg     1150 <matchkeyword+0x30>
jmp    1171 <matchkeyword+0x51>
mov    %ebp,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @matchkeyword(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %6
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %8
br label %11
11: ; preds = %24, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %7
%14 = icmp sge i32 %12, %13
br i1 %14, label %15, label %27
15: ; preds = %11
%16 = load i8*, i8** %5
%17 = load i8*, i8** %6
%18 = load i32, i32* %8
%19 = call i64 @strncasecmp(i8* %16, i8* %17, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = load i32, i32* %8
store i32 %22, i32* %4
br label %28
23: ; preds = %15
br label %24
24: ; preds = %23
%25 = load i32, i32* %8
%26 = add nsw i32 %25, -1
store i32 %26, i32* %8
br label %11
27: ; preds = %11
store i32 0, i32* %4
br label %28
28: ; preds = %27, %21
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
define i32 @matchkeyword(i8* nocapture %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = icmp slt i32 %4, %2
br i1 %5, label %13, label %6
6: ; preds = %3, %10
%7 = phi i32 [ %11, %10 ], [ %4, %3 ]
%8 = tail call i64 @strncasecmp(i8* %0, i8* %1, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = add nsw i32 %7, -1
%12 = icmp sgt i32 %7, %2
br i1 %12, label %6, label %13
13: ; preds = %6, %10, %3
%14 = phi i32 [ 0, %3 ], [ 0, %10 ], [ %7, %6 ]
ret i32 %14
}