#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 _namehash(char *);
int /*<<< orphan*/ jdns_free(char *);
char *jdns_strdup(char const *);
int strlen(char *);
char tolower(char);
int _namehash_nocase(const char *s) {
  int n, len;
  char *low = jdns_strdup(s);
  len = strlen(low);
  for (n = 0; n < len; ++n)
    low[n] = tolower(low[n]);
  n = _namehash(low);
  jdns_free(low);
  return n;
}


x86 assembly (clang, -O0):
<_namehash_nocase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <jdns_strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11b4 <_namehash_nocase+0x64>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <tolower@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117c <_namehash_nocase+0x2c>
mov    -0x18(%rbp),%rdi
call   1060 <_namehash@plt>
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <jdns_free@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_namehash_nocase>:
push   %rbp
push   %r14
push   %rbx
call   1040 <jdns_strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1185 <_namehash_nocase+0x35>
mov    %eax,%r14d
xor    %ebp,%ebp
nopl   (%rax)
movsbl (%rbx,%rbp,1),%edi
call   1050 <tolower@plt>
mov    %al,(%rbx,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1170 <_namehash_nocase+0x20>
mov    %rbx,%rdi
call   1060 <_namehash@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <jdns_free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @_namehash_nocase(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i8* @jdns_strdup(i8* %6)
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %4
store i32 0, i32* %3
br label %10
10: ; preds = %25, %1
%11 = load i32, i32* %3
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %28
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = call signext i8 @tolower(i8 signext %19)
%21 = load i8*, i8** %5
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 %20, i8* %24
br label %25
25: ; preds = %14
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %10
28: ; preds = %10
%29 = load i8*, i8** %5
%30 = call i32 @_namehash(i8* %29)
store i32 %30, i32* %3
%31 = load i8*, i8** %5
%32 = call i32 @jdns_free(i8* %31)
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
define i32 @_namehash_nocase(i8* %0) {
%2 = tail call i8* @jdns_strdup(i8* %0)
%3 = tail call i32 @strlen(i8* %2)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %1
%6 = zext i32 %3 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %12, %7 ]
%9 = getelementptr inbounds i8, i8* %2, i64 %8
%10 = load i8, i8* %9
%11 = tail call signext i8 @tolower(i8 signext %10)
store i8 %11, i8* %9
%12 = add nuw nsw i64 %8, 1
%13 = icmp eq i64 %12, %6
br i1 %13, label %14, label %7
14: ; preds = %7, %1
%15 = tail call i32 @_namehash(i8* %2)
%16 = tail call i32 @jdns_free(i8* %2)
ret i32 %15
}