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

/* Variables and functions */
scalar_t__ crypto_scrypt(int /*<<< orphan*/ const *, int /*<<< orphan*/,
                         int /*<<< orphan*/ const *, size_t, int, int, int,
                         int /*<<< orphan*/ *const, int);
scalar_t__ hashArray(int /*<<< orphan*/ *const, int, char *const, size_t const);
int /*<<< orphan*/ strlen(char const *const);
int mpw_core_calculate_master_key(char const *const masterPassword,
                                  char const *const masterKeySalt,
                                  size_t masterKeySaltLength,
                                  uint8_t *const masterKey, char *const keyID,
                                  const size_t keyIDLen) {
  if (crypto_scrypt((const uint8_t *)masterPassword, strlen(masterPassword),
                    (const uint8_t *)masterKeySalt, masterKeySaltLength, 32768,
                    8, 2, masterKey, 64) < 0) {
    return -1;
  }
  if (hashArray(masterKey, 64, keyID, keyIDLen)) {
    return -1;
  }
  do {
  } while (0);
  do {
  } while (0);
  do {
  } while (0);
  do {
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<mpw_core_calculate_master_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    $0x8000,%r8d
mov    $0x8,%r9d
movl   $0x2,(%rsp)
mov    %rax,0x8(%rsp)
movl   $0x40,0x10(%rsp)
call   1030 <crypto_scrypt@plt>
cmp    $0x0,%rax
jge    11ae <mpw_core_calculate_master_key+0x7e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1209 <mpw_core_calculate_master_key+0xd9>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    $0x40,%esi
call   1050 <hashArray@plt>
cmp    $0x0,%rax
je     11da <mpw_core_calculate_master_key+0xaa>
movl   $0xffffffff,-0x4(%rbp)
jmp    1209 <mpw_core_calculate_master_key+0xd9>
jmp    11df <mpw_core_calculate_master_key+0xaf>
jmp    11e4 <mpw_core_calculate_master_key+0xb4>
jmp    11e9 <mpw_core_calculate_master_key+0xb9>
jmp    11ee <mpw_core_calculate_master_key+0xbe>
jmp    11f3 <mpw_core_calculate_master_key+0xc3>
jmp    11f8 <mpw_core_calculate_master_key+0xc8>
jmp    11fd <mpw_core_calculate_master_key+0xcd>
jmp    1202 <mpw_core_calculate_master_key+0xd2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpw_core_calculate_master_key>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1040 <strlen@plt>
sub    $0x8,%rsp
mov    %rbp,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
mov    %r13,%rcx
mov    $0x8000,%r8d
mov    $0x8,%r9d
push   $0x40
push   %r12
push   $0x2
call   1030 <crypto_scrypt@plt>
add    $0x20,%rsp
test   %rax,%rax
js     119b <mpw_core_calculate_master_key+0x6b>
mov    %r12,%rdi
mov    $0x40,%esi
mov    %r15,%rdx
mov    %r14,%rcx
call   1050 <hashArray@plt>
neg    %rax
sbb    %eax,%eax
jmp    11a0 <mpw_core_calculate_master_key+0x70>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mpw_core_calculate_master_key(i8* %0, i8* %1, i64 %2, i32* %3, i8* %4, i64 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32*
%12 = alloca i8*
%13 = alloca i64
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
%14 = load i8*, i8** %8
%15 = bitcast i8* %14 to i32*
%16 = load i8*, i8** %8
%17 = call i32 @strlen(i8* %16)
%18 = load i8*, i8** %9
%19 = bitcast i8* %18 to i32*
%20 = load i64, i64* %10
%21 = load i32*, i32** %11
%22 = call i64 @crypto_scrypt(i32* %15, i32 %17, i32* %19, i64 %20, i32 32768, i32 8, i32 2, i32* %21, i32 64)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %6
store i32 -1, i32* %7
br label %41
25: ; preds = %6
%26 = load i32*, i32** %11
%27 = load i8*, i8** %12
%28 = load i64, i64* %13
%29 = call i64 @hashArray(i32* %26, i32 64, i8* %27, i64 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %25
store i32 -1, i32* %7
br label %41
32: ; preds = %25
br label %33
33: ; preds = %32
br label %34
34: ; preds = %33
br label %35
35: ; preds = %34
br label %36
36: ; preds = %35
br label %37
37: ; preds = %36
br label %38
38: ; preds = %37
br label %39
39: ; preds = %38
br label %40
40: ; preds = %39
store i32 0, i32* %7
br label %41
41: ; preds = %40, %31, %24
%42 = load i32, i32* %7
ret i32 %42
}

LLVM IR (-O2):
define i32 @mpw_core_calculate_master_key(i8* %0, i8* %1, i64 %2, i32* %3, i8* %4, i64 %5) {
%7 = bitcast i8* %0 to i32*
%8 = tail call i32 @strlen(i8* %0)
%9 = bitcast i8* %1 to i32*
%10 = tail call i64 @crypto_scrypt(i32* %7, i32 %8, i32* %9, i64 %2, i32 32768, i32 8, i32 2, i32* %3, i32 64)
%11 = icmp slt i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %6
%13 = tail call i64 @hashArray(i32* %3, i32 64, i8* %4, i64 %5)
%14 = icmp ne i64 %13, 0
%15 = sext i1 %14 to i32
br label %16
16: ; preds = %12, %6
%17 = phi i32 [ -1, %6 ], [ %15, %12 ]
ret i32 %17
}