#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 (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    1288 <tls_match_name+0x158>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2a,%eax
jne    1281 <tls_match_name+0x151>
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    1288 <tls_match_name+0x158>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     11b7 <tls_match_name+0x87>
movl   $0xffffffff,-0x4(%rbp)
jmp    1288 <tls_match_name+0x158>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2e,%eax
jne    11d4 <tls_match_name+0xa4>
movl   $0xffffffff,-0x4(%rbp)
jmp    1288 <tls_match_name+0x158>
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    1288 <tls_match_name+0x158>
mov    -0x30(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2e,%eax
jne    121e <tls_match_name+0xee>
movl   $0xffffffff,-0x4(%rbp)
jmp    1288 <tls_match_name+0x158>
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     124d <tls_match_name+0x11d>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jne    1259 <tls_match_name+0x129>
movl   $0xffffffff,-0x4(%rbp)
jmp    1288 <tls_match_name+0x158>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    127c <tls_match_name+0x14c>
movl   $0x0,-0x4(%rbp)
jmp    1288 <tls_match_name+0x158>
jmp    1281 <tls_match_name+0x151>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tls_match_name>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
mov    %rdi,%rbx
call   1030 <strcasecmp@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     11b9 <tls_match_name+0x89>
cmpb   $0x2a,(%rbx)
jne    11b3 <tls_match_name+0x83>
mov    $0xffffffff,%r14d
cmpb   $0x2e,0x1(%rbx)
jne    11b9 <tls_match_name+0x89>
cmpb   $0x2e,0x2(%rbx)
je     11b9 <tls_match_name+0x89>
lea    0x2(%rbx),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11b9 <tls_match_name+0x89>
cmpb   $0x2e,0x1(%rax)
je     11b9 <tls_match_name+0x89>
mov    %rbp,%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11b9 <tls_match_name+0x89>
mov    %rax,%rbp
mov    %rax,%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
je     11b9 <tls_match_name+0x89>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <strcasecmp@plt>
mov    $0x0,%r14d
test   %rax,%rax
je     11b9 <tls_match_name+0x89>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
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 %75
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 %74
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 %75
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 %75
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 %75
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 %75
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 %75
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** %7
%61 = icmp eq i8* %60, null
br i1 %61, label %66, label %62
62: ; preds = %57
%63 = load i8*, i8** %7
%64 = call i32 @strlen(i8* %63)
%65 = icmp eq i32 %64, 1
br i1 %65, label %66, label %67
66: ; preds = %62, %57
store i32 -1, i32* %3
br label %75
67: ; preds = %62
%68 = load i8*, i8** %6
%69 = load i8*, i8** %7
%70 = call i64 @strcasecmp(i8* %68, i8* %69)
%71 = icmp eq i64 %70, 0
br i1 %71, label %72, label %73
72: ; preds = %67
store i32 0, i32* %3
br label %75
73: ; preds = %67
br label %74
74: ; preds = %73, %14
store i32 -1, i32* %3
br label %75
75: ; preds = %74, %72, %66, %56, %49, %42, %35, %28, %13
%76 = load i32, i32* %3
ret i32 %76
}

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 %33, label %5
5: ; preds = %2
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 42
br i1 %7, label %8, label %32
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 %33
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 %33, 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 %33, 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 %33, label %23
23: ; preds = %19
%24 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 46)
%25 = icmp eq i8* %24, null
br i1 %25, label %33, label %26
26: ; preds = %23
%27 = tail call i32 @strlen(i8* %24)
%28 = icmp eq i32 %27, 1
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = tail call i64 @strcasecmp(i8* %9, i8* %24)
%31 = icmp eq i64 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %29, %5
br label %33
33: ; preds = %8, %29, %23, %26, %19, %16, %12, %2, %32
%34 = phi i32 [ -1, %32 ], [ 0, %2 ], [ -1, %8 ], [ -1, %12 ], [ -1, %16 ], [ -1, %19 ], [ -1, %26 ], [ -1, %23 ], [ 0, %29 ]
ret i32 %34
}