#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 */
typedef int /*<<< orphan*/ X509;

/* Variables and functions */
int /*<<< orphan*/ GEN_DNS;
int do_x509_check(int /*<<< orphan*/ *, char const *, size_t, unsigned int,
                  int /*<<< orphan*/, char **);
scalar_t__ memchr(char const *, char, size_t);
size_t strlen(char const *);
int X509_check_host(X509 *x, const char *chk, size_t chklen, unsigned int flags,
                    char **peername) {
  if (chk == NULL)
    return -2;
  if (chklen == 0)
    chklen = strlen(chk);
  else if (memchr(chk, '\0', chklen))
    return -2;
  return do_x509_check(x, chk, chklen, flags, GEN_DNS, peername);
}


x86 assembly (clang, -O0):
<X509_check_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1162 <X509_check_host+0x32>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11ce <X509_check_host+0x9e>
cmpq   $0x0,-0x20(%rbp)
jne    117f <X509_check_host+0x4f>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
jmp    11a9 <X509_check_host+0x79>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1050 <memchr@plt>
cmp    $0x0,%rax
je     11a4 <X509_check_host+0x74>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11ce <X509_check_host+0x9e>
jmp    11a9 <X509_check_host+0x79>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    0x2e29(%rip),%rax
mov    (%rax),%r8d
mov    -0x30(%rbp),%r9
call   1030 <do_x509_check@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<X509_check_host>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rsi,%rsi
je     1163 <X509_check_host+0x33>
mov    %r8,%r14
mov    %ecx,%r15d
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %rdi,%r12
mov    %rsi,%rdi
test   %rdx,%rdx
je     1171 <X509_check_host+0x41>
xor    %esi,%esi
mov    %rbp,%rdx
call   1050 <memchr@plt>
test   %rax,%rax
je     1179 <X509_check_host+0x49>
mov    $0xfffffffe,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
call   1040 <strlen@plt>
mov    %rax,%rbp
mov    0x2e68(%rip),%rax
mov    (%rax),%r8d
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %r15d,%ecx
mov    %r14,%r9
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <do_x509_check@plt>

LLVM IR (-O0):
@GEN_DNS = global i32 0
define i32 @X509_check_host(i32* %0, i8* %1, i64 %2, i32 %3, i8** %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i8**
store i32* %0, i32** %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i32 %3, i32* %10
store i8** %4, i8*** %11
%12 = load i8*, i8** %8
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %5
store i32 -2, i32* %6
br label %36
15: ; preds = %5
%16 = load i64, i64* %9
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i8*, i8** %8
%20 = call i64 @strlen(i8* %19)
store i64 %20, i64* %9
br label %28
21: ; preds = %15
%22 = load i8*, i8** %8
%23 = load i64, i64* %9
%24 = call i64 @memchr(i8* %22, i8 signext 0, i64 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 -2, i32* %6
br label %36
27: ; preds = %21
br label %28
28: ; preds = %27, %18
%29 = load i32*, i32** %7
%30 = load i8*, i8** %8
%31 = load i64, i64* %9
%32 = load i32, i32* %10
%33 = load i32, i32* @GEN_DNS
%34 = load i8**, i8*** %11
%35 = call i32 @do_x509_check(i32* %29, i8* %30, i64 %31, i32 %32, i32 %33, i8** %34)
store i32 %35, i32* %6
br label %36
36: ; preds = %28, %26, %14
%37 = load i32, i32* %6
ret i32 %37
}

LLVM IR (-O2):
@GEN_DNS = global i32 0
define i32 @X509_check_host(i32* %0, i8* %1, i64 %2, i32 %3, i8** %4) {
%6 = icmp eq i8* %1, null
br i1 %6, label %18, label %7
7: ; preds = %5
%8 = icmp eq i64 %2, 0
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i64 @strlen(i8* %1)
br label %14
11: ; preds = %7
%12 = tail call i64 @memchr(i8* %1, i8 signext 0, i64 %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11, %9
%15 = phi i64 [ %10, %9 ], [ %2, %11 ]
%16 = load i32, i32* @GEN_DNS
%17 = tail call i32 @do_x509_check(i32* %0, i8* %1, i64 %15, i32 %3, i32 %16, i8** %4)
br label %18
18: ; preds = %11, %5, %14
%19 = phi i32 [ %17, %14 ], [ -2, %5 ], [ -2, %11 ]
ret i32 %19
}