#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 unsigned char MD4_CTX;

/* Variables and functions */
int /*<<< orphan*/ MD4_Final(unsigned char *, unsigned char *);
int /*<<< orphan*/ MD4_Init(unsigned char *);
int /*<<< orphan*/ MD4_Update(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
unsigned char *nt_unicode(char const *, int);
int strlen(char const *);
void nt_hash_password(unsigned char *hash, const char *pass) {
  int len;
  unsigned char *nt_pw;
  MD4_CTX context;
  len = strlen(pass);
  if ((nt_pw = nt_unicode(pass, len)) == NULL)
    return;
  MD4_Init(&context);
  MD4_Update(&context, nt_pw, 2 * len);
  MD4_Final(hash, &context);
  memset(&context, 0, sizeof context);
  memset(nt_pw, 0, 2 * len);
  free(nt_pw);
}


x86 assembly (clang, -O0):
<nt_hash_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <nt_unicode@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11ab <nt_hash_password+0x3b>
jmp    11fe <nt_hash_password+0x8e>
lea    -0x21(%rbp),%rdi
call   1080 <MD4_Init@plt>
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
shl    $0x1,%edx
lea    -0x21(%rbp),%rdi
call   1070 <MD4_Update@plt>
mov    -0x8(%rbp),%rdi
lea    -0x21(%rbp),%rsi
call   1090 <MD4_Final@plt>
lea    -0x21(%rbp),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1060 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
shl    $0x1,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nt_hash_password>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <nt_unicode@plt>
test   %rax,%rax
je     11e3 <nt_hash_password+0x73>
mov    %rax,%r14
lea    0x7(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <MD4_Init@plt>
add    %ebp,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1070 <MD4_Update@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <MD4_Final@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @nt_hash_password(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %5
%10 = load i8*, i8** %4
%11 = load i32, i32* %5
%12 = call i8* @nt_unicode(i8* %10, i32 %11)
store i8* %12, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %2
br label %30
15: ; preds = %2
%16 = call i32 @MD4_Init(i8* %7)
%17 = load i8*, i8** %6
%18 = load i32, i32* %5
%19 = mul nsw i32 2, %18
%20 = call i32 @MD4_Update(i8* %7, i8* %17, i32 %19)
%21 = load i8*, i8** %3
%22 = call i32 @MD4_Final(i8* %21, i8* %7)
%23 = call i32 @memset(i8* %7, i32 0, i32 1)
%24 = load i8*, i8** %6
%25 = load i32, i32* %5
%26 = mul nsw i32 2, %25
%27 = call i32 @memset(i8* %24, i32 0, i32 %26)
%28 = load i8*, i8** %6
%29 = call i32 @free(i8* %28)
br label %30
30: ; preds = %15, %14
ret void
}

LLVM IR (-O2):
define void @nt_hash_password(i8* %0, i8* %1) {
%3 = alloca i8
%4 = tail call i32 @strlen(i8* %1)
%5 = tail call i8* @nt_unicode(i8* %1, i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %15, label %7
7: ; preds = %2
%8 = call i32 @MD4_Init(i8* %3)
%9 = shl nsw i32 %4, 1
%10 = call i32 @MD4_Update(i8* %3, i8* %5, i32 %9)
%11 = call i32 @MD4_Final(i8* %0, i8* %3)
%12 = call i32 @memset(i8* %3, i32 0, i32 1)
%13 = call i32 @memset(i8* %5, i32 0, i32 %9)
%14 = call i32 @free(i8* %5)
br label %15
15: ; preds = %2, %7
ret void
}