#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__ strcasecmp(char const *, char const *);
char *strchr(char const *, char);
int strlen(char const *);
int ressl_match_hostname(const char *cert_hostname, const char *hostname) {
  const char *cert_domain, *domain;
  if (strcasecmp(cert_hostname, hostname) == 0)
    return 0;
  if (cert_hostname[0] == '*') {
    cert_domain = &cert_hostname[1];
    if (cert_domain[0] != '.')
      return -1;
    if (strlen(cert_domain) == 1)
      return -1;
    domain = strchr(hostname, '.');
    if (domain == NULL || strlen(domain) == 1)
      return -1;
    if (strcasecmp(cert_domain, domain) == 0)
      return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<ressl_match_hostname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1163 <ressl_match_hostname+0x33>
movl   $0x0,-0x4(%rbp)
jmp    1223 <ressl_match_hostname+0xf3>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2a,%eax
jne    121c <ressl_match_hostname+0xec>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     119b <ressl_match_hostname+0x6b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1223 <ressl_match_hostname+0xf3>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jne    11b9 <ressl_match_hostname+0x89>
movl   $0xffffffff,-0x4(%rbp)
jmp    1223 <ressl_match_hostname+0xf3>
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11e8 <ressl_match_hostname+0xb8>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jne    11f4 <ressl_match_hostname+0xc4>
movl   $0xffffffff,-0x4(%rbp)
jmp    1223 <ressl_match_hostname+0xf3>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1217 <ressl_match_hostname+0xe7>
movl   $0x0,-0x4(%rbp)
jmp    1223 <ressl_match_hostname+0xf3>
jmp    121c <ressl_match_hostname+0xec>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ressl_match_hostname>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
mov    %rdi,%rbx
call   1030 <strcasecmp@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     11a7 <ressl_match_hostname+0x77>
cmpb   $0x2a,(%rbx)
jne    11a1 <ressl_match_hostname+0x71>
mov    $0xffffffff,%r14d
cmpb   $0x2e,0x1(%rbx)
jne    11a7 <ressl_match_hostname+0x77>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
je     11a7 <ressl_match_hostname+0x77>
mov    %rbp,%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11a7 <ressl_match_hostname+0x77>
mov    %rax,%rbp
mov    %rax,%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
je     11a7 <ressl_match_hostname+0x77>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <strcasecmp@plt>
mov    $0x0,%r14d
test   %rax,%rax
je     11a7 <ressl_match_hostname+0x77>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ressl_match_hostname(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
%9 = load i8*, i8** %5
%10 = call i64 @strcasecmp(i8* %8, i8* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %51
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 42
br i1 %18, label %19, label %50
19: ; preds = %13
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 1
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 46
br i1 %26, label %27, label %28
27: ; preds = %19
store i32 -1, i32* %3
br label %51
28: ; preds = %19
%29 = load i8*, i8** %6
%30 = call i32 @strlen(i8* %29)
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 -1, i32* %3
br label %51
33: ; preds = %28
%34 = load i8*, i8** %5
%35 = call i8* @strchr(i8* %34, i8 signext 46)
store i8* %35, i8** %7
%36 = load i8*, i8** %7
%37 = icmp eq i8* %36, null
br i1 %37, label %42, label %38
38: ; preds = %33
%39 = load i8*, i8** %7
%40 = call i32 @strlen(i8* %39)
%41 = icmp eq i32 %40, 1
br i1 %41, label %42, label %43
42: ; preds = %38, %33
store i32 -1, i32* %3
br label %51
43: ; preds = %38
%44 = load i8*, i8** %6
%45 = load i8*, i8** %7
%46 = call i64 @strcasecmp(i8* %44, i8* %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %43
store i32 0, i32* %3
br label %51
49: ; preds = %43
br label %50
50: ; preds = %49, %13
store i32 -1, i32* %3
br label %51
51: ; preds = %50, %48, %42, %32, %27, %12
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
define i32 @ressl_match_hostname(i8* %0, i8* %1) {
%3 = tail call i64 @strcasecmp(i8* %0, i8* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %25, label %5
5: ; preds = %2
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 42
br i1 %7, label %8, label %24
8: ; preds = %5
%9 = getelementptr inbounds i8, i8* %0, i64 1
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 46
br i1 %11, label %12, label %25
12: ; preds = %8
%13 = tail call i32 @strlen(i8* %9)
%14 = icmp eq i32 %13, 1
br i1 %14, label %25, label %15
15: ; preds = %12
%16 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 46)
%17 = icmp eq i8* %16, null
br i1 %17, label %25, label %18
18: ; preds = %15
%19 = tail call i32 @strlen(i8* %16)
%20 = icmp eq i32 %19, 1
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = tail call i64 @strcasecmp(i8* %9, i8* %16)
%23 = icmp eq i64 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %21, %5
br label %25
25: ; preds = %21, %15, %18, %12, %8, %2, %24
%26 = phi i32 [ -1, %24 ], [ 0, %2 ], [ -1, %8 ], [ -1, %12 ], [ -1, %18 ], [ -1, %15 ], [ 0, %21 ]
ret i32 %26
}