#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*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *, size_t);
int /*<<< orphan*/ stderr;
size_t strlen(char const *);
scalar_t__ strncmp(char const *, char const *, size_t);
int origin_matches(const char *origin, const char *candidate) {
  if (!origin || !candidate)
    return 0;
  size_t origin_len = strlen(origin);
  size_t candidate_len = strlen(candidate);
  if (candidate_len > 1 && candidate[candidate_len - 1] == '*') {
    if (origin_len < candidate_len)
      return 0;
    fprintf(stderr, "comparing %s to %s len %zu\n", origin, candidate,
            candidate_len);
    return strncmp(origin, candidate, candidate_len - 1) == 0;
  }
  return (origin_len == strlen(candidate) &&
          strncmp(origin, candidate, origin_len) == 0);
}


x86 assembly (clang, -O0):
<origin_matches>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1156 <origin_matches+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1162 <origin_matches+0x32>
movl   $0x0,-0x4(%rbp)
jmp    1250 <origin_matches+0x120>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x1,-0x28(%rbp)
jbe    1204 <origin_matches+0xd4>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2a,%eax
jne    1204 <origin_matches+0xd4>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11ba <origin_matches+0x8a>
movl   $0x0,-0x4(%rbp)
jmp    1250 <origin_matches+0x120>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xe2a(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
sub    $0x1,%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    1250 <origin_matches+0x120>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rcx
mov    %rax,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x29(%rbp)
jne    1245 <origin_matches+0x115>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%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):
<origin_matches>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     11af <origin_matches+0x7f>
mov    %rsi,%r14
test   %rsi,%rsi
je     11af <origin_matches+0x7f>
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%rax
jb     1193 <origin_matches+0x63>
cmpb   $0x2a,-0x1(%r14,%rax,1)
jne    1193 <origin_matches+0x63>
cmp    %rax,%r15
jb     11af <origin_matches+0x7f>
mov    %rax,%r15
add    $0xffffffffffffffff,%r15
mov    0x2e66(%rip),%rcx
mov    (%rcx),%edi
lea    0xe7d(%rip),%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %rax,%r8
call   1050 <fprintf@plt>
jmp    1198 <origin_matches+0x68>
cmp    %rax,%r15
jne    11af <origin_matches+0x7f>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <strncmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"comparing %s to %s len %zu\0A\00"
define i32 @origin_matches(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %10, %2
store i32 0, i32* %3
br label %61
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = call i64 @strlen(i8* %15)
store i64 %16, i64* %6
%17 = load i8*, i8** %5
%18 = call i64 @strlen(i8* %17)
store i64 %18, i64* %7
%19 = load i64, i64* %7
%20 = icmp ugt i64 %19, 1
br i1 %20, label %21, label %47
21: ; preds = %14
%22 = load i8*, i8** %5
%23 = load i64, i64* %7
%24 = sub i64 %23, 1
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 42
br i1 %28, label %29, label %47
29: ; preds = %21
%30 = load i64, i64* %6
%31 = load i64, i64* %7
%32 = icmp ult i64 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 0, i32* %3
br label %61
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %4
%37 = load i8*, i8** %5
%38 = load i64, i64* %7
%39 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %36, i8* %37, i64 %38)
%40 = load i8*, i8** %4
%41 = load i8*, i8** %5
%42 = load i64, i64* %7
%43 = sub i64 %42, 1
%44 = call i64 @strncmp(i8* %40, i8* %41, i64 %43)
%45 = icmp eq i64 %44, 0
%46 = zext i1 %45 to i32
store i32 %46, i32* %3
br label %61
47: ; preds = %21, %14
%48 = load i64, i64* %6
%49 = load i8*, i8** %5
%50 = call i64 @strlen(i8* %49)
%51 = icmp eq i64 %48, %50
br i1 %51, label %52, label %58
52: ; preds = %47
%53 = load i8*, i8** %4
%54 = load i8*, i8** %5
%55 = load i64, i64* %6
%56 = call i64 @strncmp(i8* %53, i8* %54, i64 %55)
%57 = icmp eq i64 %56, 0
br label %58
58: ; preds = %52, %47
%59 = phi i1 [ false, %47 ], [ %57, %52 ]
%60 = zext i1 %59 to i32
store i32 %60, i32* %3
br label %61
61: ; preds = %58, %34, %33, %13
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"comparing %s to %s len %zu\0A\00"
define i32 @origin_matches(i8* %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i8* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %27
6: ; preds = %2
%7 = tail call i64 @strlen(i8* %0)
%8 = tail call i64 @strlen(i8* %1)
%9 = icmp ugt i64 %8, 1
br i1 %9, label %10, label %20
10: ; preds = %6
%11 = add i64 %8, -1
%12 = getelementptr inbounds i8, i8* %1, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 42
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = icmp ult i64 %7, %8
br i1 %16, label %27, label %17
17: ; preds = %15
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i64 %8)
br label %22
20: ; preds = %10, %6
%21 = icmp eq i64 %7, %8
br i1 %21, label %22, label %27
22: ; preds = %20, %17
%23 = phi i64 [ %11, %17 ], [ %7, %20 ]
%24 = tail call i64 @strncmp(i8* %0, i8* %1, i64 %23)
%25 = icmp eq i64 %24, 0
%26 = zext i1 %25 to i32
br label %27
27: ; preds = %22, %15, %20, %2
%28 = phi i32 [ 0, %2 ], [ 0, %15 ], [ 0, %20 ], [ %26, %22 ]
ret i32 %28
}