#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 */
struct s_map {
  int dummy;
};

/* Variables and functions */
unsigned char *mapGet(struct s_map *, unsigned char *);
int /*<<< orphan*/ mapGetKeyByID(struct s_map *, int);
int mapGetKeySize(struct s_map *);
unsigned char *mapGetN(struct s_map *, unsigned char *, int);
int mapGetPrefixID(struct s_map *, unsigned char *, int);
scalar_t__ memcmp(unsigned char *, int /*<<< orphan*/, int);
int mapTestsuiteRWDPrefixCheck(struct s_map *map, unsigned char *keys,
                               int *states, int nr) {
  int key_size = mapGetKeySize(map);
  unsigned char *kptr = &keys[nr * key_size];
  unsigned char *sptr;
  int i, j;
  if (states[nr]) {
    for (i = 0; i <= key_size; i++) {
      j = mapGetPrefixID(map, kptr, i);
      if (j < 0)
        return 0;
      if (memcmp(kptr, mapGetKeyByID(map, j), i) != 0)
        return 0;
    }
    return 1;
  } else {
    sptr = mapGet(map, kptr);
    if (sptr == NULL) {
      sptr = mapGetN(map, kptr, key_size);
      if (sptr == NULL) {
        return 1;
      } else {
        return 0;
      }
    } else {
      return 1;
    }
  }
}


x86 assembly (clang, -O0):
<mapTestsuiteRWDPrefixCheck>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <mapGetKeySize@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x28(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     123d <mapTestsuiteRWDPrefixCheck+0xdd>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jg     1231 <mapTestsuiteRWDPrefixCheck+0xd1>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   1060 <mapGetPrefixID@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    11e6 <mapTestsuiteRWDPrefixCheck+0x86>
movl   $0x0,-0x4(%rbp)
jmp    1297 <mapTestsuiteRWDPrefixCheck+0x137>
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%esi
call   1040 <mapGetKeyByID@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
mov    -0x3c(%rbp),%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
je     121e <mapTestsuiteRWDPrefixCheck+0xbe>
movl   $0x0,-0x4(%rbp)
jmp    1297 <mapTestsuiteRWDPrefixCheck+0x137>
jmp    1223 <mapTestsuiteRWDPrefixCheck+0xc3>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11b1 <mapTestsuiteRWDPrefixCheck+0x51>
movl   $0x1,-0x4(%rbp)
jmp    1297 <mapTestsuiteRWDPrefixCheck+0x137>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <mapGet@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1290 <mapTestsuiteRWDPrefixCheck+0x130>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1050 <mapGetN@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1284 <mapTestsuiteRWDPrefixCheck+0x124>
movl   $0x1,-0x4(%rbp)
jmp    1297 <mapTestsuiteRWDPrefixCheck+0x137>
movl   $0x0,-0x4(%rbp)
jmp    1297 <mapTestsuiteRWDPrefixCheck+0x137>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mapTestsuiteRWDPrefixCheck>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%r12
call   1080 <mapGetKeySize@plt>
mov    %eax,%r14d
imul   %ebx,%eax
movslq %eax,%rbp
add    %r13,%rbp
movslq %ebx,%rax
cmpl   $0x0,(%r15,%rax,4)
je     11e6 <mapTestsuiteRWDPrefixCheck+0x86>
mov    $0x1,%r15d
test   %r14d,%r14d
js     1219 <mapTestsuiteRWDPrefixCheck+0xb9>
add    $0x1,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1060 <mapGetPrefixID@plt>
test   %eax,%eax
js     1216 <mapTestsuiteRWDPrefixCheck+0xb6>
mov    %r12,%rdi
mov    %eax,%esi
call   1040 <mapGetKeyByID@plt>
mov    %rbp,%rdi
mov    %eax,%esi
mov    %ebx,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
jne    1216 <mapTestsuiteRWDPrefixCheck+0xb6>
add    $0x1,%ebx
cmp    %ebx,%r14d
jne    11b0 <mapTestsuiteRWDPrefixCheck+0x50>
jmp    1219 <mapTestsuiteRWDPrefixCheck+0xb9>
mov    %r12,%rdi
mov    %rbp,%rsi
call   1070 <mapGet@plt>
mov    $0x1,%r15d
test   %rax,%rax
jne    1219 <mapTestsuiteRWDPrefixCheck+0xb9>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1050 <mapGetN@plt>
xor    %r15d,%r15d
test   %rax,%rax
sete   %r15b
jmp    1219 <mapTestsuiteRWDPrefixCheck+0xb9>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.s_map = type { i32 }
define i32 @mapTestsuiteRWDPrefixCheck(%struct.s_map* %0, i8* %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.s_map*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
store %struct.s_map* %0, %struct.s_map** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
%15 = load %struct.s_map*, %struct.s_map** %6
%16 = call i32 @mapGetKeySize(%struct.s_map* %15)
store i32 %16, i32* %10
%17 = load i8*, i8** %7
%18 = load i32, i32* %9
%19 = load i32, i32* %10
%20 = mul nsw i32 %18, %19
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %17, i64 %21
store i8* %22, i8** %11
%23 = load i32*, i32** %8
%24 = load i32, i32* %9
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %56
29: ; preds = %4
store i32 0, i32* %13
br label %30
30: ; preds = %52, %29
%31 = load i32, i32* %13
%32 = load i32, i32* %10
%33 = icmp sle i32 %31, %32
br i1 %33, label %34, label %55
34: ; preds = %30
%35 = load %struct.s_map*, %struct.s_map** %6
%36 = load i8*, i8** %11
%37 = load i32, i32* %13
%38 = call i32 @mapGetPrefixID(%struct.s_map* %35, i8* %36, i32 %37)
store i32 %38, i32* %14
%39 = load i32, i32* %14
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %34
store i32 0, i32* %5
br label %72
42: ; preds = %34
%43 = load i8*, i8** %11
%44 = load %struct.s_map*, %struct.s_map** %6
%45 = load i32, i32* %14
%46 = call i32 @mapGetKeyByID(%struct.s_map* %44, i32 %45)
%47 = load i32, i32* %13
%48 = call i64 @memcmp(i8* %43, i32 %46, i32 %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %42
store i32 0, i32* %5
br label %72
51: ; preds = %42
br label %52
52: ; preds = %51
%53 = load i32, i32* %13
%54 = add nsw i32 %53, 1
store i32 %54, i32* %13
br label %30
55: ; preds = %30
store i32 1, i32* %5
br label %72
56: ; preds = %4
%57 = load %struct.s_map*, %struct.s_map** %6
%58 = load i8*, i8** %11
%59 = call i8* @mapGet(%struct.s_map* %57, i8* %58)
store i8* %59, i8** %12
%60 = load i8*, i8** %12
%61 = icmp eq i8* %60, null
br i1 %61, label %62, label %71
62: ; preds = %56
%63 = load %struct.s_map*, %struct.s_map** %6
%64 = load i8*, i8** %11
%65 = load i32, i32* %10
%66 = call i8* @mapGetN(%struct.s_map* %63, i8* %64, i32 %65)
store i8* %66, i8** %12
%67 = load i8*, i8** %12
%68 = icmp eq i8* %67, null
br i1 %68, label %69, label %70
69: ; preds = %62
store i32 1, i32* %5
br label %72
70: ; preds = %62
store i32 0, i32* %5
br label %72
71: ; preds = %56
store i32 1, i32* %5
br label %72
72: ; preds = %71, %70, %69, %55, %50, %41
%73 = load i32, i32* %5
ret i32 %73
}

LLVM IR (-O2):
%struct.s_map = type { i32 }
define i32 @mapTestsuiteRWDPrefixCheck(%struct.s_map* %0, i8* %1, i32* nocapture %2, i32 %3) {
%5 = tail call i32 @mapGetKeySize(%struct.s_map* %0)
%6 = mul nsw i32 %5, %3
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = sext i32 %3 to i64
%10 = getelementptr inbounds i32, i32* %2, i64 %9
%11 = load i32, i32* %10
%12 = icmp eq i32 %11, 0
br i1 %12, label %26, label %13
13: ; preds = %4
%14 = icmp slt i32 %5, 0
br i1 %14, label %33, label %18
15: ; preds = %22
%16 = add nuw i32 %19, 1
%17 = icmp eq i32 %19, %5
br i1 %17, label %33, label %18
18: ; preds = %13, %15
%19 = phi i32 [ %16, %15 ], [ 0, %13 ]
%20 = tail call i32 @mapGetPrefixID(%struct.s_map* %0, i8* %8, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %33, label %22
22: ; preds = %18
%23 = tail call i32 @mapGetKeyByID(%struct.s_map* %0, i32 %20)
%24 = tail call i64 @memcmp(i8* %8, i32 %23, i32 %19)
%25 = icmp eq i64 %24, 0
br i1 %25, label %15, label %33
26: ; preds = %4
%27 = tail call i8* @mapGet(%struct.s_map* %0, i8* %8)
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = tail call i8* @mapGetN(%struct.s_map* %0, i8* %8, i32 %5)
%31 = icmp eq i8* %30, null
%32 = zext i1 %31 to i32
br label %33
33: ; preds = %18, %22, %15, %13, %26, %29
%34 = phi i32 [ %32, %29 ], [ 1, %26 ], [ 1, %13 ], [ 0, %18 ], [ 0, %22 ], [ 1, %15 ]
ret i32 %34
}