#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*/ const uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ JV_SHA1(int /*<<< orphan*/ const *,
                           int /*<<< orphan*/ const *, size_t const);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ const *,
                          int /*<<< orphan*/ const *, size_t const);
uint8_t *JV_PBKDF1(uint8_t *dkey, const uint8_t password[], const size_t pwlen,
                   const uint8_t salt[], const size_t saltlen,
                   const uint32_t itercount) {
  uint8_t mid_odd[20] = {0}, mid_even[20] = {0};
  uint8_t kickoff[84] = {0};
  int i = 1;
  memcpy(kickoff, password, pwlen);
  memcpy(kickoff + pwlen, salt, saltlen);
  JV_SHA1(mid_even, kickoff, pwlen + saltlen);
  for (i = 1; i < itercount; i++) {
    if (i % 2) {
      JV_SHA1(mid_odd, mid_even, 20);
    } else {
      JV_SHA1(mid_even, mid_odd, 20);
    }
  }
  if (i % 2) {
    memcpy(dkey, mid_even, 20);
  } else {
    memcpy(dkey, mid_odd, 20);
  }
  return dkey;
}


x86 assembly (clang, -O0):
<JV_PBKDF1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1030 <memset@plt>
lea    -0xd0(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1030 <memset@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x150,%edx
call   1030 <memset@plt>
movl   $0x1,-0x224(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <memcpy@plt>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memcpy@plt>
lea    -0xd0(%rbp),%rdi
lea    -0x220(%rbp),%rsi
mov    -0x18(%rbp),%rdx
add    -0x28(%rbp),%rdx
call   1050 <JV_SHA1@plt>
movl   $0x1,-0x224(%rbp)
mov    -0x224(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1259 <JV_PBKDF1+0x129>
mov    -0x224(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     122b <JV_PBKDF1+0xfb>
lea    -0x80(%rbp),%rdi
lea    -0xd0(%rbp),%rsi
mov    $0x14,%edx
call   1050 <JV_SHA1@plt>
jmp    1240 <JV_PBKDF1+0x110>
lea    -0xd0(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x14,%edx
call   1050 <JV_SHA1@plt>
jmp    1245 <JV_PBKDF1+0x115>
mov    -0x224(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x224(%rbp)
jmp    11eb <JV_PBKDF1+0xbb>
mov    -0x224(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     128a <JV_PBKDF1+0x15a>
mov    -0x8(%rbp),%rdi
lea    -0xd0(%rbp),%rsi
mov    $0x14,%edx
call   1040 <memcpy@plt>
jmp    129c <JV_PBKDF1+0x16c>
mov    -0x8(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x14,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<JV_PBKDF1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %r9d,%r13d
mov    %r8,%r15
mov    %rcx,%rbp
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,0x8(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0xb0(%rsp),%r14
mov    $0x150,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <memcpy@plt>
lea    (%rsp,%r12,4),%rdi
add    $0xb0,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1040 <memcpy@plt>
lea    0x10(%rsp),%rbx
add    %r12,%r15
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <JV_SHA1@plt>
cmp    $0x2,%r13d
jl     122e <JV_PBKDF1+0xfe>
mov    $0x1,%ebp
lea    0x10(%rsp),%rbx
lea    0x60(%rsp),%r15
jmp    1213 <JV_PBKDF1+0xe3>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <JV_SHA1@plt>
add    $0x1,%ebp
cmp    %ebp,%r13d
je     1226 <JV_PBKDF1+0xf6>
mov    $0x14,%edx
test   $0x1,%bpl
je     1200 <JV_PBKDF1+0xd0>
mov    %r15,%rdi
mov    %rbx,%rsi
jmp    1206 <JV_PBKDF1+0xd6>
test   $0x1,%r13b
cmove  %r15,%rbx
mov    $0x14,%edx
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <memcpy@plt>
mov    %rbp,%rax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @JV_PBKDF1(i32* %0, i32* %1, i64 %2, i32* %3, i64 %4, i32 %5) {
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i32
%13 = alloca [20 x i32]
%14 = alloca [20 x i32]
%15 = alloca [84 x i32]
%16 = alloca i32
store i32* %0, i32** %7
store i32* %1, i32** %8
store i64 %2, i64* %9
store i32* %3, i32** %10
store i64 %4, i64* %11
store i32 %5, i32* %12
%17 = bitcast [20 x i32]* %13 to i8*
%18 = bitcast [20 x i32]* %14 to i8*
%19 = bitcast [84 x i32]* %15 to i8*
store i32 1, i32* %16
%20 = getelementptr inbounds [84 x i32], [84 x i32]* %15, i64 0, i64 0
%21 = load i32*, i32** %8
%22 = load i64, i64* %9
%23 = call i32 @memcpy(i32* %20, i32* %21, i64 %22)
%24 = getelementptr inbounds [84 x i32], [84 x i32]* %15, i64 0, i64 0
%25 = load i64, i64* %9
%26 = getelementptr inbounds i32, i32* %24, i64 %25
%27 = load i32*, i32** %10
%28 = load i64, i64* %11
%29 = call i32 @memcpy(i32* %26, i32* %27, i64 %28)
%30 = getelementptr inbounds [20 x i32], [20 x i32]* %14, i64 0, i64 0
%31 = getelementptr inbounds [84 x i32], [84 x i32]* %15, i64 0, i64 0
%32 = load i64, i64* %9
%33 = load i64, i64* %11
%34 = add i64 %32, %33
%35 = call i32 @JV_SHA1(i32* %30, i32* %31, i64 %34)
store i32 1, i32* %16
br label %36
36: ; preds = %53, %6
%37 = load i32, i32* %16
%38 = load i32, i32* %12
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %56
40: ; preds = %36
%41 = load i32, i32* %16
%42 = srem i32 %41, 2
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %40
%45 = getelementptr inbounds [20 x i32], [20 x i32]* %13, i64 0, i64 0
%46 = getelementptr inbounds [20 x i32], [20 x i32]* %14, i64 0, i64 0
%47 = call i32 @JV_SHA1(i32* %45, i32* %46, i64 20)
br label %52
48: ; preds = %40
%49 = getelementptr inbounds [20 x i32], [20 x i32]* %14, i64 0, i64 0
%50 = getelementptr inbounds [20 x i32], [20 x i32]* %13, i64 0, i64 0
%51 = call i32 @JV_SHA1(i32* %49, i32* %50, i64 20)
br label %52
52: ; preds = %48, %44
br label %53
53: ; preds = %52
%54 = load i32, i32* %16
%55 = add nsw i32 %54, 1
store i32 %55, i32* %16
br label %36
56: ; preds = %36
%57 = load i32, i32* %16
%58 = srem i32 %57, 2
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %56
%61 = load i32*, i32** %7
%62 = getelementptr inbounds [20 x i32], [20 x i32]* %14, i64 0, i64 0
%63 = call i32 @memcpy(i32* %61, i32* %62, i64 20)
br label %68
64: ; preds = %56
%65 = load i32*, i32** %7
%66 = getelementptr inbounds [20 x i32], [20 x i32]* %13, i64 0, i64 0
%67 = call i32 @memcpy(i32* %65, i32* %66, i64 20)
br label %68
68: ; preds = %64, %60
%69 = load i32*, i32** %7
ret i32* %69
}

LLVM IR (-O2):
define i32* @JV_PBKDF1(i32* returned %0, i32* %1, i64 %2, i32* %3, i64 %4, i32 %5) {
%7 = alloca [20 x i32]
%8 = alloca [20 x i32]
%9 = alloca [84 x i32]
%10 = bitcast [20 x i32]* %7 to i8*
%11 = bitcast [20 x i32]* %8 to i8*
%12 = bitcast [84 x i32]* %9 to i8*
%13 = getelementptr inbounds [84 x i32], [84 x i32]* %9, i64 0, i64 0
%14 = call i32 @memcpy(i32* %13, i32* %1, i64 %2)
%15 = getelementptr inbounds [84 x i32], [84 x i32]* %9, i64 0, i64 %2
%16 = call i32 @memcpy(i32* %15, i32* %3, i64 %4)
%17 = getelementptr inbounds [20 x i32], [20 x i32]* %8, i64 0, i64 0
%18 = add i64 %4, %2
%19 = call i32 @JV_SHA1(i32* %17, i32* %13, i64 %18)
%20 = icmp sgt i32 %5, 1
br i1 %20, label %21, label %39
21: ; preds = %6
%22 = getelementptr inbounds [20 x i32], [20 x i32]* %7, i64 0, i64 0
br label %23
23: ; preds = %21, %31
%24 = phi i32 [ 1, %21 ], [ %32, %31 ]
%25 = and i32 %24, 1
%26 = icmp eq i32 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %23
%28 = call i32 @JV_SHA1(i32* %22, i32* %17, i64 20)
br label %31
29: ; preds = %23
%30 = call i32 @JV_SHA1(i32* %17, i32* %22, i64 20)
br label %31
31: ; preds = %27, %29
%32 = add nuw nsw i32 %24, 1
%33 = icmp eq i32 %32, %5
br i1 %33, label %34, label %23
34: ; preds = %31
%35 = and i32 %5, 1
%36 = icmp eq i32 %35, 0
%37 = getelementptr inbounds [20 x i32], [20 x i32]* %7, i64 0, i64 0
%38 = select i1 %36, i32* %37, i32* %17
br label %39
39: ; preds = %34, %6
%40 = phi i32* [ %17, %6 ], [ %38, %34 ]
%41 = call i32 @memcpy(i32* %0, i32* %40, i64 20)
ret i32* %0
}