#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 char uint8_t;

/* Variables and functions */
int /*<<< orphan*/ EVP_md5();
int /*<<< orphan*/ HMAC(int /*<<< orphan*/, char const *, int, char *, size_t,
                        char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ abort();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ safe_free(char *);
char *safe_malloc_internal(size_t, char *, int);
int /*<<< orphan*/ stderr;
size_t strlen(char const *);
scalar_t__ unicode_alloc_upper(char *);
void ntlmv2_create_hash(const uint8_t ntlm[16], const char *username,
                        const char *domain, uint8_t hash[16]) {
  size_t username_length = strlen(username);
  size_t domain_length = strlen(domain);
  char *combined;
  uint8_t *combined_unicode;
  if (username_length > 256 || domain_length > 256) {
    fprintf(
        stderr, "Unrecoverable error in %s(%d): %s\n\n",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/iagox86/nbtool/refs/heads/master/crypto.c",
        143, "username or domain too long.");
    abort();
  };
  combined = safe_malloc_internal(
      username_length + domain_length + 1,
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/iagox86/nbtool/refs/heads/master/crypto.c",
      146);
  memset(combined, 0, username_length + domain_length + 1);
  memcpy(combined, username, username_length);
  memcpy(combined + username_length, domain, domain_length);
  combined_unicode = (uint8_t *)unicode_alloc_upper(combined);
  if (!combined_unicode) {
    {
      fprintf(
          stderr, "Unrecoverable error in %s(%d): %s\n\n",
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/iagox86/nbtool/refs/heads/master/crypto.c",
          155, "Out of memory.");
      abort();
    };
  };
  HMAC(EVP_md5(), ntlm, 16, combined_unicode,
       (username_length + domain_length) * 2, hash, NULL);
  safe_free(combined_unicode);
  safe_free(combined);
}


x86 assembly (clang, -O0):
<ntlmv2_create_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x100,-0x28(%rbp)
ja     11ee <ntlmv2_create_hash+0x4e>
cmpq   $0x100,-0x30(%rbp)
jbe    121d <ntlmv2_create_hash+0x7d>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
lea    0xe02(%rip),%rsi
lea    0xe1f(%rip),%rdx
mov    $0x8f,%ecx
lea    0xe97(%rip),%r8
call   1080 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x28(%rbp),%rdi
add    -0x30(%rbp),%rdi
add    $0x1,%rdi
lea    0xdf4(%rip),%rsi
mov    $0x92,%edx
call   1070 <safe_malloc_internal@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rdx
add    -0x30(%rbp),%rdx
add    $0x1,%rdx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1090 <memcpy@plt>
mov    -0x38(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1090 <memcpy@plt>
mov    -0x38(%rbp),%rdi
call   10b0 <unicode_alloc_upper@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    12c2 <ntlmv2_create_hash+0x122>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
lea    0xd5d(%rip),%rsi
lea    0xd7a(%rip),%rdx
mov    $0x9b,%ecx
lea    0xe0f(%rip),%r8
call   1080 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    $0x0,%al
call   1040 <EVP_md5@plt>
mov    %eax,%edi
mov    -0x8(%rbp),%rsi
mov    -0x40(%rbp),%rcx
mov    -0x28(%rbp),%r8
add    -0x30(%rbp),%r8
shl    $0x1,%r8
mov    -0x20(%rbp),%r9
mov    $0x10,%edx
xor    %eax,%eax
movq   $0x0,(%rsp)
call   10a0 <HMAC@plt>
mov    -0x40(%rbp),%rdi
call   10c0 <safe_free@plt>
mov    -0x38(%rbp),%rdi
call   10c0 <safe_free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ntlmv2_create_hash>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,0x10(%rsp)
mov    %rdx,%rbp
mov    %rsi,%r14
mov    %rdi,0x8(%rsp)
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %rax,%r13
mov    %rbp,%rdi
call   1050 <strlen@plt>
cmp    $0x100,%r13
ja     1295 <ntlmv2_create_hash+0xf5>
mov    %rax,%rbx
cmp    $0x101,%rax
jae    1295 <ntlmv2_create_hash+0xf5>
lea    (%rbx,%r13,1),%r15
add    $0x1,%r15
lea    0xe28(%rip),%rsi
mov    %r15,%rdi
mov    $0x92,%edx
call   1070 <safe_malloc_internal@plt>
mov    %rax,%r12
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1060 <memset@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1090 <memcpy@plt>
lea    (%r12,%r13,1),%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1090 <memcpy@plt>
mov    %r12,%rdi
call   10b0 <unicode_alloc_upper@plt>
test   %rax,%rax
je     12ba <ntlmv2_create_hash+0x11a>
mov    %rax,%rbp
add    %r13,%rbx
xor    %eax,%eax
call   1040 <EVP_md5@plt>
add    %rbx,%rbx
movq   $0x0,(%rsp)
mov    %eax,%edi
mov    0x8(%rsp),%rsi
mov    $0x10,%edx
mov    %rbp,%rcx
mov    %rbx,%r8
mov    0x10(%rsp),%r9
call   10a0 <HMAC@plt>
mov    %rbp,%rdi
call   10c0 <safe_free@plt>
mov    %r12,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10c0 <safe_free@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
lea    0xd5b(%rip),%rsi
lea    0xd78(%rip),%rdx
lea    0xdf5(%rip),%r8
mov    $0x8f,%ecx
jmp    12dd <ntlmv2_create_hash+0x13d>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
lea    0xd36(%rip),%rsi
lea    0xd53(%rip),%rdx
lea    0xded(%rip),%r8
mov    $0x9b,%ecx
call   1080 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"Unrecoverable error in %s(%d): %s\0A\0A\00"
@.str.1 = [132 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/iagox86/nbtool/refs/heads/master/crypto.c\00"
@.str.2 = [29 x i8] c"username or domain too long.\00"
@.str.3 = [15 x i8] c"Out of memory.\00"
define void @ntlmv2_create_hash(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%13 = load i8*, i8** %6
%14 = call i64 @strlen(i8* %13)
store i64 %14, i64* %9
%15 = load i8*, i8** %7
%16 = call i64 @strlen(i8* %15)
store i64 %16, i64* %10
%17 = load i64, i64* %9
%18 = icmp ugt i64 %17, 256
br i1 %18, label %22, label %19
19: ; preds = %4
%20 = load i64, i64* %10
%21 = icmp ugt i64 %20, 256
br i1 %21, label %22, label %26
22: ; preds = %19, %4
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.1, i64 0, i64 0), i32 143, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 (...) @abort()
unreachable
26: ; preds = %19
%27 = load i64, i64* %9
%28 = load i64, i64* %10
%29 = add i64 %27, %28
%30 = add i64 %29, 1
%31 = call i8* @safe_malloc_internal(i64 %30, i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.1, i64 0, i64 0), i32 146)
store i8* %31, i8** %11
%32 = load i8*, i8** %11
%33 = load i64, i64* %9
%34 = load i64, i64* %10
%35 = add i64 %33, %34
%36 = add i64 %35, 1
%37 = call i32 @memset(i8* %32, i32 0, i64 %36)
%38 = load i8*, i8** %11
%39 = load i8*, i8** %6
%40 = load i64, i64* %9
%41 = call i32 @memcpy(i8* %38, i8* %39, i64 %40)
%42 = load i8*, i8** %11
%43 = load i64, i64* %9
%44 = getelementptr inbounds i8, i8* %42, i64 %43
%45 = load i8*, i8** %7
%46 = load i64, i64* %10
%47 = call i32 @memcpy(i8* %44, i8* %45, i64 %46)
%48 = load i8*, i8** %11
%49 = call i64 @unicode_alloc_upper(i8* %48)
%50 = inttoptr i64 %49 to i8*
store i8* %50, i8** %12
%51 = load i8*, i8** %12
%52 = icmp ne i8* %51, null
br i1 %52, label %57, label %53
53: ; preds = %26
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.1, i64 0, i64 0), i32 155, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%56 = call i32 (...) @abort()
unreachable
57: ; preds = %26
%58 = call i32 (...) @EVP_md5()
%59 = load i8*, i8** %5
%60 = load i8*, i8** %12
%61 = load i64, i64* %9
%62 = load i64, i64* %10
%63 = add i64 %61, %62
%64 = mul i64 %63, 2
%65 = load i8*, i8** %8
%66 = call i32 @HMAC(i32 %58, i8* %59, i32 16, i8* %60, i64 %64, i8* %65, i32* null)
%67 = load i8*, i8** %12
%68 = call i32 @safe_free(i8* %67)
%69 = load i8*, i8** %11
%70 = call i32 @safe_free(i8* %69)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"Unrecoverable error in %s(%d): %s\0A\0A\00"
@.str.1 = [132 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/iagox86/nbtool/refs/heads/master/crypto.c\00"
@.str.2 = [29 x i8] c"username or domain too long.\00"
@.str.3 = [15 x i8] c"Out of memory.\00"
define void @ntlmv2_create_hash(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%7 = icmp ugt i64 %5, 256
%8 = icmp ugt i64 %6, 256
%9 = select i1 %7, i1 true, i1 %8
br i1 %9, label %10, label %14
10: ; preds = %4
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.1, i64 0, i64 0), i32 143, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 (...) @abort()
unreachable
14: ; preds = %4
%15 = add nuw nsw i64 %6, %5
%16 = add nuw nsw i64 %15, 1
%17 = tail call i8* @safe_malloc_internal(i64 %16, i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.1, i64 0, i64 0), i32 146)
%18 = tail call i32 @memset(i8* %17, i32 0, i64 %16)
%19 = tail call i32 @memcpy(i8* %17, i8* %1, i64 %5)
%20 = getelementptr inbounds i8, i8* %17, i64 %5
%21 = tail call i32 @memcpy(i8* %20, i8* %2, i64 %6)
%22 = tail call i64 @unicode_alloc_upper(i8* %17)
%23 = inttoptr i64 %22 to i8*
%24 = icmp eq i64 %22, 0
br i1 %24, label %25, label %29
25: ; preds = %14
%26 = load i32, i32* @stderr
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.1, i64 0, i64 0), i32 155, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%28 = tail call i32 (...) @abort()
unreachable
29: ; preds = %14
%30 = tail call i32 (...) @EVP_md5()
%31 = shl nuw nsw i64 %15, 1
%32 = tail call i32 @HMAC(i32 %30, i8* %0, i32 16, i8* %23, i64 %31, i8* %3, i32* null)
%33 = tail call i32 @safe_free(i8* %23)
%34 = tail call i32 @safe_free(i8* %17)
ret void
}