#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 *);
int /*<<< orphan*/ strncasecmp(char *, char *, int);
int matchcmd(char *command, char *prototype, int len) {
  int lp, lc, lm;
  lp = strlen(prototype);
  lp = (lp < len ? lp : len);
  lc = strlen(command);
  lm = (lc > lp ? lc : lp);
  return (!strncasecmp(command, prototype, lm));
}


x86 assembly (clang, -O0):
<matchcmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1156 <matchcmd+0x36>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    115c <matchcmd+0x3c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1185 <matchcmd+0x65>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    118b <matchcmd+0x6b>
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matchcmd>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
cmp    %ebx,%eax
cmovl  %eax,%ebx
mov    %r15,%rdi
call   1030 <strlen@plt>
cmp    %ebx,%eax
cmovg  %eax,%ebx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <strncasecmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @matchcmd(i8* %0, i8* %1, i32 %2) {
%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
store i32 %2, i32* %6
%10 = load i8*, i8** %5
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = load i32, i32* %7
br label %19
17: ; preds = %3
%18 = load i32, i32* %6
br label %19
19: ; preds = %17, %15
%20 = phi i32 [ %16, %15 ], [ %18, %17 ]
store i32 %20, i32* %7
%21 = load i8*, i8** %4
%22 = call i32 @strlen(i8* %21)
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = load i32, i32* %7
%25 = icmp sgt i32 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = load i32, i32* %8
br label %30
28: ; preds = %19
%29 = load i32, i32* %7
br label %30
30: ; preds = %28, %26
%31 = phi i32 [ %27, %26 ], [ %29, %28 ]
store i32 %31, i32* %9
%32 = load i8*, i8** %4
%33 = load i8*, i8** %5
%34 = load i32, i32* %9
%35 = call i32 @strncasecmp(i8* %32, i8* %33, i32 %34)
%36 = icmp ne i32 %35, 0
%37 = xor i1 %36, true
%38 = zext i1 %37 to i32
ret i32 %38
}

LLVM IR (-O2):
define i32 @matchcmd(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = icmp slt i32 %4, %2
%6 = select i1 %5, i32 %4, i32 %2
%7 = tail call i32 @strlen(i8* %0)
%8 = icmp sgt i32 %7, %6
%9 = select i1 %8, i32 %7, i32 %6
%10 = tail call i32 @strncasecmp(i8* %0, i8* %1, i32 %9)
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
ret i32 %12
}