#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 char uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ EVP_sha512();
int /*<<< orphan*/ PKCS5_PBKDF2_HMAC(char *, int, char *, int, int,
                                     int /*<<< orphan*/, int, char *);
int atoi(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ hextorb(char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int strlen(char *);
int main(int argc, char **argv) {
  uint8_t k_user[2048];
  uint8_t salt[2048];
  uint8_t key[4096];
  uint32_t key_length = atoi(argv[1]);
  uint32_t iteration_count = atoi(argv[2]);
  hextorb(argv[3], salt);
  uint32_t salt_length = strlen(argv[3]) / 2;
  fgets(k_user, 2048, stdin);
  uint32_t k_user_length = strlen(k_user);
  if (k_user[k_user_length - 1] == '\n') {
    k_user[k_user_length - 1] = '\0';
  }
  PKCS5_PBKDF2_HMAC(k_user, k_user_length, salt, salt_length, iteration_count,
                    EVP_sha512(), key_length, key);
  fwrite(key, 1, key_length, stdout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2050,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x2014(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x2018(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    -0x1010(%rbp),%rsi
call   1070 <hextorb@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1050 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x201c(%rbp)
lea    -0x810(%rbp),%rdi
mov    0x2dfc(%rip),%rax
mov    (%rax),%edx
mov    $0x800,%esi
call   1060 <fgets@plt>
lea    -0x810(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x2020(%rbp)
mov    -0x2020(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x810(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1239 <main+0xc9>
mov    -0x2020(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x810(%rbp,%rax,1)
lea    -0x810(%rbp),%rax
mov    %rax,-0x2040(%rbp)
mov    -0x2020(%rbp),%eax
mov    %eax,-0x2034(%rbp)
lea    -0x1010(%rbp),%rax
mov    %rax,-0x2030(%rbp)
mov    -0x201c(%rbp),%eax
mov    %eax,-0x2028(%rbp)
mov    -0x2018(%rbp),%eax
mov    %eax,-0x2024(%rbp)
mov    $0x0,%al
call   1040 <EVP_sha512@plt>
mov    -0x2040(%rbp),%rdi
mov    -0x2034(%rbp),%esi
mov    -0x2030(%rbp),%rdx
mov    -0x2028(%rbp),%ecx
mov    -0x2024(%rbp),%r8d
mov    %eax,%r9d
mov    -0x2014(%rbp),%r10d
lea    -0x2010(%rbp),%rax
mov    %r10d,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <PKCS5_PBKDF2_HMAC@plt>
lea    -0x2010(%rbp),%rdi
mov    -0x2014(%rbp),%edx
mov    0x2d04(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1090 <fwrite@plt>
xor    %eax,%eax
add    $0x2050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2008,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
mov    0x10(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
mov    0x18(%rbx),%rdi
lea    0x800(%rsp),%rsi
call   1070 <hextorb@plt>
mov    0x18(%rbx),%rdi
call   1050 <strlen@plt>
mov    %eax,%r13d
mov    0x2e28(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x800,%esi
call   1060 <fgets@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
cltq
cmpb   $0xa,-0x1(%rax,%r12,1)
jne    11eb <main+0x7b>
movb   $0x0,-0x1(%rsp,%rax,1)
mov    %r13d,%ebp
shr    $0x1f,%ebp
add    %r13d,%ebp
sar    %ebp
xor    %eax,%eax
call   1040 <EVP_sha512@plt>
lea    0x1000(%rsp),%r12
mov    %rsp,%rdi
lea    0x800(%rsp),%rdx
mov    %ebx,%esi
mov    %ebp,%ecx
mov    %r14d,%r8d
mov    %eax,%r9d
push   %r12
push   %r15
call   1030 <PKCS5_PBKDF2_HMAC@plt>
add    $0x10,%rsp
mov    0x2daa(%rip),%rax
mov    (%rax),%ecx
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
call   1090 <fwrite@plt>
xor    %eax,%eax
add    $0x2008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2048 x i8]
%7 = alloca [2048 x i8]
%8 = alloca [4096 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %9
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %10
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 3
%23 = load i8*, i8** %22
%24 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%25 = call i32 @hextorb(i8* %23, i8* %24)
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 3
%28 = load i8*, i8** %27
%29 = call i32 @strlen(i8* %28)
%30 = sdiv i32 %29, 2
store i32 %30, i32* %11
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%32 = load i32, i32* @stdin
%33 = call i32 @fgets(i8* %31, i32 2048, i32 %32)
%34 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%35 = call i32 @strlen(i8* %34)
store i32 %35, i32* %12
%36 = load i32, i32* %12
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 10
br i1 %42, label %43, label %48
43: ; preds = %2
%44 = load i32, i32* %12
%45 = sub nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 %46
store i8 0, i8* %47
br label %48
48: ; preds = %43, %2
%49 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%50 = load i32, i32* %12
%51 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%52 = load i32, i32* %11
%53 = load i32, i32* %10
%54 = call i32 (...) @EVP_sha512()
%55 = load i32, i32* %9
%56 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%57 = call i32 @PKCS5_PBKDF2_HMAC(i8* %49, i32 %50, i8* %51, i32 %52, i32 %53, i32 %54, i32 %55, i8* %56)
%58 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%59 = load i32, i32* %9
%60 = load i32, i32* @stdout
%61 = call i32 @fwrite(i8* %58, i32 1, i32 %59, i32 %60)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2048 x i8]
%4 = alloca [2048 x i8]
%5 = alloca [4096 x i8]
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 3
%16 = load i8*, i8** %15
%17 = call i32 @hextorb(i8* %16, i8* %7)
%18 = load i8*, i8** %15
%19 = call i32 @strlen(i8* %18)
%20 = load i32, i32* @stdin
%21 = call i32 @fgets(i8* %6, i32 2048, i32 %20)
%22 = call i32 @strlen(i8* %6)
%23 = add nsw i32 %22, -1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 10
br i1 %27, label %28, label %29
28: ; preds = %2
store i8 0, i8* %25
br label %29
29: ; preds = %28, %2
%30 = sdiv i32 %19, 2
%31 = call i32 (...) @EVP_sha512()
%32 = call i32 @PKCS5_PBKDF2_HMAC(i8* %6, i32 %22, i8* %7, i32 %30, i32 %14, i32 %31, i32 %11, i8* %8)
%33 = load i32, i32* @stdout
%34 = call i32 @fwrite(i8* %8, i32 1, i32 %11, i32 %33)
ret i32 0
}