#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 */
int NS_MAXDNAME;
scalar_t__ ns_makecanon(char const *, char *, int);
scalar_t__ strcasecmp(char *, char *);
int ns_samename(const char *a, const char *b) {
  char ta[NS_MAXDNAME], tb[NS_MAXDNAME];
  if (ns_makecanon(a, ta, sizeof ta) < 0 || ns_makecanon(b, tb, sizeof tb) < 0)
    return (-1);
  if (strcasecmp(ta, tb) == 0)
    return (1);
  else
    return (0);
}


x86 assembly (clang, -O0):
<ns_samename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2eb1(%rip),%rcx
mov    (%rcx),%eax
mov    %rsp,%rdx
mov    %rdx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rsi
sub    %rdx,%rsi
mov    %rsi,-0x50(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x28(%rbp)
mov    (%rcx),%ecx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rdi
add    $0xf,%rdi
and    $0xfffffffffffffff0,%rdi
mov    %rsp,%rdx
sub    %rdi,%rdx
mov    %rdx,-0x40(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    %eax,%edx
call   1040 <ns_makecanon@plt>
cmp    $0x0,%rax
jl     11b0 <ns_samename+0x90>
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rax
mov    -0x18(%rbp),%rdi
mov    %eax,%edx
call   1040 <ns_makecanon@plt>
cmp    $0x0,%rax
jge    11c3 <ns_samename+0xa3>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    11fb <ns_samename+0xdb>
mov    -0x40(%rbp),%rsi
mov    -0x50(%rbp),%rdi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11ed <ns_samename+0xcd>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    11fb <ns_samename+0xdb>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ns_samename>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x2eb0(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%r12
mov    %r15,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r12,%rsi
mov    %r15d,%edx
call   1040 <ns_makecanon@plt>
mov    $0xffffffff,%r13d
test   %rax,%rax
js     1196 <ns_samename+0x76>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1040 <ns_makecanon@plt>
test   %rax,%rax
js     1196 <ns_samename+0x76>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <strcasecmp@plt>
xor    %r13d,%r13d
test   %rax,%rax
sete   %r13b
mov    %r13d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@NS_MAXDNAME = global i32 0
define i32 @ns_samename(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i32, i32* @NS_MAXDNAME
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i8, i64 %11
store i64 %11, i64* %7
%14 = load i32, i32* @NS_MAXDNAME
%15 = zext i32 %14 to i64
%16 = alloca i8, i64 %15
store i64 %15, i64* %8
%17 = load i8*, i8** %4
%18 = trunc i64 %11 to i32
%19 = call i64 @ns_makecanon(i8* %17, i8* %13, i32 %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %2
%22 = load i8*, i8** %5
%23 = trunc i64 %15 to i32
%24 = call i64 @ns_makecanon(i8* %22, i8* %16, i32 %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21, %2
store i32 -1, i32* %3
store i32 1, i32* %9
br label %32
27: ; preds = %21
%28 = call i64 @strcasecmp(i8* %13, i8* %16)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 1, i32* %3
store i32 1, i32* %9
br label %32
31: ; preds = %27
store i32 0, i32* %3
store i32 1, i32* %9
br label %32
32: ; preds = %31, %30, %26
%33 = load i8*, i8** %6
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@NS_MAXDNAME = global i32 0
define i32 @ns_samename(i8* %0, i8* %1) {
%3 = load i32, i32* @NS_MAXDNAME
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = alloca i8, i64 %4
%7 = call i64 @ns_makecanon(i8* %0, i8* %5, i32 %3)
%8 = icmp slt i64 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %2
%10 = call i64 @ns_makecanon(i8* %1, i8* %6, i32 %3)
%11 = icmp slt i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = call i64 @strcasecmp(i8* %5, i8* %6)
%14 = icmp eq i64 %13, 0
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %12, %2, %9
%17 = phi i32 [ -1, %9 ], [ -1, %2 ], [ %15, %12 ]
ret i32 %17
}