#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 */
struct tls {
  int dummy;
};
typedef int /*<<< orphan*/ X509;

/* Variables and functions */
int tls_check_common_name(struct tls *, int /*<<< orphan*/ *, char const *);
int tls_check_subject_altname(struct tls *, int /*<<< orphan*/ *, char const *);
int tls_check_servername(struct tls *ctx, X509 *cert, const char *servername) {
  int rv;
  rv = tls_check_subject_altname(ctx, cert, servername);
  if (rv == 0 || rv == -2)
    return rv;
  return tls_check_common_name(ctx, cert, servername);
}


x86 assembly (clang, -O0):
<tls_check_servername>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <tls_check_subject_altname@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     115c <tls_check_servername+0x3c>
cmpl   $0xfffffffe,-0x24(%rbp)
jne    1167 <tls_check_servername+0x47>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    117b <tls_check_servername+0x5b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <tls_check_common_name@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tls_check_servername>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1030 <tls_check_subject_altname@plt>
cmp    $0xfffffffe,%eax
je     113c <tls_check_servername+0x1c>
test   %eax,%eax
jne    1142 <tls_check_servername+0x22>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <tls_check_common_name@plt>

LLVM IR (-O0):
%struct.tls = type { i32 }
define i32 @tls_check_servername(%struct.tls* %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.tls*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
store %struct.tls* %0, %struct.tls** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
%9 = load %struct.tls*, %struct.tls** %5
%10 = load i32*, i32** %6
%11 = load i8*, i8** %7
%12 = call i32 @tls_check_subject_altname(%struct.tls* %9, i32* %10, i8* %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %3
%16 = load i32, i32* %8
%17 = icmp eq i32 %16, -2
br i1 %17, label %18, label %20
18: ; preds = %15, %3
%19 = load i32, i32* %8
store i32 %19, i32* %4
br label %25
20: ; preds = %15
%21 = load %struct.tls*, %struct.tls** %5
%22 = load i32*, i32** %6
%23 = load i8*, i8** %7
%24 = call i32 @tls_check_common_name(%struct.tls* %21, i32* %22, i8* %23)
store i32 %24, i32* %4
br label %25
25: ; preds = %20, %18
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
%struct.tls = type { i32 }
define i32 @tls_check_servername(%struct.tls* %0, i32* %1, i8* %2) {
%4 = tail call i32 @tls_check_subject_altname(%struct.tls* %0, i32* %1, i8* %2)
switch i32 %4, label %5 [
i32 -2, label %7
i32 0, label %7
]
5: ; preds = %3
%6 = tail call i32 @tls_check_common_name(%struct.tls* %0, i32* %1, i8* %2)
br label %7
7: ; preds = %3, %3, %5
%8 = phi i32 [ %6, %5 ], [ %4, %3 ], [ %4, %3 ]
ret i32 %8
}