#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 */
int /*<<< orphan*/ iswildcard(char);
int binary_cmp_with_wildcards(void *mem1, void *mem2, size_t n) {
  char *block1, *block2;
  block1 = mem1;
  block2 = mem2;
  while (n) {
    if (!iswildcard(*block2)) {
      if (*block1 != *block2)
        return *block1 - *block2;
    }
    block1++;
    block2++;
    n--;
  }
  return 0;
}


x86 assembly (clang, -O0):
<binary_cmp_with_wildcards>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b0 <binary_cmp_with_wildcards+0xa0>
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1030 <iswildcard@plt>
cmp    $0x0,%eax
jne    1187 <binary_cmp_with_wildcards+0x77>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
mov    -0x30(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1182 <binary_cmp_with_wildcards+0x72>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
mov    -0x30(%rbp),%rcx
movsbl (%rcx),%ecx
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11b7 <binary_cmp_with_wildcards+0xa7>
jmp    1187 <binary_cmp_with_wildcards+0x77>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1134 <binary_cmp_with_wildcards+0x24>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binary_cmp_with_wildcards>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     1159 <binary_cmp_with_wildcards+0x49>
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
xor    %ebx,%ebx
jmp    1139 <binary_cmp_with_wildcards+0x29>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r14
je     1159 <binary_cmp_with_wildcards+0x49>
movsbl (%r12,%rbx,1),%edi
call   1030 <iswildcard@plt>
test   %eax,%eax
jne    1130 <binary_cmp_with_wildcards+0x20>
movsbl (%r15,%rbx,1),%eax
movsbl (%r12,%rbx,1),%ecx
cmp    %cl,%al
je     1130 <binary_cmp_with_wildcards+0x20>
sub    %ecx,%eax
jmp    115b <binary_cmp_with_wildcards+0x4b>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @binary_cmp_with_wildcards(i8* nocapture %0, i8* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %25, label %5
5: ; preds = %3, %20
%6 = phi i8* [ %22, %20 ], [ %1, %3 ]
%7 = phi i8* [ %21, %20 ], [ %0, %3 ]
%8 = phi i64 [ %23, %20 ], [ %2, %3 ]
%9 = load i8, i8* %6
%10 = tail call i32 @iswildcard(i8 signext %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %5
%13 = load i8, i8* %7
%14 = load i8, i8* %6
%15 = icmp eq i8 %13, %14
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = sext i8 %14 to i32
%18 = sext i8 %13 to i32
%19 = sub nsw i32 %18, %17
br label %25
20: ; preds = %12, %5
%21 = getelementptr inbounds i8, i8* %7, i64 1
%22 = getelementptr inbounds i8, i8* %6, i64 1
%23 = add i64 %8, -1
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %5
25: ; preds = %20, %3, %16
%26 = phi i32 [ %19, %16 ], [ 0, %3 ], [ 0, %20 ]
ret i32 %26
}