#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 int /*<<< orphan*/ MD4_CTX;

/* Variables and functions */
int /*<<< orphan*/ ChallengeResponse(unsigned char *, unsigned char *,
                                     unsigned char *);
int MD4_DIGEST_LENGTH;
int /*<<< orphan*/ MD4_Final(unsigned char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ MD4_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ MD4_Update(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int ChapMS(unsigned char *resp, unsigned char *chl, unsigned char *secret,
           int secret_len) {
  MD4_CTX ctx;
  unsigned char unicode_secret[(256) * 2];
  unsigned char hash[MD4_DIGEST_LENGTH];
  int i;
  memset(unicode_secret, 0, sizeof unicode_secret);
  for (i = 0; i < secret_len; i++)
    unicode_secret[i * 2] = secret[i];
  MD4_Init(&ctx);
  MD4_Update(&ctx, unicode_secret, secret_len * 2);
  MD4_Final(hash, &ctx);
  ChallengeResponse(chl, hash, resp);
  return 0;
}


x86 assembly (clang, -O0):
<ChapMS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x228(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x240(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x230(%rbp)
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1040 <memset@plt>
movl   $0x0,-0x234(%rbp)
mov    -0x234(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ff <ChapMS+0xaf>
mov    -0x18(%rbp),%rax
movslq -0x234(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x234(%rbp),%eax
shl    $0x1,%eax
cltq
mov    %cl,-0x220(%rbp,%rax,1)
mov    -0x234(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x234(%rbp)
jmp    11bc <ChapMS+0x6c>
lea    -0x20(%rbp),%rdi
call   1060 <MD4_Init@plt>
lea    -0x220(%rbp),%rsi
mov    -0x1c(%rbp),%edx
shl    $0x1,%edx
lea    -0x20(%rbp),%rdi
call   1050 <MD4_Update@plt>
mov    -0x240(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <MD4_Final@plt>
mov    -0x240(%rbp),%rsi
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
call   1030 <ChallengeResponse@plt>
mov    -0x228(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ChapMS>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %ecx,%r12d
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,-0x30(%rbp)
mov    %rsp,%r14
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
lea    -0x240(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1040 <memset@plt>
test   %r12d,%r12d
jle    1230 <ChapMS+0xe0>
mov    %r12d,%ecx
lea    -0x1(%rcx),%rdx
mov    %ecx,%esi
and    $0x3,%esi
cmp    $0x3,%rdx
jae    11c0 <ChapMS+0x70>
xor    %edx,%edx
jmp    1208 <ChapMS+0xb8>
and    $0xfffffffc,%ecx
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rbx,%rdx,1),%eax
mov    %al,-0x240(%rbp,%rdx,2)
movzbl 0x1(%rbx,%rdx,1),%eax
mov    %al,-0x23e(%rbp,%rdx,2)
movzbl 0x2(%rbx,%rdx,1),%eax
mov    %al,-0x23c(%rbp,%rdx,2)
movzbl 0x3(%rbx,%rdx,1),%eax
mov    %al,-0x23a(%rbp,%rdx,2)
add    $0x4,%rdx
cmp    %rdx,%rcx
jne    11d0 <ChapMS+0x80>
test   %rsi,%rsi
je     1230 <ChapMS+0xe0>
lea    -0x240(,%rdx,2),%rcx
ff
add    %rbp,%rcx
add    %rdx,%rbx
xor    %edx,%edx
nopl   (%rax)
movzbl (%rbx,%rdx,1),%eax
mov    %al,(%rcx,%rdx,2)
add    $0x1,%rdx
cmp    %rdx,%rsi
jne    1220 <ChapMS+0xd0>
lea    -0x34(%rbp),%rbx
mov    %rbx,%rdi
call   1060 <MD4_Init@plt>
add    %r12d,%r12d
lea    -0x240(%rbp),%rsi
mov    %rbx,%rdi
mov    %r12d,%edx
call   1050 <MD4_Update@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1070 <MD4_Final@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    -0x30(%rbp),%rdx
call   1030 <ChallengeResponse@plt>
mov    %r14,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MD4_DIGEST_LENGTH = global i32 0
define i32 @ChapMS(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [512 x i8]
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%14 = load i32, i32* @MD4_DIGEST_LENGTH
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %11
%17 = alloca i8, i64 %15
store i64 %15, i64* %12
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%19 = call i32 @memset(i8* %18, i32 0, i32 512)
store i32 0, i32* %13
br label %20
20: ; preds = %34, %4
%21 = load i32, i32* %13
%22 = load i32, i32* %8
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %37
24: ; preds = %20
%25 = load i8*, i8** %7
%26 = load i32, i32* %13
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = load i32, i32* %13
%31 = mul nsw i32 %30, 2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 %32
store i8 %29, i8* %33
br label %34
34: ; preds = %24
%35 = load i32, i32* %13
%36 = add nsw i32 %35, 1
store i32 %36, i32* %13
br label %20
37: ; preds = %20
%38 = call i32 @MD4_Init(i32* %9)
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%40 = load i32, i32* %8
%41 = mul nsw i32 %40, 2
%42 = call i32 @MD4_Update(i32* %9, i8* %39, i32 %41)
%43 = call i32 @MD4_Final(i8* %17, i32* %9)
%44 = load i8*, i8** %6
%45 = load i8*, i8** %5
%46 = call i32 @ChallengeResponse(i8* %44, i8* %17, i8* %45)
%47 = load i8*, i8** %11
ret i32 0
}

LLVM IR (-O2):
@MD4_DIGEST_LENGTH = global i32 0
define i32 @ChapMS(i8* %0, i8* %1, i8* nocapture %2, i32 %3) {
%5 = alloca i32
%6 = alloca [512 x i8]
%7 = bitcast i32* %5 to i8*
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%9 = load i32, i32* @MD4_DIGEST_LENGTH
%10 = zext i32 %9 to i64
%11 = tail call i8* @llvm.stacksave()
%12 = alloca i8, i64 %10
%13 = call i32 @memset(i8* %8, i32 0, i32 512)
%14 = icmp sgt i32 %3, 0
br i1 %14, label %15, label %60
15: ; preds = %4
%16 = zext i32 %3 to i64
%17 = add nsw i64 %16, -1
%18 = and i64 %16, 3
%19 = icmp ult i64 %17, 3
br i1 %19, label %47, label %20
20: ; preds = %15
%21 = and i64 %16, 4294967292
br label %22
22: ; preds = %22, %20
%23 = phi i64 [ 0, %20 ], [ %44, %22 ]
%24 = phi i64 [ 0, %20 ], [ %45, %22 ]
%25 = getelementptr inbounds i8, i8* %2, i64 %23
%26 = load i8, i8* %25
%27 = shl nuw nsw i64 %23, 1
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %27
store i8 %26, i8* %28
%29 = or i64 %23, 1
%30 = getelementptr inbounds i8, i8* %2, i64 %29
%31 = load i8, i8* %30
%32 = shl nuw nsw i64 %29, 1
%33 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %32
store i8 %31, i8* %33
%34 = or i64 %23, 2
%35 = getelementptr inbounds i8, i8* %2, i64 %34
%36 = load i8, i8* %35
%37 = shl nuw nsw i64 %34, 1
%38 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %37
store i8 %36, i8* %38
%39 = or i64 %23, 3
%40 = getelementptr inbounds i8, i8* %2, i64 %39
%41 = load i8, i8* %40
%42 = shl nuw nsw i64 %39, 1
%43 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %42
store i8 %41, i8* %43
%44 = add nuw nsw i64 %23, 4
%45 = add i64 %24, 4
%46 = icmp eq i64 %45, %21
br i1 %46, label %47, label %22
47: ; preds = %22, %15
%48 = phi i64 [ 0, %15 ], [ %44, %22 ]
%49 = icmp eq i64 %18, 0
br i1 %49, label %60, label %50
50: ; preds = %47, %50
%51 = phi i64 [ %57, %50 ], [ %48, %47 ]
%52 = phi i64 [ %58, %50 ], [ 0, %47 ]
%53 = getelementptr inbounds i8, i8* %2, i64 %51
%54 = load i8, i8* %53
%55 = shl nuw nsw i64 %51, 1
%56 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %55
store i8 %54, i8* %56
%57 = add nuw nsw i64 %51, 1
%58 = add i64 %52, 1
%59 = icmp eq i64 %58, %18
br i1 %59, label %60, label %50
60: ; preds = %47, %50, %4
%61 = call i32 @MD4_Init(i32* %5)
%62 = shl nsw i32 %3, 1
%63 = call i32 @MD4_Update(i32* %5, i8* %8, i32 %62)
%64 = call i32 @MD4_Final(i8* %12, i32* %5)
%65 = call i32 @ChallengeResponse(i8* %1, i8* %12, i8* %0)
ret i32 0
}