#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 (baseptr[0] != '.' && 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    11eb <nc_dns+0xdb>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jle    11b7 <nc_dns+0xa7>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
sub    (%rcx),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     11b2 <nc_dns+0xa2>
mov    -0x28(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x2e,%eax
je     11b2 <nc_dns+0xa2>
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11eb <nc_dns+0xdb>
jmp    11b7 <nc_dns+0xa7>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
je     11df <nc_dns+0xcf>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11eb <nc_dns+0xdb>
mov    0x2e12(%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
mov    (%rdi),%dl
test   %dl,%dl
je     1145 <nc_dns+0x35>
mov    %rsi,%rax
mov    0x8(%rcx),%rsi
mov    (%rcx),%rcx
sub    (%rax),%rcx
jle    113b <nc_dns+0x2b>
add    %rcx,%rsi
cmp    $0x2e,%dl
je     113b <nc_dns+0x2b>
cmpb   $0x2e,-0x1(%rsi)
jne    114e <nc_dns+0x3e>
call   1030 <strcasecmp@plt>
test   %rax,%rax
jne    114e <nc_dns+0x3e>
mov    0x2eac(%rip),%rax
jmp    1155 <nc_dns+0x45>
mov    0x2e8b(%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 %62
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 %53
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** %6
%40 = getelementptr inbounds i8, i8* %39, i64 0
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 46
br i1 %43, label %44, label %52
44: ; preds = %29
%45 = load i8*, i8** %7
%46 = getelementptr inbounds i8, i8* %45, i64 -1
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 46
br i1 %49, label %50, label %52
50: ; preds = %44
%51 = load i32, i32* @X509_V_ERR_PERMITTED_VIOLATION
store i32 %51, i32* %3
br label %62
52: ; preds = %44, %29
br label %53
53: ; preds = %52, %21
%54 = load i8*, i8** %6
%55 = load i8*, i8** %7
%56 = call i64 @strcasecmp(i8* %54, i8* %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %53
%59 = load i32, i32* @X509_V_ERR_PERMITTED_VIOLATION
store i32 %59, i32* %3
br label %62
60: ; preds = %53
%61 = load i32, i32* @X509_V_OK
store i32 %61, i32* %3
br label %62
62: ; preds = %60, %58, %50, %19
%63 = load i32, i32* %3
ret i32 %63
}

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 %30, 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 %25
17: ; preds = %11
%18 = sub nsw i64 %13, %15
%19 = getelementptr inbounds i8, i8* %8, i64 %18
%20 = icmp eq i8 %9, 46
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = getelementptr inbounds i8, i8* %19, i64 -1
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 46
br i1 %24, label %25, label %30
25: ; preds = %17, %21, %11
%26 = phi i8* [ %19, %21 ], [ %19, %17 ], [ %8, %11 ]
%27 = tail call i64 @strcasecmp(i8* %5, i8* %26)
%28 = icmp eq i64 %27, 0
%29 = select i1 %28, i32* @X509_V_OK, i32* @X509_V_ERR_PERMITTED_VIOLATION
br label %30
30: ; preds = %25, %21, %2
%31 = phi i32* [ @X509_V_OK, %2 ], [ @X509_V_ERR_PERMITTED_VIOLATION, %21 ], [ %29, %25 ]
%32 = load i32, i32* %31
ret i32 %32
}