#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 *);
scalar_t__ strncmp(char *, char *, size_t);
int compare_cmd(char *str, char *cmd) {
  char c;
  if (strncmp(str, cmd, strlen(cmd)) != 0)
    return -1;
  c = str[strlen(cmd)];
  if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<compare_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     116f <compare_cmd+0x4f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d4 <compare_cmd+0xb4>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x41,%eax
jl     11a7 <compare_cmd+0x87>
movsbl -0x19(%rbp),%eax
cmp    $0x5a,%eax
jle    11c1 <compare_cmd+0xa1>
movsbl -0x19(%rbp),%eax
cmp    $0x61,%eax
jl     11cd <compare_cmd+0xad>
movsbl -0x19(%rbp),%eax
cmp    $0x7a,%eax
jg     11cd <compare_cmd+0xad>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d4 <compare_cmd+0xb4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_cmd>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    1161 <compare_cmd+0x41>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    (%r14,%rax,1),%al
and    $0xdf,%al
add    $0xbf,%al
cmp    $0x1a,%al
sbb    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @compare_cmd(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = tail call i64 @strncmp(i8* %0, i8* %1, i64 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %2
%7 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = and i8 %9, -33
%11 = add i8 %10, -65
%12 = icmp ult i8 %11, 26
%13 = sext i1 %12 to i32
br label %14
14: ; preds = %6, %2
%15 = phi i32 [ -1, %2 ], [ %13, %6 ]
ret i32 %15
}