#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 /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, size_t);
int /*<<< orphan*/ pbkdf2_sha1_f(char *, char *, size_t, int, int,
                                 unsigned char *, int /*<<< orphan*/);
void pbkdf2_sha1(char *passphrase, char *ssid, size_t ssid_len, int iterations,
                 unsigned char *buf, size_t buflen, int usecached) {
  int count = 0;
  unsigned char *pos = buf;
  size_t left = buflen, plen;
  unsigned char digest[20];
  while (left > 0) {
    count++;
    pbkdf2_sha1_f(passphrase, ssid, ssid_len, iterations, count, digest, 0);
    plen = left > 20 ? 20 : left;
    memcpy(pos, digest, plen);
    pos += plen;
    left -= plen;
  }
}


x86 assembly (clang, -O0):
<pbkdf2_sha1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jbe    11ef <pbkdf2_sha1+0xcf>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x34(%rbp),%r8d
lea    -0x70(%rbp),%r9
xor    %eax,%eax
movl   $0x0,(%rsp)
call   1040 <pbkdf2_sha1_f@plt>
cmpq   $0x14,-0x48(%rbp)
jbe    11ae <pbkdf2_sha1+0x8e>
mov    $0x14,%eax
mov    %rax,-0x78(%rbp)
jmp    11b6 <pbkdf2_sha1+0x96>
mov    -0x48(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    -0x50(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x50(%rbp),%rax
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x48(%rbp)
jmp    115c <pbkdf2_sha1+0x3c>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pbkdf2_sha1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
test   %r9,%r9
je     119d <pbkdf2_sha1+0x7d>
mov    %r9,%rbx
mov    %r8,%r14
mov    %ecx,%ebp
mov    %rdx,%r12
mov    $0x1,%r15d
mov    %rsi,0x18(%rsp)
mov    %rdi,0x10(%rsp)
xchg   %ax,%ax
movl   $0x0,(%rsp)
mov    0x10(%rsp),%rdi
mov    0x18(%rsp),%rsi
mov    %r12,%rdx
mov    %ebp,%ecx
mov    %r15d,%r8d
lea    0x20(%rsp),%r9
call   1040 <pbkdf2_sha1_f@plt>
cmp    $0x14,%rbx
mov    $0x14,%r13d
cmovb  %rbx,%r13
mov    %r14,%rdi
lea    0x20(%rsp),%rsi
mov    %r13,%rdx
call   1030 <memcpy@plt>
add    %r13,%r14
add    $0x1,%r15d
sub    %r13,%rbx
jne    1150 <pbkdf2_sha1+0x30>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @pbkdf2_sha1(i8* %0, i8* %1, i64 %2, i32 %3, i8* %4, i64 %5, i32 %6) {
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i64
%19 = alloca [20 x i8]
store i8* %0, i8** %8
store i8* %1, i8** %9
store i64 %2, i64* %10
store i32 %3, i32* %11
store i8* %4, i8** %12
store i64 %5, i64* %13
store i32 %6, i32* %14
store i32 0, i32* %15
%20 = load i8*, i8** %12
store i8* %20, i8** %16
%21 = load i64, i64* %13
store i64 %21, i64* %17
br label %22
22: ; preds = %40, %7
%23 = load i64, i64* %17
%24 = icmp ugt i64 %23, 0
br i1 %24, label %25, label %52
25: ; preds = %22
%26 = load i32, i32* %15
%27 = add nsw i32 %26, 1
store i32 %27, i32* %15
%28 = load i8*, i8** %8
%29 = load i8*, i8** %9
%30 = load i64, i64* %10
%31 = load i32, i32* %11
%32 = load i32, i32* %15
%33 = getelementptr inbounds [20 x i8], [20 x i8]* %19, i64 0, i64 0
%34 = call i32 @pbkdf2_sha1_f(i8* %28, i8* %29, i64 %30, i32 %31, i32 %32, i8* %33, i32 0)
%35 = load i64, i64* %17
%36 = icmp ugt i64 %35, 20
br i1 %36, label %37, label %38
37: ; preds = %25
br label %40
38: ; preds = %25
%39 = load i64, i64* %17
br label %40
40: ; preds = %38, %37
%41 = phi i64 [ 20, %37 ], [ %39, %38 ]
store i64 %41, i64* %18
%42 = load i8*, i8** %16
%43 = getelementptr inbounds [20 x i8], [20 x i8]* %19, i64 0, i64 0
%44 = load i64, i64* %18
%45 = call i32 @memcpy(i8* %42, i8* %43, i64 %44)
%46 = load i64, i64* %18
%47 = load i8*, i8** %16
%48 = getelementptr inbounds i8, i8* %47, i64 %46
store i8* %48, i8** %16
%49 = load i64, i64* %18
%50 = load i64, i64* %17
%51 = sub i64 %50, %49
store i64 %51, i64* %17
br label %22
52: ; preds = %22
ret void
}

LLVM IR (-O2):
define void @pbkdf2_sha1(i8* %0, i8* %1, i64 %2, i32 %3, i8* %4, i64 %5, i32 %6) {
%8 = alloca [20 x i8]
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%10 = icmp eq i64 %5, 0
br i1 %10, label %23, label %11
11: ; preds = %7, %11
%12 = phi i32 [ %15, %11 ], [ 0, %7 ]
%13 = phi i64 [ %21, %11 ], [ %5, %7 ]
%14 = phi i8* [ %20, %11 ], [ %4, %7 ]
%15 = add nuw nsw i32 %12, 1
%16 = call i32 @pbkdf2_sha1_f(i8* %0, i8* %1, i64 %2, i32 %3, i32 %15, i8* %9, i32 0)
%17 = icmp ult i64 %13, 20
%18 = select i1 %17, i64 %13, i64 20
%19 = call i32 @memcpy(i8* %14, i8* %9, i64 %18)
%20 = getelementptr inbounds i8, i8* %14, i64 %18
%21 = sub i64 %13, %18
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %11
23: ; preds = %11, %7
ret void
}