int GenerateCrypt(char *szUser, char *szPassword, char *szChallenge64,
                  long clientinfo, long embkey, char *szResult) {
  unsigned char szDecoded[256];
  unsigned char szKey[256];
  unsigned char szAscii[256];
  unsigned int nDecodedLen;
  long challengetime = 0;
  int nMoveBits;
  long challengetime_new = 0;
  long a, b, c, d;
  unsigned int nKey;
  int nUser;
  unsigned int nEncoded;
  nDecodedLen = lutil_b64_pton(szChallenge64, szDecoded, 256);
  memcpy(&challengetime, szDecoded + 6, 4);
  challengetime |= ~embkey;
  nMoveBits = challengetime % 30;
  a = challengetime << ((32 - nMoveBits) % 32);
  b = challengetime >> (((unsigned int)nMoveBits) % 32);
  c = ~(0xffffffff << ((32 - nMoveBits) % 32));
  d = b & c;
  challengetime_new = a | d;
  nKey = KeyMD5Encode(szKey, (unsigned char *)szPassword,
                      strlen((char *)szPassword), (unsigned char *)szDecoded,
                      nDecodedLen);
  szKey[nKey] = 0;
  nUser = strlen((char *)szUser);
  memcpy(szAscii, szUser, nUser);
  szAscii[nUser] = ' ';
  memcpy(szAscii + nUser + 1, &challengetime_new, 4);
  memcpy(szAscii + nUser + 1 + 4, &clientinfo, 4);
  memcpy(szAscii + nUser + 1 + 4 + 4, szKey, nKey);
  nEncoded = lutil_b64_ntop((unsigned char *)szAscii, nUser + 1 + 4 + 4 + nKey,
                            szResult, 256);
  return nEncoded;
}


x86 assembly (clang, -O0):
<GenerateCrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3a0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movq   $0x0,-0x340(%rbp)
movq   $0x0,-0x350(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x130(%rbp),%rsi
mov    $0x100,%edx
mov    $0x0,%al
call   1040 <lutil_b64_pton@plt>
mov    %eax,-0x334(%rbp)
mov    -0x12a(%rbp),%eax
mov    %eax,-0x340(%rbp)
mov    -0x28(%rbp),%rax
xor    $0xffffffffffffffff,%rax
or     -0x340(%rbp),%rax
mov    %rax,-0x340(%rbp)
mov    -0x340(%rbp),%rax
mov    $0x1e,%ecx
cqto
idiv   %rcx
mov    %edx,%eax
mov    %eax,-0x344(%rbp)
mov    -0x340(%rbp),%rax
mov    %rax,-0x398(%rbp)
mov    $0x20,%eax
sub    -0x344(%rbp),%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
mov    -0x398(%rbp),%rax
mov    %edx,%ecx
shl    %cl,%rax
mov    %rax,-0x358(%rbp)
mov    -0x340(%rbp),%rax
mov    -0x344(%rbp),%ecx
and    $0x1f,%ecx
mov    %ecx,%ecx
sar    %cl,%rax
mov    %rax,-0x360(%rbp)
mov    $0x20,%eax
sub    -0x344(%rbp),%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    $0xffffffff,%eax
shl    %cl,%eax
xor    $0xffffffff,%eax
mov    %eax,%eax
mov    %rax,-0x368(%rbp)
mov    -0x360(%rbp),%rax
and    -0x368(%rbp),%rax
mov    %rax,-0x370(%rbp)
mov    -0x358(%rbp),%rax
or     -0x370(%rbp),%rax
mov    %rax,-0x350(%rbp)
lea    -0x230(%rbp),%rax
mov    %rax,-0x390(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x388(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x390(%rbp),%rdi
mov    -0x388(%rbp),%rsi
mov    %rax,%rdx
lea    -0x130(%rbp),%rcx
mov    -0x334(%rbp),%r8d
mov    $0x0,%al
call   1060 <KeyMD5Encode@plt>
mov    %eax,-0x374(%rbp)
mov    -0x374(%rbp),%eax
movb   $0x0,-0x230(%rbp,%rax,1)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x378(%rbp)
lea    -0x330(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x378(%rbp),%rdx
call   1050 <memcpy@plt>
movslq -0x378(%rbp),%rax
movb   $0x20,-0x330(%rbp,%rax,1)
20
movslq -0x378(%rbp),%rax
mov    -0x350(%rbp),%ecx
mov    %ecx,-0x32f(%rbp,%rax,1)
movslq -0x378(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,-0x32b(%rbp,%rax,1)
lea    -0x330(%rbp),%rdi
movslq -0x378(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
add    $0x4,%rdi
add    $0x4,%rdi
lea    -0x230(%rbp),%rsi
mov    -0x374(%rbp),%eax
mov    %eax,%edx
call   1050 <memcpy@plt>
lea    -0x330(%rbp),%rdi
mov    -0x378(%rbp),%esi
add    $0x1,%esi
add    $0x4,%esi
add    $0x4,%esi
add    -0x374(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    $0x100,%ecx
mov    $0x0,%al
call   1070 <lutil_b64_ntop@plt>
mov    %eax,-0x37c(%rbp)
mov    -0x37c(%rbp),%eax
add    $0x3a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GenerateCrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x318,%rsp
mov    %r9,0x8(%rsp)
mov    %r8,%rbx
mov    %rcx,(%rsp)
mov    %rsi,%r13
mov    %rdi,%r12
lea    0x210(%rsp),%rbp
mov    %rdx,%rdi
mov    %rbp,%rsi
mov    $0x100,%edx
xor    %eax,%eax
call   1040 <lutil_b64_pton@plt>
mov    %eax,%r14d
mov    0x216(%rsp),%eax
not    %rbx
or     %rax,%rbx
movabs $0x8888888888888889,%rcx
88 88 88
mov    %rbx,%rax
imul   %rcx
lea    (%rdx,%rbx,1),%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x4,%eax
add    %ecx,%eax
mov    %eax,%edx
shl    $0x5,%edx
mov    %eax,%ecx
sub    %edx,%ecx
add    %eax,%ecx
add    %ebx,%ecx
mov    %ecx,%eax
neg    %al
and    $0x1f,%cl
mov    %rbx,%rdx
sar    %cl,%rdx
mov    $0xffffffff,%esi
mov    %eax,%ecx
shl    %cl,%esi
not    %esi
and    %esi,%edx
shl    %cl,%ebx
or     %edx,%ebx
mov    %r13,%rdi
call   1030 <strlen@plt>
lea    0x110(%rsp),%rdi
mov    %r13,%rsi
mov    %rax,%rdx
mov    %rbp,%rcx
mov    %r14d,%r8d
xor    %eax,%eax
call   1060 <KeyMD5Encode@plt>
mov    %eax,%r14d
mov    %eax,%r13d
movb   $0x0,0x110(%rsp,%r13,1)
mov    %r12,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbp
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1050 <memcpy@plt>
movb   $0x20,0x10(%rsp,%rbp,1)
mov    %ebx,0x11(%rsp,%rbp,1)
mov    (%rsp),%rax
mov    %eax,0x15(%rsp,%rbp,1)
lea    (%rsp,%rbp,1),%rdi
add    $0x19,%rdi
lea    0x110(%rsp),%rsi
mov    %r13,%rdx
call   1050 <memcpy@plt>
lea    (%r14,%rbp,1),%esi
add    $0x9,%esi
mov    %r15,%rdi
mov    0x8(%rsp),%rdx
mov    $0x100,%ecx
xor    %eax,%eax
call   1070 <lutil_b64_ntop@plt>
add    $0x318,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @GenerateCrypt(i8* %0, i8* %1, i8* %2, i64 %3, i64 %4, i8* %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
%13 = alloca [256 x i8]
%14 = alloca [256 x i8]
%15 = alloca [256 x i8]
%16 = alloca i32
%17 = alloca i64
%18 = alloca i32
%19 = alloca i64
%20 = alloca i64
%21 = alloca i64
%22 = alloca i64
%23 = alloca i64
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i64 %3, i64* %10
store i64 %4, i64* %11
store i8* %5, i8** %12
store i64 0, i64* %17
store i64 0, i64* %19
%27 = load i8*, i8** %9
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%29 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @lutil_b64_pton to i32 (i8*, i8*, i32, ...)*)(i8* %27, i8* %28, i32 256)
store i32 %29, i32* %16
%30 = bitcast i64* %17 to i8*
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%32 = getelementptr inbounds i8, i8* %31, i64 6
%33 = load i64, i64* %11
%34 = xor i64 %33, -1
%35 = load i64, i64* %17
%36 = or i64 %35, %34
store i64 %36, i64* %17
%37 = load i64, i64* %17
%38 = srem i64 %37, 30
%39 = trunc i64 %38 to i32
store i32 %39, i32* %18
%40 = load i64, i64* %17
%41 = load i32, i32* %18
%42 = sub nsw i32 32, %41
%43 = srem i32 %42, 32
%44 = zext i32 %43 to i64
%45 = shl i64 %40, %44
store i64 %45, i64* %20
%46 = load i64, i64* %17
%47 = load i32, i32* %18
%48 = urem i32 %47, 32
%49 = zext i32 %48 to i64
%50 = ashr i64 %46, %49
store i64 %50, i64* %21
%51 = load i32, i32* %18
%52 = sub nsw i32 32, %51
%53 = srem i32 %52, 32
%54 = shl i32 -1, %53
%55 = xor i32 %54, -1
%56 = zext i32 %55 to i64
store i64 %56, i64* %22
%57 = load i64, i64* %21
%58 = load i64, i64* %22
%59 = and i64 %57, %58
store i64 %59, i64* %23
%60 = load i64, i64* %20
%61 = load i64, i64* %23
%62 = or i64 %60, %61
store i64 %62, i64* %19
%63 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%64 = load i8*, i8** %8
%65 = load i8*, i8** %8
%66 = call i64 @strlen(i8* %65)
%67 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%68 = load i32, i32* %16
%69 = call i32 (i8*, i8*, i64, i8*, i32, ...) bitcast (i32 (...)* @KeyMD5Encode to i32 (i8*, i8*, i64, i8*, i32, ...)*)(i8* %63, i8* %64, i64 %66, i8* %67, i32 %68)
store i32 %69, i32* %24
%70 = load i32, i32* %24
%71 = zext i32 %70 to i64
%72 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 %71
store i8 0, i8* %72
%73 = load i8*, i8** %7
%74 = call i64 @strlen(i8* %73)
%75 = trunc i64 %74 to i32
store i32 %75, i32* %25
%76 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%77 = load i8*, i8** %7
%78 = load i32, i32* %25
%79 = sext i32 %78 to i64
%80 = load i32, i32* %25
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 %81
store i8 32, i8* %82
%83 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%84 = load i32, i32* %25
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %83, i64 %85
%87 = getelementptr inbounds i8, i8* %86, i64 1
%88 = bitcast i64* %19 to i8*
%89 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%90 = load i32, i32* %25
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i8, i8* %89, i64 %91
%93 = getelementptr inbounds i8, i8* %92, i64 1
%94 = getelementptr inbounds i8, i8* %93, i64 4
%95 = bitcast i64* %10 to i8*
%96 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%97 = load i32, i32* %25
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8, i8* %96, i64 %98
%100 = getelementptr inbounds i8, i8* %99, i64 1
%101 = getelementptr inbounds i8, i8* %100, i64 4
%102 = getelementptr inbounds i8, i8* %101, i64 4
%103 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%104 = load i32, i32* %24
%105 = zext i32 %104 to i64
%106 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%107 = load i32, i32* %25
%108 = add nsw i32 %107, 1
%109 = add nsw i32 %108, 4
%110 = add nsw i32 %109, 4
%111 = load i32, i32* %24
%112 = add i32 %110, %111
%113 = load i8*, i8** %12
%114 = call i32 (i8*, i32, i8*, i32, ...) bitcast (i32 (...)* @lutil_b64_ntop to i32 (i8*, i32, i8*, i32, ...)*)(i8* %106, i32 %112, i8* %113, i32 256)
store i32 %114, i32* %26
%115 = load i32, i32* %26
ret i32 %115
}

LLVM IR (-O2):
define i32 @GenerateCrypt(i8* nocapture %0, i8* %1, i8* %2, i64 %3, i64 %4, i8* %5) {
%7 = alloca [256 x i8]
%8 = alloca [256 x i8]
%9 = alloca [256 x i8]
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%13 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @lutil_b64_pton to i32 (i8*, i8*, i32, ...)*)(i8* %2, i8* %10, i32 256)
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 6
%15 = bitcast i8* %14 to i32*
%16 = load i32, i32* %15
%17 = zext i32 %16 to i64
%18 = xor i64 %4, -1
%19 = or i64 %17, %18
%20 = srem i64 %19, 30
%21 = trunc i64 %20 to i32
%22 = sub nsw i32 0, %21
%23 = and i32 %22, 31
%24 = zext i32 %23 to i64
%25 = shl i64 %19, %24
%26 = and i64 %20, 31
%27 = ashr i64 %19, %26
%28 = shl nsw i32 -1, %23
%29 = xor i32 %28, -1
%30 = zext i32 %29 to i64
%31 = and i64 %27, %30
%32 = or i64 %31, %25
%33 = call i64 @strlen(i8* dereferenceable(1) %1)
%34 = call i32 (i8*, i8*, i64, i8*, i32, ...) bitcast (i32 (...)* @KeyMD5Encode to i32 (i8*, i8*, i64, i8*, i32, ...)*)(i8* %11, i8* %1, i64 %33, i8* %10, i32 %13)
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %35
store i8 0, i8* %36
%37 = call i64 @strlen(i8* dereferenceable(1) %0)
%38 = trunc i64 %37 to i32
%39 = shl i64 %37, 32
%40 = ashr exact i64 %39, 32
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %40
store i8 32, i8* %41
%42 = getelementptr inbounds i8, i8* %41, i64 1
%43 = bitcast i8* %42 to i32*
%44 = trunc i64 %32 to i32
store i32 %44, i32* %43
%45 = getelementptr inbounds i8, i8* %41, i64 5
%46 = bitcast i8* %45 to i32*
%47 = trunc i64 %3 to i32
store i32 %47, i32* %46
%48 = getelementptr inbounds i8, i8* %41, i64 9
%49 = add i32 %34, 9
%50 = add i32 %49, %38
%51 = call i32 (i8*, i32, i8*, i32, ...) bitcast (i32 (...)* @lutil_b64_ntop to i32 (i8*, i32, i8*, i32, ...)*)(i8* %12, i32 %50, i8* %5, i32 256)
ret i32 %51
}