#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*/ hexconvert;

/* Variables and functions */
int /*<<< orphan*/ PKCS5_PBKDF2_HMAC_SHA1(char *, int, unsigned char *, int,
                                          int, int, unsigned char *);
int SHA_DIGEST_LENGTH;
int /*<<< orphan*/ bzero(unsigned char *, int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
scalar_t__ strlen(char *);
unsigned char strtol(char *, int /*<<< orphan*/ *, int);
int pw_encrypt_new(const unsigned char *pw_pwd, unsigned char *encryp,
                   char *digest) {
  unsigned char hexconvert[3];
  unsigned char *salt;
  int i;
  unsigned char md[SHA_DIGEST_LENGTH];
  int mdlen = SHA_DIGEST_LENGTH;
  unsigned char real_salt[4 + 1];
  bzero(hexconvert, sizeof(hexconvert));
  salt = encryp;
  salt++;
  for (i = 0; i < 4; i++) {
    hexconvert[0] = (*salt);
    salt++;
    hexconvert[1] = (*salt);
    salt++;
    real_salt[i] = strtol((char *)hexconvert, NULL, 16);
  }
  PKCS5_PBKDF2_HMAC_SHA1((char *)pw_pwd, (int)strlen((char *)pw_pwd), real_salt,
                         4, 100, mdlen, md);
  *digest = '$';
  digest++;
  for (i = 0; i < 4; i++) {
    sprintf(digest, "%02x", real_salt[i]);
    digest += 2;
  }
  *digest = '$';
  digest++;
  for (i = 0; i < mdlen; i++) {
    sprintf(digest, "%02x", md[i]);
    digest += 2;
  }
  *digest = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<pw_encrypt_new>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
lea    -0x1b(%rbp),%rdi
mov    $0x3,%esi
call   1060 <bzero@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x4,-0x2c(%rbp)
jge    1223 <pw_encrypt_new+0xd3>
mov    -0x28(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x1b(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x1a(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
lea    -0x1b(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %al,%cl
movslq -0x2c(%rbp),%rax
mov    %cl,-0x49(%rbp,%rax,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c5 <pw_encrypt_new+0x75>
mov    -0x8(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
mov    %ecx,%esi
lea    -0x49(%rbp),%rdx
mov    -0x44(%rbp),%r9d
mov    $0x4,%ecx
mov    $0x64,%r8d
sub    $0x10,%rsp
mov    %rax,(%rsp)
call   1050 <PKCS5_PBKDF2_HMAC_SHA1@plt>
add    $0x10,%rsp
mov    -0x18(%rbp),%rax
movb   $0x24,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x4,-0x2c(%rbp)
jge    12bc <pw_encrypt_new+0x16c>
mov    -0x18(%rbp),%rdi
movslq -0x2c(%rbp),%rax
lea    0xd68(%rip),%rsi
movzbl -0x49(%rbp,%rax,1),%edx
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    127f <pw_encrypt_new+0x12f>
mov    -0x18(%rbp),%rax
movb   $0x24,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    1318 <pw_encrypt_new+0x1c8>
mov    -0x58(%rbp),%rax
mov    -0x18(%rbp),%rdi
movslq -0x2c(%rbp),%rcx
lea    0xd0b(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12d6 <pw_encrypt_new+0x186>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pw_encrypt_new>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,-0x38(%rbp)
mov    %rsp,-0x40(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%r13
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r13
mov    %r13,%rsp
mov    (%rax),%r14d
lea    -0x2b(%rbp),%r15
mov    %r15,%rdi
mov    $0x3,%esi
call   1060 <bzero@plt>
mov    0x1(%rbx),%al
mov    %al,-0x2b(%rbp)
mov    0x2(%rbx),%al
mov    %al,-0x2a(%rbp)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %al,-0x30(%rbp)
mov    0x3(%rbx),%al
mov    %al,-0x2b(%rbp)
mov    0x4(%rbx),%al
mov    %al,-0x2a(%rbp)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %al,-0x2f(%rbp)
mov    0x5(%rbx),%al
mov    %al,-0x2b(%rbp)
mov    0x6(%rbx),%al
mov    %al,-0x2a(%rbp)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %al,-0x2e(%rbp)
mov    0x7(%rbx),%al
mov    %al,-0x2b(%rbp)
mov    0x8(%rbx),%al
mov    %al,-0x2a(%rbp)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %al,-0x2d(%rbp)
mov    -0x38(%rbp),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
sub    $0x8,%rsp
lea    -0x30(%rbp),%rdx
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x4,%ecx
mov    $0x64,%r8d
mov    %r14d,%r9d
push   %r13
call   1050 <PKCS5_PBKDF2_HMAC_SHA1@plt>
add    $0x10,%rsp
movb   $0x24,(%r12)
lea    0x1(%r12),%rdi
movzbl -0x30(%rbp),%edx
lea    0xda4(%rip),%r15
mov    %r15,%rsi
call   1070 <sprintf@plt>
lea    0x3(%r12),%rdi
movzbl -0x2f(%rbp),%edx
mov    %r15,%rsi
call   1070 <sprintf@plt>
lea    0x5(%r12),%rdi
movzbl -0x2e(%rbp),%edx
mov    %r15,%rsi
call   1070 <sprintf@plt>
lea    0x7(%r12),%rdi
movzbl -0x2d(%rbp),%edx
mov    %r15,%rsi
call   1070 <sprintf@plt>
movb   $0x24,0x9(%r12)
add    $0xa,%r12
test   %r14d,%r14d
jle    12ce <pw_encrypt_new+0x17e>
xor    %ebx,%ebx
lea    0xd51(%rip),%r15
nop
movzbl 0x0(%r13,%rbx,1),%edx
mov    %r12,%rdi
mov    %r15,%rsi
call   1070 <sprintf@plt>
add    $0x2,%r12
add    $0x1,%rbx
cmp    %rbx,%r14
jne    12b0 <pw_encrypt_new+0x160>
movb   $0x0,(%r12)
mov    -0x40(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SHA_DIGEST_LENGTH = global i32 0
@.str = [5 x i8] c"%02x\00"
define i32 @pw_encrypt_new(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [3 x i8]
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca [5 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%14 = load i32, i32* @SHA_DIGEST_LENGTH
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %10
%17 = alloca i8, i64 %15
store i64 %15, i64* %11
%18 = load i32, i32* @SHA_DIGEST_LENGTH
store i32 %18, i32* %12
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%20 = call i32 @bzero(i8* %19, i32 3)
%21 = load i8*, i8** %5
store i8* %21, i8** %8
%22 = load i8*, i8** %8
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %8
store i32 0, i32* %9
br label %24
24: ; preds = %43, %3
%25 = load i32, i32* %9
%26 = icmp slt i32 %25, 4
br i1 %26, label %27, label %46
27: ; preds = %24
%28 = load i8*, i8** %8
%29 = load i8, i8* %28
%30 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
store i8 %29, i8* %30
%31 = load i8*, i8** %8
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %8
%33 = load i8*, i8** %8
%34 = load i8, i8* %33
%35 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 1
store i8 %34, i8* %35
%36 = load i8*, i8** %8
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %8
%38 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%39 = call zeroext i8 @strtol(i8* %38, i32* null, i32 16)
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [5 x i8], [5 x i8]* %13, i64 0, i64 %41
store i8 %39, i8* %42
br label %43
43: ; preds = %27
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
store i32 %45, i32* %9
br label %24
46: ; preds = %24
%47 = load i8*, i8** %4
%48 = load i8*, i8** %4
%49 = call i64 @strlen(i8* %48)
%50 = trunc i64 %49 to i32
%51 = getelementptr inbounds [5 x i8], [5 x i8]* %13, i64 0, i64 0
%52 = load i32, i32* %12
%53 = call i32 @PKCS5_PBKDF2_HMAC_SHA1(i8* %47, i32 %50, i8* %51, i32 4, i32 100, i32 %52, i8* %17)
%54 = load i8*, i8** %6
store i8 36, i8* %54
%55 = load i8*, i8** %6
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %6
store i32 0, i32* %9
br label %57
57: ; preds = %69, %46
%58 = load i32, i32* %9
%59 = icmp slt i32 %58, 4
br i1 %59, label %60, label %72
60: ; preds = %57
%61 = load i8*, i8** %6
%62 = load i32, i32* %9
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [5 x i8], [5 x i8]* %13, i64 0, i64 %63
%65 = load i8, i8* %64
%66 = call i32 @sprintf(i8* %61, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %65)
%67 = load i8*, i8** %6
%68 = getelementptr inbounds i8, i8* %67, i64 2
store i8* %68, i8** %6
br label %69
69: ; preds = %60
%70 = load i32, i32* %9
%71 = add nsw i32 %70, 1
store i32 %71, i32* %9
br label %57
72: ; preds = %57
%73 = load i8*, i8** %6
store i8 36, i8* %73
%74 = load i8*, i8** %6
%75 = getelementptr inbounds i8, i8* %74, i32 1
store i8* %75, i8** %6
store i32 0, i32* %9
br label %76
76: ; preds = %89, %72
%77 = load i32, i32* %9
%78 = load i32, i32* %12
%79 = icmp slt i32 %77, %78
br i1 %79, label %80, label %92
80: ; preds = %76
%81 = load i8*, i8** %6
%82 = load i32, i32* %9
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i8, i8* %17, i64 %83
%85 = load i8, i8* %84
%86 = call i32 @sprintf(i8* %81, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %85)
%87 = load i8*, i8** %6
%88 = getelementptr inbounds i8, i8* %87, i64 2
store i8* %88, i8** %6
br label %89
89: ; preds = %80
%90 = load i32, i32* %9
%91 = add nsw i32 %90, 1
store i32 %91, i32* %9
br label %76
92: ; preds = %76
%93 = load i8*, i8** %6
store i8 0, i8* %93
%94 = load i8*, i8** %10
ret i32 0
}

LLVM IR (-O2):
@SHA_DIGEST_LENGTH = global i32 0
@.str = [5 x i8] c"%02x\00"
define i32 @pw_encrypt_new(i8* %0, i8* nocapture %1, i8* nocapture writeonly %2) {
%4 = alloca [3 x i8]
%5 = alloca [5 x i8]
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @SHA_DIGEST_LENGTH
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = load i32, i32* @SHA_DIGEST_LENGTH
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%13 = call i32 @bzero(i8* %6, i32 3)
%14 = getelementptr inbounds i8, i8* %1, i64 1
%15 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
%16 = load i8, i8* %14
store i8 %16, i8* %6
%17 = getelementptr inbounds i8, i8* %1, i64 2
%18 = load i8, i8* %17
store i8 %18, i8* %15
%19 = getelementptr inbounds i8, i8* %1, i64 3
%20 = call zeroext i8 @strtol(i8* nocapture %6, i32* null, i32 16)
store i8 %20, i8* %12
%21 = load i8, i8* %19
store i8 %21, i8* %6
%22 = getelementptr inbounds i8, i8* %1, i64 4
%23 = load i8, i8* %22
store i8 %23, i8* %15
%24 = getelementptr inbounds i8, i8* %1, i64 5
%25 = call zeroext i8 @strtol(i8* nocapture %6, i32* null, i32 16)
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 1
store i8 %25, i8* %26
%27 = load i8, i8* %24
store i8 %27, i8* %6
%28 = getelementptr inbounds i8, i8* %1, i64 6
%29 = load i8, i8* %28
store i8 %29, i8* %15
%30 = getelementptr inbounds i8, i8* %1, i64 7
%31 = call zeroext i8 @strtol(i8* nocapture %6, i32* null, i32 16)
%32 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 2
store i8 %31, i8* %32
%33 = load i8, i8* %30
store i8 %33, i8* %6
%34 = getelementptr inbounds i8, i8* %1, i64 8
%35 = load i8, i8* %34
store i8 %35, i8* %15
%36 = call zeroext i8 @strtol(i8* nocapture %6, i32* null, i32 16)
%37 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 3
store i8 %36, i8* %37
%38 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%39 = trunc i64 %38 to i32
%40 = call i32 @PKCS5_PBKDF2_HMAC_SHA1(i8* %0, i32 %39, i8* %12, i32 4, i32 100, i32 %11, i8* %10)
store i8 36, i8* %2
%41 = getelementptr inbounds i8, i8* %2, i64 1
%42 = load i8, i8* %12
%43 = call i32 @sprintf(i8* %41, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %42)
%44 = getelementptr inbounds i8, i8* %2, i64 3
%45 = load i8, i8* %26
%46 = call i32 @sprintf(i8* %44, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %45)
%47 = getelementptr inbounds i8, i8* %2, i64 5
%48 = load i8, i8* %32
%49 = call i32 @sprintf(i8* %47, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %48)
%50 = getelementptr inbounds i8, i8* %2, i64 7
%51 = load i8, i8* %37
%52 = call i32 @sprintf(i8* %50, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %51)
%53 = getelementptr inbounds i8, i8* %2, i64 9
store i8 36, i8* %53
%54 = getelementptr inbounds i8, i8* %2, i64 10
%55 = icmp sgt i32 %11, 0
br i1 %55, label %56, label %67
56: ; preds = %3
%57 = zext i32 %11 to i64
br label %58
58: ; preds = %56, %58
%59 = phi i64 [ 0, %56 ], [ %65, %58 ]
%60 = phi i8* [ %54, %56 ], [ %64, %58 ]
%61 = getelementptr inbounds i8, i8* %10, i64 %59
%62 = load i8, i8* %61
%63 = call i32 @sprintf(i8* %60, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %62)
%64 = getelementptr inbounds i8, i8* %60, i64 2
%65 = add nuw nsw i64 %59, 1
%66 = icmp eq i64 %65, %57
br i1 %66, label %67, label %58
67: ; preds = %58, %3
%68 = phi i8* [ %54, %3 ], [ %64, %58 ]
store i8 0, i8* %68
ret i32 0
}