#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_Encryption(char *, char *, char *, int, char *);
int /*<<< orphan*/ getKey(char *);
unsigned long hashckey(char *, int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned long);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int SetClearPasswd(char *sClearPwd, char *sKey, char *sEncPwd) {
  int rc;
  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);
  strcpy(sEncPswd, sClearPwd);
  nEncPswdLen = strlen(sEncPswd);
  DES_CBC_Encryption(sEncPswd, sEncPwd, sTmp, (nEncPswdLen + 7) / 8 * 8, sIv);
  return (nEncPswdLen + 7) / 8 * 8;
}


x86 assembly (clang, -O0):
<SetClearPasswd>:
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   1070 <memset@plt>
lea    -0x450(%rbp),%rdi
xor    %esi,%esi
mov    $0x21,%edx
call   1070 <memset@plt>
lea    -0x4f0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1070 <memset@plt>
lea    -0x540(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1070 <memset@plt>
lea    -0x548(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x3ff,%edx
call   1030 <strncpy@plt>
lea    -0x450(%rbp),%rdi
call   1090 <getKey@plt>
lea    -0x420(%rbp),%rax
mov    %rax,-0x568(%rbp)
lea    -0x450(%rbp),%rax
mov    %rax,-0x560(%rbp)
lea    -0x420(%rbp),%rdi
call   1050 <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   1080 <strncat@plt>
lea    -0x420(%rbp),%rax
mov    %rax,-0x558(%rbp)
lea    -0x420(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x558(%rbp),%rdi
mov    %eax,%esi
call   10b0 <hashckey@plt>
mov    %rax,-0x458(%rbp)
lea    -0x461(%rbp),%rdi
mov    -0x458(%rbp),%rcx
mov    $0x9,%esi
lea    0xd44(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x4f0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x4f0(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x4f4(%rbp)
lea    -0x4f0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x461(%rbp),%rax
mov    %rax,-0x550(%rbp)
mov    -0x4f4(%rbp),%eax
add    $0x7,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    -0x550(%rbp),%rdx
mov    %eax,%ecx
shl    $0x3,%ecx
lea    -0x548(%rbp),%r8
call   10a0 <DES_CBC_Encryption@plt>
mov    -0x4f4(%rbp),%eax
add    $0x7,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
shl    $0x3,%eax
add    $0x570,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetClearPasswd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x518,%rsp
mov    %rdx,(%rsp)
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x110(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x21,%edx
call   1070 <memset@plt>
lea    0x90(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1070 <memset@plt>
lea    0x50(%rsp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1070 <memset@plt>
lea    0xf(%rsp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    $0x3ff,%r12d
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3ff,%edx
call   1030 <strncpy@plt>
mov    %rbp,%rdi
call   1090 <getKey@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
sub    %eax,%r12d
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
call   1080 <strncat@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   10b0 <hashckey@plt>
lea    0xda1(%rip),%rdx
lea    0x17(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x9,%esi
mov    %rax,%rcx
call   1060 <snprintf@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
lea    0x7(%rbp),%eax
add    $0xe,%ebp
test   %eax,%eax
cmovns %eax,%ebp
and    $0xfffffff8,%ebp
mov    %r13,%rdi
mov    (%rsp),%rsi
mov    %rbx,%rdx
mov    %ebp,%ecx
lea    0xf(%rsp),%r8
call   10a0 <DES_CBC_Encryption@plt>
mov    %ebp,%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 @SetClearPasswd(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca [33 x i8]
%10 = alloca i64
%11 = alloca [9 x i8]
%12 = alloca [128 x i8]
%13 = alloca i32
%14 = alloca [64 x i8]
%15 = alloca [8 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%17 = call i32 @memset(i8* %16, i32 0, i32 1024)
%18 = getelementptr inbounds [33 x i8], [33 x i8]* %9, i64 0, i64 0
%19 = call i32 @memset(i8* %18, i32 0, i32 33)
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%21 = call i32 @memset(i8* %20, i32 0, i32 128)
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %14, i64 0, i64 0
%23 = call i32 @memset(i8* %22, i32 0, i32 64)
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %15, i64 0, i64 0
%25 = call i32 @memset(i8* %24, i32 0, i32 8)
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%27 = load i8*, i8** %5
%28 = call i32 @strncpy(i8* %26, i8* %27, i32 1023)
%29 = getelementptr inbounds [33 x i8], [33 x i8]* %9, i64 0, i64 0
%30 = call i32 @getKey(i8* %29)
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%32 = getelementptr inbounds [33 x i8], [33 x i8]* %9, i64 0, i64 0
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
%35 = sext i32 %34 to i64
%36 = sub i64 1024, %35
%37 = sub i64 %36, 1
%38 = trunc i64 %37 to i32
%39 = call i32 @strncat(i8* %31, i8* %32, i32 %38)
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%42 = call i32 @strlen(i8* %41)
%43 = call i64 @hashckey(i8* %40, i32 %42)
store i64 %43, i64* %10
%44 = getelementptr inbounds [9 x i8], [9 x i8]* %11, i64 0, i64 0
%45 = load i64, i64* %10
%46 = call i32 @snprintf(i8* %44, i32 9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %45)
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%48 = load i8*, i8** %4
%49 = call i32 @strcpy(i8* %47, i8* %48)
%50 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%51 = call i32 @strlen(i8* %50)
store i32 %51, i32* %13
%52 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%53 = load i8*, i8** %6
%54 = getelementptr inbounds [9 x i8], [9 x i8]* %11, i64 0, i64 0
%55 = load i32, i32* %13
%56 = add nsw i32 %55, 7
%57 = sdiv i32 %56, 8
%58 = mul nsw i32 %57, 8
%59 = getelementptr inbounds [8 x i8], [8 x i8]* %15, i64 0, i64 0
%60 = call i32 @DES_CBC_Encryption(i8* %52, i8* %53, i8* %54, i32 %58, i8* %59)
%61 = load i32, i32* %13
%62 = add nsw i32 %61, 7
%63 = sdiv i32 %62, 8
%64 = mul nsw i32 %63, 8
ret i32 %64
}

LLVM IR (-O2):
@.str = [5 x i8] c"%.8x\00"
define i32 @SetClearPasswd(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 @strcpy(i8* %13, i8* %0)
%30 = call i32 @strlen(i8* %13)
%31 = add nsw i32 %30, 7
%32 = sdiv i32 %31, 8
%33 = shl nsw i32 %32, 3
%34 = call i32 @DES_CBC_Encryption(i8* %13, i8* %2, i8* %12, i32 %33, i8* %15)
ret i32 %33
}