#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*/ sUserKey;
typedef int /*<<< orphan*/ sTmp;
typedef int /*<<< orphan*/ sIv;
typedef int /*<<< orphan*/ sInnerKey;
typedef int /*<<< orphan*/ sEncPswd;
typedef int /*<<< orphan*/ sEnc;

/* Variables and functions */
int /*<<< orphan*/ DES_CBC_Decryption(char *, char *, char *, int, char *);
int /*<<< orphan*/ Str2Hex(char *, char *, int);
int /*<<< orphan*/ getKey(char *);
unsigned long hashckey(char *, int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned long);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int GetClearPwd(char *sEncPwd, char *sKey, char *sClearPwd) {
  char sUserKey[1024];
  char sInnerKey[33];
  unsigned long i;
  char sTmp[8 + 1];
  char sEncPswd[128];
  int nEncPswdLen;
  char sEnc[64];
  char sIv[8];
  memset(sUserKey, 0x00, sizeof(sUserKey));
  memset(sInnerKey, 0x00, sizeof(sInnerKey));
  memset(sEncPswd, 0x00, sizeof(sEncPswd));
  memset(sEnc, 0x00, sizeof(sEnc));
  memset(sIv, 0x00, sizeof(sIv));
  strncpy(sUserKey, sKey, sizeof(sUserKey) - 1);
  getKey(sInnerKey);
  strncat(sUserKey, sInnerKey, sizeof(sUserKey) - strlen(sUserKey) - 1);
  i = hashckey(sUserKey, strlen(sUserKey));
  snprintf(sTmp, sizeof(sTmp), "%.8x", i);
  strncpy(sEncPswd, sEncPwd, sizeof(sEncPswd) - 1);
  nEncPswdLen = strlen(sEncPswd);
  Str2Hex(sEncPswd, sEnc, nEncPswdLen);
  DES_CBC_Decryption(sEnc, sClearPwd, sTmp, nEncPswdLen / 2, sIv);
  return 0;
}


x86 assembly (clang, -O0):
<GetClearPwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x570,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    -0x450(%rbp),%rdi
xor    %esi,%esi
mov    $0x21,%edx
call   1060 <memset@plt>
lea    -0x4f0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    -0x540(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1060 <memset@plt>
lea    -0x548(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x3ff,%edx
call   1030 <strncpy@plt>
lea    -0x450(%rbp),%rdi
call   1080 <getKey@plt>
lea    -0x420(%rbp),%rax
mov    %rax,-0x568(%rbp)
lea    -0x450(%rbp),%rax
mov    %rax,-0x560(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x568(%rbp),%rdi
mov    -0x560(%rbp),%rsi
movslq %eax,%rcx
mov    $0x400,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1070 <strncat@plt>
lea    -0x420(%rbp),%rax
mov    %rax,-0x558(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x558(%rbp),%rdi
mov    %eax,%esi
call   1090 <hashckey@plt>
mov    %rax,-0x458(%rbp)
lea    -0x461(%rbp),%rdi
mov    -0x458(%rbp),%rcx
mov    $0x9,%esi
lea    0xd44(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x4f0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x7f,%edx
call   1030 <strncpy@plt>
lea    -0x4f0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4f4(%rbp)
lea    -0x4f0(%rbp),%rdi
lea    -0x540(%rbp),%rsi
mov    -0x4f4(%rbp),%edx
call   10a0 <Str2Hex@plt>
lea    -0x540(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x461(%rbp),%rax
mov    %rax,-0x550(%rbp)
mov    -0x4f4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x550(%rbp),%rdx
mov    %eax,%ecx
lea    -0x548(%rbp),%r8
call   10b0 <DES_CBC_Decryption@plt>
xor    %eax,%eax
add    $0x570,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetClearPwd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x518,%rsp
mov    %rdx,(%rsp)
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x110(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    0x60(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x21,%edx
call   1060 <memset@plt>
lea    0x90(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    0x20(%rsp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1060 <memset@plt>
lea    0xf(%rsp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    $0x3ff,%r15d
mov    %rbp,%rdi
mov    %r14,%rsi
mov    $0x3ff,%edx
call   1030 <strncpy@plt>
mov    %r13,%rdi
call   1080 <getKey@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
sub    %eax,%r15d
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r15d,%edx
call   1070 <strncat@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1090 <hashckey@plt>
lea    0xda1(%rip),%rdx
lea    0x17(%rsp),%r14
mov    %r14,%rdi
mov    $0x9,%esi
mov    %rax,%rcx
call   1050 <snprintf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x7f,%edx
call   1030 <strncpy@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r12,%rdi
lea    0x20(%rsp),%rbp
mov    %rbp,%rsi
mov    %eax,%edx
call   10a0 <Str2Hex@plt>
mov    %ebx,%ecx
shr    $0x1f,%ecx
add    %ebx,%ecx
sar    %ecx
mov    %rbp,%rdi
mov    (%rsp),%rsi
mov    %r14,%rdx
lea    0xf(%rsp),%r8
call   10b0 <DES_CBC_Decryption@plt>
xor    %eax,%eax
add    $0x518,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%.8x\00"
define i32 @GetClearPwd(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [1024 x i8]
%8 = alloca [33 x i8]
%9 = alloca i64
%10 = alloca [9 x i8]
%11 = alloca [128 x i8]
%12 = alloca i32
%13 = alloca [64 x i8]
%14 = alloca [8 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i32 0, i32 1024)
%17 = getelementptr inbounds [33 x i8], [33 x i8]* %8, i64 0, i64 0
%18 = call i32 @memset(i8* %17, i32 0, i32 33)
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i32 0, i32 128)
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %13, i64 0, i64 0
%22 = call i32 @memset(i8* %21, i32 0, i32 64)
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %14, i64 0, i64 0
%24 = call i32 @memset(i8* %23, i32 0, i32 8)
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%26 = load i8*, i8** %5
%27 = call i32 @strncpy(i8* %25, i8* %26, i32 1023)
%28 = getelementptr inbounds [33 x i8], [33 x i8]* %8, i64 0, i64 0
%29 = call i32 @getKey(i8* %28)
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%31 = getelementptr inbounds [33 x i8], [33 x i8]* %8, i64 0, i64 0
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%33 = call i32 @strlen(i8* %32)
%34 = sext i32 %33 to i64
%35 = sub i64 1024, %34
%36 = sub i64 %35, 1
%37 = trunc i64 %36 to i32
%38 = call i32 @strncat(i8* %30, i8* %31, i32 %37)
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
%42 = call i64 @hashckey(i8* %39, i32 %41)
store i64 %42, i64* %9
%43 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 0
%44 = load i64, i64* %9
%45 = call i32 @snprintf(i8* %43, i32 9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %44)
%46 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%47 = load i8*, i8** %4
%48 = call i32 @strncpy(i8* %46, i8* %47, i32 127)
%49 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
store i32 %50, i32* %12
%51 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%52 = getelementptr inbounds [64 x i8], [64 x i8]* %13, i64 0, i64 0
%53 = load i32, i32* %12
%54 = call i32 @Str2Hex(i8* %51, i8* %52, i32 %53)
%55 = getelementptr inbounds [64 x i8], [64 x i8]* %13, i64 0, i64 0
%56 = load i8*, i8** %6
%57 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 0
%58 = load i32, i32* %12
%59 = sdiv i32 %58, 2
%60 = getelementptr inbounds [8 x i8], [8 x i8]* %14, i64 0, i64 0
%61 = call i32 @DES_CBC_Decryption(i8* %55, i8* %56, i8* %57, i32 %59, i8* %60)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%.8x\00"
define i32 @GetClearPwd(i8* %0, i8* %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = alloca [33 x i8]
%6 = alloca [9 x i8]
%7 = alloca [128 x i8]
%8 = alloca [64 x i8]
%9 = alloca [8 x i8]
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [33 x i8], [33 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%16 = call i32 @memset(i8* %10, i32 0, i32 1024)
%17 = call i32 @memset(i8* %11, i32 0, i32 33)
%18 = call i32 @memset(i8* %13, i32 0, i32 128)
%19 = call i32 @memset(i8* %14, i32 0, i32 64)
%20 = call i32 @memset(i8* %15, i32 0, i32 8)
%21 = call i32 @strncpy(i8* %10, i8* %1, i32 1023)
%22 = call i32 @getKey(i8* %11)
%23 = call i32 @strlen(i8* %10)
%24 = sub i32 1023, %23
%25 = call i32 @strncat(i8* %10, i8* %11, i32 %24)
%26 = call i32 @strlen(i8* %10)
%27 = call i64 @hashckey(i8* %10, i32 %26)
%28 = call i32 @snprintf(i8* %12, i32 9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %27)
%29 = call i32 @strncpy(i8* %13, i8* %0, i32 127)
%30 = call i32 @strlen(i8* %13)
%31 = call i32 @Str2Hex(i8* %13, i8* %14, i32 %30)
%32 = sdiv i32 %30, 2
%33 = call i32 @DES_CBC_Decryption(i8* %14, i8* %2, i8* %12, i32 %32, i8* %15)
ret i32 0
}