#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 tls_match_name(const char *cert_name, const char *name) {
  const char *cert_domain, *domain, *next_dot;
  if (strcasecmp(cert_name, name) == 0)
    return 0;
  if (cert_name[0] == '*') {
    cert_domain = &cert_name[1];
    if (cert_domain[0] == '\0')
      return -1;
    if (cert_domain[0] != '.')
      return -1;
    if (cert_domain[1] == '.')
      return -1;
    next_dot = strchr(&cert_domain[1], '.');
    if (next_dot == NULL)
      return -1;
    if (next_dot[1] == '.')
      return -1;
    domain = strchr(name, '.');
    if (name[0] == '.')
      return -1;
    if (domain == NULL || strlen(domain) == 1)
      return -1;
    if (strcasecmp(cert_domain, domain) == 0)
      return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<tls_match_name>:
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 <tls_match_name+0x33>
movl   $0x0,-0x4(%rbp)
jmp    12a4 <tls_match_name+0x174>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2a,%eax
jne    129d <tls_match_name+0x16d>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    119b <tls_match_name+0x6b>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a4 <tls_match_name+0x174>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     11b7 <tls_match_name+0x87>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a4 <tls_match_name+0x174>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2e,%eax
jne    11d4 <tls_match_name+0xa4>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a4 <tls_match_name+0x174>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1201 <tls_match_name+0xd1>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a4 <tls_match_name+0x174>
mov    -0x30(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2e,%eax
jne    121e <tls_match_name+0xee>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a4 <tls_match_name+0x174>
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    124c <tls_match_name+0x11c>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a4 <tls_match_name+0x174>
cmpq   $0x0,-0x28(%rbp)
je     1269 <tls_match_name+0x139>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jne    1275 <tls_match_name+0x145>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a4 <tls_match_name+0x174>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1298 <tls_match_name+0x168>
movl   $0x0,-0x4(%rbp)
jmp    12a4 <tls_match_name+0x174>
jmp    129d <tls_match_name+0x16d>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tls_match_name>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %rdi,%rbx
call   1030 <strcasecmp@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     11c2 <tls_match_name+0x92>
cmpb   $0x2a,(%rbx)
jne    11bc <tls_match_name+0x8c>
mov    $0xffffffff,%r14d
cmpb   $0x2e,0x1(%rbx)
jne    11c2 <tls_match_name+0x92>
cmpb   $0x2e,0x2(%rbx)
je     11c2 <tls_match_name+0x92>
lea    0x2(%rbx),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11c2 <tls_match_name+0x92>
cmpb   $0x2e,0x1(%rax)
je     11c2 <tls_match_name+0x92>
mov    %rbp,%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
cmpb   $0x2e,0x0(%rbp)
je     11c2 <tls_match_name+0x92>
mov    %rax,%r15
test   %rax,%rax
je     11c2 <tls_match_name+0x92>
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
je     11c2 <tls_match_name+0x92>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcasecmp@plt>
mov    $0x0,%r14d
test   %rax,%rax
je     11c2 <tls_match_name+0x92>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @tls_match_name(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i64 @strcasecmp(i8* %9, i8* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 0, i32* %3
br label %82
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 42
br i1 %19, label %20, label %81
20: ; preds = %14
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8* %22, i8** %6
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %20
store i32 -1, i32* %3
br label %82
29: ; preds = %20
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i64 0
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 46
br i1 %34, label %35, label %36
35: ; preds = %29
store i32 -1, i32* %3
br label %82
36: ; preds = %29
%37 = load i8*, i8** %6
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 46
br i1 %41, label %42, label %43
42: ; preds = %36
store i32 -1, i32* %3
br label %82
43: ; preds = %36
%44 = load i8*, i8** %6
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = call i8* @strchr(i8* %45, i8 signext 46)
store i8* %46, i8** %8
%47 = load i8*, i8** %8
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %50
49: ; preds = %43
store i32 -1, i32* %3
br label %82
50: ; preds = %43
%51 = load i8*, i8** %8
%52 = getelementptr inbounds i8, i8* %51, i64 1
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 46
br i1 %55, label %56, label %57
56: ; preds = %50
store i32 -1, i32* %3
br label %82
57: ; preds = %50
%58 = load i8*, i8** %5
%59 = call i8* @strchr(i8* %58, i8 signext 46)
store i8* %59, i8** %7
%60 = load i8*, i8** %5
%61 = getelementptr inbounds i8, i8* %60, i64 0
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp eq i32 %63, 46
br i1 %64, label %65, label %66
65: ; preds = %57
store i32 -1, i32* %3
br label %82
66: ; preds = %57
%67 = load i8*, i8** %7
%68 = icmp eq i8* %67, null
br i1 %68, label %73, label %69
69: ; preds = %66
%70 = load i8*, i8** %7
%71 = call i32 @strlen(i8* %70)
%72 = icmp eq i32 %71, 1
br i1 %72, label %73, label %74
73: ; preds = %69, %66
store i32 -1, i32* %3
br label %82
74: ; preds = %69
%75 = load i8*, i8** %6
%76 = load i8*, i8** %7
%77 = call i64 @strcasecmp(i8* %75, i8* %76)
%78 = icmp eq i64 %77, 0
br i1 %78, label %79, label %80
79: ; preds = %74
store i32 0, i32* %3
br label %82
80: ; preds = %74
br label %81
81: ; preds = %80, %14
store i32 -1, i32* %3
br label %82
82: ; preds = %81, %79, %73, %65, %56, %49, %42, %35, %28, %13
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
define i32 @tls_match_name(i8* %0, i8* %1) {
%3 = tail call i64 @strcasecmp(i8* %0, i8* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %36, label %5
5: ; preds = %2
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 42
br i1 %7, label %8, label %35
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 %36
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %0, i64 2
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 46
br i1 %15, label %36, label %16
16: ; preds = %12
%17 = tail call i8* @strchr(i8* %13, i8 signext 46)
%18 = icmp eq i8* %17, null
br i1 %18, label %36, label %19
19: ; preds = %16
%20 = getelementptr inbounds i8, i8* %17, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 46
br i1 %22, label %36, label %23
23: ; preds = %19
%24 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 46)
%25 = load i8, i8* %1
%26 = icmp eq i8 %25, 46
%27 = icmp eq i8* %24, null
%28 = select i1 %26, i1 true, i1 %27
br i1 %28, label %36, label %29
29: ; preds = %23
%30 = tail call i32 @strlen(i8* %24)
%31 = icmp eq i32 %30, 1
br i1 %31, label %36, label %32
32: ; preds = %29
%33 = tail call i64 @strcasecmp(i8* %9, i8* %24)
%34 = icmp eq i64 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %32, %5
br label %36
36: ; preds = %8, %32, %29, %23, %19, %16, %12, %2, %35
%37 = phi i32 [ -1, %35 ], [ 0, %2 ], [ -1, %8 ], [ -1, %12 ], [ -1, %16 ], [ -1, %19 ], [ -1, %23 ], [ -1, %29 ], [ 0, %32 ]
ret i32 %37
}