#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  scalar_t__ length;
  scalar_t__ data;
};
typedef TYPE_1__ ASN1_IA5STRING;

/* Variables and functions */
int X509_V_ERR_PERMITTED_VIOLATION;
int X509_V_OK;
scalar_t__ strcasecmp(char *, char *);
int nc_dns(ASN1_IA5STRING *dns, ASN1_IA5STRING *base) {
  char *baseptr = (char *)base->data;
  char *dnsptr = (char *)dns->data;
  if (!*baseptr)
    return X509_V_OK;
  if (dns->length > base->length) {
    dnsptr += dns->length - base->length;
    if (dnsptr[-1] != '.')
      return X509_V_ERR_PERMITTED_VIOLATION;
  }
  if (strcasecmp(baseptr, dnsptr))
    return X509_V_ERR_PERMITTED_VIOLATION;
  return X509_V_OK;
}


x86 assembly (clang, -O0):
<nc_dns>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1156 <nc_dns+0x46>
mov    0x2eac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11db <nc_dns+0xcb>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jle    11a7 <nc_dns+0x97>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
sub    (%rcx),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x2e,%eax
je     11a2 <nc_dns+0x92>
mov    0x2e48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11db <nc_dns+0xcb>
jmp    11a7 <nc_dns+0x97>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
je     11cf <nc_dns+0xbf>
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11db <nc_dns+0xcb>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nc_dns>:
push   %rax
mov    %rdi,%rcx
mov    0x8(%rsi),%rdi
cmpb   $0x0,(%rdi)
je     1140 <nc_dns+0x30>
mov    %rsi,%rax
mov    0x8(%rcx),%rsi
mov    (%rcx),%rcx
sub    (%rax),%rcx
jle    1136 <nc_dns+0x26>
cmpb   $0x2e,-0x1(%rsi,%rcx,1)
jne    1149 <nc_dns+0x39>
add    %rcx,%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
jne    1149 <nc_dns+0x39>
mov    0x2eb1(%rip),%rax
jmp    1150 <nc_dns+0x40>
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i64, i64 }
@X509_V_OK = global i32 0
@X509_V_ERR_PERMITTED_VIOLATION = global i32 0
define i32 @nc_dns(%struct.TYPE_4__* %0, %struct.TYPE_4__* %1) {
%3 = alloca i32
%4 = alloca %struct.TYPE_4__*
%5 = alloca %struct.TYPE_4__*
%6 = alloca i8*
%7 = alloca i8*
store %struct.TYPE_4__* %0, %struct.TYPE_4__** %4
store %struct.TYPE_4__* %1, %struct.TYPE_4__** %5
%8 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%9 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %8, i32 0, i32 1
%10 = load i64, i64* %9
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %6
%12 = load %struct.TYPE_4__*, %struct.TYPE_4__** %4
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %12, i32 0, i32 1
%14 = load i64, i64* %13
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %7
%16 = load i8*, i8** %6
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %2
%20 = load i32, i32* @X509_V_OK
store i32 %20, i32* %3
br label %56
21: ; preds = %2
%22 = load %struct.TYPE_4__*, %struct.TYPE_4__** %4
%23 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %22, i32 0, i32 0
%24 = load i64, i64* %23
%25 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%26 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %25, i32 0, i32 0
%27 = load i64, i64* %26
%28 = icmp sgt i64 %24, %27
br i1 %28, label %29, label %47
29: ; preds = %21
%30 = load %struct.TYPE_4__*, %struct.TYPE_4__** %4
%31 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %30, i32 0, i32 0
%32 = load i64, i64* %31
%33 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%34 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %33, i32 0, i32 0
%35 = load i64, i64* %34
%36 = sub nsw i64 %32, %35
%37 = load i8*, i8** %7
%38 = getelementptr inbounds i8, i8* %37, i64 %36
store i8* %38, i8** %7
%39 = load i8*, i8** %7
%40 = getelementptr inbounds i8, i8* %39, i64 -1
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 46
br i1 %43, label %44, label %46
44: ; preds = %29
%45 = load i32, i32* @X509_V_ERR_PERMITTED_VIOLATION
store i32 %45, i32* %3
br label %56
46: ; preds = %29
br label %47
47: ; preds = %46, %21
%48 = load i8*, i8** %6
%49 = load i8*, i8** %7
%50 = call i64 @strcasecmp(i8* %48, i8* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %47
%53 = load i32, i32* @X509_V_ERR_PERMITTED_VIOLATION
store i32 %53, i32* %3
br label %56
54: ; preds = %47
%55 = load i32, i32* @X509_V_OK
store i32 %55, i32* %3
br label %56
56: ; preds = %54, %52, %44, %19
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i64, i64 }
@X509_V_OK = global i32 0
@X509_V_ERR_PERMITTED_VIOLATION = global i32 0
define i32 @nc_dns(%struct.TYPE_4__* nocapture %0, %struct.TYPE_4__* nocapture %1) {
%3 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %1, i64 0, i32 1
%4 = load i64, i64* %3
%5 = inttoptr i64 %4 to i8*
%6 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 1
%7 = load i64, i64* %6
%8 = inttoptr i64 %7 to i8*
%9 = load i8, i8* %5
%10 = icmp eq i8 %9, 0
br i1 %10, label %28, label %11
11: ; preds = %2
%12 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 0
%13 = load i64, i64* %12
%14 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %1, i64 0, i32 0
%15 = load i64, i64* %14
%16 = icmp sgt i64 %13, %15
br i1 %16, label %17, label %23
17: ; preds = %11
%18 = sub nsw i64 %13, %15
%19 = getelementptr inbounds i8, i8* %8, i64 %18
%20 = getelementptr inbounds i8, i8* %19, i64 -1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 46
br i1 %22, label %23, label %28
23: ; preds = %17, %11
%24 = phi i8* [ %19, %17 ], [ %8, %11 ]
%25 = tail call i64 @strcasecmp(i8* %5, i8* %24)
%26 = icmp eq i64 %25, 0
%27 = select i1 %26, i32* @X509_V_OK, i32* @X509_V_ERR_PERMITTED_VIOLATION
br label %28
28: ; preds = %23, %17, %2
%29 = phi i32* [ @X509_V_OK, %2 ], [ @X509_V_ERR_PERMITTED_VIOLATION, %17 ], [ %27, %23 ]
%30 = load i32, i32* %29
ret i32 %30
}