#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 const *, char const *, unsigned int);
int r3_memis(const void *_target, unsigned int target_len, const void *_test,
             unsigned int test_len) {
  const char *target = (const char *)_target, *test = (const char *)_test;
  if (target_len != test_len)
    return 0;
  if (target_len == 0)
    return 1;
  if (target[0] != test[0])
    return 0;
  return memcmp(target + 1, test + 1, test_len - 1) == 0;
}


x86 assembly (clang, -O0):
<r3_memis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
je     114e <r3_memis+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <r3_memis+0xa0>
cmpl   $0x0,-0x14(%rbp)
jne    1164 <r3_memis+0x54>
movl   $0x1,-0x4(%rbp)
jmp    11b0 <r3_memis+0xa0>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
mov    -0x38(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1186 <r3_memis+0x76>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <r3_memis+0xa0>
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
mov    -0x38(%rbp),%rsi
add    $0x1,%rsi
mov    -0x24(%rbp),%edx
sub    $0x1,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<r3_memis>:
push   %rax
xor    %eax,%eax
cmp    %ecx,%esi
jne    1146 <r3_memis+0x36>
mov    %esi,%r8d
test   %esi,%esi
je     1148 <r3_memis+0x38>
mov    (%rdi),%cl
cmp    (%rdx),%cl
jne    1146 <r3_memis+0x36>
add    $0x1,%rdi
add    $0x1,%rdx
add    $0xffffffff,%r8d
mov    %rdx,%rsi
mov    %r8d,%edx
call   1030 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
pop    %rcx
ret
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @r3_memis(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%12 = load i8*, i8** %6
store i8* %12, i8** %10
%13 = load i8*, i8** %8
store i8* %13, i8** %11
%14 = load i32, i32* %7
%15 = load i32, i32* %9
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 0, i32* %5
br label %43
18: ; preds = %4
%19 = load i32, i32* %7
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 1, i32* %5
br label %43
22: ; preds = %18
%23 = load i8*, i8** %10
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = load i8*, i8** %11
%28 = getelementptr inbounds i8, i8* %27, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %26, %30
br i1 %31, label %32, label %33
32: ; preds = %22
store i32 0, i32* %5
br label %43
33: ; preds = %22
%34 = load i8*, i8** %10
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8*, i8** %11
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = load i32, i32* %9
%39 = sub i32 %38, 1
%40 = call i64 @memcmp(i8* %35, i8* %37, i32 %39)
%41 = icmp eq i64 %40, 0
%42 = zext i1 %41 to i32
store i32 %42, i32* %5
br label %43
43: ; preds = %33, %32, %21, %17
%44 = load i32, i32* %5
ret i32 %44
}

LLVM IR (-O2):
define i32 @r3_memis(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = icmp eq i32 %1, %3
br i1 %5, label %6, label %19
6: ; preds = %4
%7 = icmp eq i32 %1, 0
br i1 %7, label %19, label %8
8: ; preds = %6
%9 = load i8, i8* %0
%10 = load i8, i8* %2
%11 = icmp eq i8 %9, %10
br i1 %11, label %12, label %19
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %0, i64 1
%14 = getelementptr inbounds i8, i8* %2, i64 1
%15 = add i32 %1, -1
%16 = tail call i64 @memcmp(i8* %13, i8* %14, i32 %15)
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %8, %6, %4, %12
%20 = phi i32 [ %18, %12 ], [ 0, %4 ], [ 1, %6 ], [ 0, %8 ]
ret i32 %20
}