#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__ strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, scalar_t__);
int str_compare_func(void *key1, void *key2) {
  char *k1 = (char *)key1;
  char *k2 = (char *)key2;
  if (strlen(k1) == strlen(k2) && !strncmp(k1, k2, strlen(k1))) {
    return 0;
  } else {
    return -1;
  }
}


x86 assembly (clang, -O0):
<str_compare_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
jne    11a4 <str_compare_func+0x84>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11a4 <str_compare_func+0x84>
movl   $0x0,-0x4(%rbp)
jmp    11ab <str_compare_func+0x8b>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_compare_func>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %rax,%rbx
jne    1152 <str_compare_func+0x32>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1159 <str_compare_func+0x39>
mov    $0xffffffff,%eax
jmp    115b <str_compare_func+0x3b>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @str_compare_func(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = icmp eq i64 %3, %4
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @strncmp(i8* %0, i8* %1, i64 %3)
%8 = icmp eq i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %6, %2
br label %10
10: ; preds = %6, %9
%11 = phi i32 [ -1, %9 ], [ 0, %6 ]
ret i32 %11
}