#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 */
scalar_t__ memcmp(char *, char *, int);
char *sr_formatkey(char *, int /*<<< orphan*/);
int sr_formatkey_size(char *, int /*<<< orphan*/);
__attribute__((hot)) int sr_cmpstring_prefix(char *prefix, int prefixsz,
                                             char *key, int keysz,
                                             void *arg
                                             __attribute__((unused))) {
  keysz = sr_formatkey_size(key, 0);
  key = sr_formatkey(key, 0);
  if (keysz < prefixsz)
    return 0;
  return (memcmp(prefix, key, prefixsz) == 0) ? 1 : 0;
}


x86 assembly (clang, -O0):
<sr_cmpstring_prefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1040 <sr_formatkey_size@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1050 <sr_formatkey@plt>
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    117f <sr_cmpstring_prefix+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    11a3 <sr_cmpstring_prefix+0x73>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <memcmp@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sr_cmpstring_prefix>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %rdi,%r14
xor    %ebp,%ebp
mov    %rdx,%rdi
xor    %esi,%esi
call   1040 <sr_formatkey_size@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <sr_formatkey@plt>
cmp    %r15d,%r12d
jl     10b6 <sr_cmpstring_prefix+0x46>
mov    %r14,%rdi
mov    %rax,%rsi
mov    %r15d,%edx
call   1030 <memcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)

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

LLVM IR (-O2):
define i32 @sr_cmpstring_prefix(i8* %0, i32 %1, i8* %2, i32 %3, i8* nocapture readnone %4) {
%6 = tail call i32 @sr_formatkey_size(i8* %2, i32 0)
%7 = tail call i8* @sr_formatkey(i8* %2, i32 0)
%8 = icmp slt i32 %6, %1
br i1 %8, label %13, label %9
9: ; preds = %5
%10 = tail call i64 @memcmp(i8* %0, i8* %7, i32 %1)
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %5, %9
%14 = phi i32 [ %12, %9 ], [ 0, %5 ]
ret i32 %14
}