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

/* Variables and functions */
int SHA_DIGEST_LENGTH;
int /*<<< orphan*/ pbkdf2(unsigned char const *, int, int, unsigned char *,
                          int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
scalar_t__ strlen(char *);
int pw_encrypt(const unsigned char *pw_pwd, char *digest) {
  unsigned char md[SHA_DIGEST_LENGTH];
  int mdlen = SHA_DIGEST_LENGTH, i;
  pbkdf2(pw_pwd, (int)strlen((char *)pw_pwd), 100, md, SHA_DIGEST_LENGTH);
  for (i = 0; i < mdlen; i++) {
    sprintf(digest, "%02x", md[i]);
    digest += 2;
  }
  *digest = '\0';
  return 1;
}


x86 assembly (clang, -O0):
<pw_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    %eax,%esi
mov    0x2e4e(%rip),%rax
mov    (%rax),%r8d
mov    $0x64,%edx
call   1030 <pbkdf2@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11f0 <pw_encrypt+0xc0>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rdi
movslq -0x28(%rbp),%rcx
lea    0xe33(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11ae <pw_encrypt+0x7e>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    $0x1,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pw_encrypt>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %rdi,%r12
mov    0x2e9d(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r15
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
call   1040 <strlen@plt>
mov    %r12,%rdi
mov    %eax,%esi
mov    $0x64,%edx
mov    %r15,%rcx
mov    %r14d,%r8d
call   1030 <pbkdf2@plt>
test   %r14d,%r14d
jle    11ad <pw_encrypt+0x7d>
xor    %ebx,%ebx
lea    0xe79(%rip),%r12
nopw   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%edx
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <sprintf@plt>
add    $0x2,%r13
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1190 <pw_encrypt+0x60>
movb   $0x0,0x0(%r13)
mov    $0x1,%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(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i32, i32* @SHA_DIGEST_LENGTH
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %5
%12 = alloca i8, i64 %10
store i64 %10, i64* %6
%13 = load i32, i32* @SHA_DIGEST_LENGTH
store i32 %13, i32* %7
%14 = load i8*, i8** %3
%15 = load i8*, i8** %3
%16 = call i64 @strlen(i8* %15)
%17 = trunc i64 %16 to i32
%18 = load i32, i32* @SHA_DIGEST_LENGTH
%19 = call i32 @pbkdf2(i8* %14, i32 %17, i32 100, i8* %12, i32 %18)
store i32 0, i32* %8
br label %20
20: ; preds = %33, %2
%21 = load i32, i32* %8
%22 = load i32, i32* %7
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %36
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %12, i64 %27
%29 = load i8, i8* %28
%30 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %29)
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i64 2
store i8* %32, i8** %4
br label %33
33: ; preds = %24
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %20
36: ; preds = %20
%37 = load i8*, i8** %4
store i8 0, i8* %37
%38 = load i8*, i8** %5
ret i32 1
}

LLVM IR (-O2):
@SHA_DIGEST_LENGTH = global i32 0
@.str = [5 x i8] c"%02x\00"
define i32 @pw_encrypt(i8* %0, i8* nocapture writeonly %1) {
%3 = load i32, i32* @SHA_DIGEST_LENGTH
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = trunc i64 %6 to i32
%8 = call i32 @pbkdf2(i8* %0, i32 %7, i32 100, i8* %5, i32 %3)
%9 = icmp sgt i32 %3, 0
br i1 %9, label %10, label %19
10: ; preds = %2, %10
%11 = phi i64 [ %17, %10 ], [ 0, %2 ]
%12 = phi i8* [ %16, %10 ], [ %1, %2 ]
%13 = getelementptr inbounds i8, i8* %5, i64 %11
%14 = load i8, i8* %13
%15 = call i32 @sprintf(i8* dereferenceable(1) %12, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %14)
%16 = getelementptr inbounds i8, i8* %12, i64 2
%17 = add nuw nsw i64 %11, 1
%18 = icmp eq i64 %17, %4
br i1 %18, label %19, label %10
19: ; preds = %10, %2
%20 = phi i8* [ %1, %2 ], [ %16, %10 ]
store i8 0, i8* %20
ret i32 1
}