#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 uint32_t;
typedef int /*<<< orphan*/ n_userNameLength;

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, char const *const, int);
char myHtonl(char);
int strlen(char const *const);
int mpw_core_calculate_master_key_salt(char const *const userName,
                                       char *const masterKeySalt,
                                       size_t *const masterKeySaltLength) {
  char const *const mpNameSpace = "com.lyndir.masterpassword";
  const uint32_t n_userNameLength = myHtonl((uint32_t)strlen(userName));
  *masterKeySaltLength =
      strlen(mpNameSpace) + sizeof(n_userNameLength) + strlen(userName);
  char *mKS = masterKeySalt;
  memcpy(mKS, mpNameSpace, strlen(mpNameSpace));
  mKS += strlen(mpNameSpace);
  memcpy(mKS, &n_userNameLength, sizeof(n_userNameLength));
  mKS += sizeof(n_userNameLength);
  memcpy(mKS, userName, strlen(userName));
  mKS += strlen(userName);
  if (mKS - masterKeySalt != *masterKeySaltLength) {
    return -1;
  }
  do {
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<mpw_core_calculate_master_key_salt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    0xeb5(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
movsbl %al,%edi
call   1040 <myHtonl@plt>
mov    %al,-0x29(%rbp)
lea    0xe96(%rip),%rdi
call   1030 <strlen@plt>
cltq
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x58(%rbp),%rcx
cltq
add    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    0xe57(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%edx
lea    0xe45(%rip),%rsi
call   1050 <memcpy@plt>
lea    0xe39(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%rax
je     125f <mpw_core_calculate_master_key_salt+0x12f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1270 <mpw_core_calculate_master_key_salt+0x140>
jmp    1264 <mpw_core_calculate_master_key_salt+0x134>
jmp    1269 <mpw_core_calculate_master_key_salt+0x139>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpw_core_calculate_master_key_salt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbp
call   1030 <strlen@plt>
movsbl %al,%edi
call   1040 <myHtonl@plt>
mov    %al,0x7(%rsp)
lea    0xea4(%rip),%r12
mov    %r12,%rdi
call   1030 <strlen@plt>
movslq %eax,%r13
mov    %rbp,%rdi
call   1030 <strlen@plt>
cltq
add    %r13,%rax
add    $0x1,%rax
mov    %rax,(%r14)
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbx
lea    (%r15,%rbx,1),%r12
lea    0x7(%rsp),%rsi
mov    %r12,%rdi
mov    $0x1,%edx
call   1050 <memcpy@plt>
lea    (%r15,%rbx,1),%r13
add    $0x1,%r13
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    %rbp,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rax,%r12,1),%rcx
add    $0x1,%rcx
sub    %r15,%rcx
xor    %eax,%eax
cmp    (%r14),%rcx
setne  %al
neg    %eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"com.lyndir.masterpassword\00"
define i32 @mpw_core_calculate_master_key_salt(i8* %0, i8* %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i8*
%9 = alloca i8
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64* %2, i64** %7
store i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8** %8
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = trunc i32 %12 to i8
%14 = call signext i8 @myHtonl(i8 signext %13)
store i8 %14, i8* %9
%15 = call i32 @strlen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i32 0, i32 0))
%16 = sext i32 %15 to i64
%17 = add i64 %16, 1
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
%20 = sext i32 %19 to i64
%21 = add i64 %17, %20
%22 = load i64*, i64** %7
store i64 %21, i64* %22
%23 = load i8*, i8** %6
store i8* %23, i8** %10
%24 = load i8*, i8** %10
%25 = call i32 @strlen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i32 0, i32 0))
%26 = call i32 @memcpy(i8* %24, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i32 0, i32 0), i32 %25)
%27 = call i32 @strlen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i32 0, i32 0))
%28 = load i8*, i8** %10
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds i8, i8* %28, i64 %29
store i8* %30, i8** %10
%31 = load i8*, i8** %10
%32 = call i32 @memcpy(i8* %31, i8* %9, i32 1)
%33 = load i8*, i8** %10
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8* %34, i8** %10
%35 = load i8*, i8** %10
%36 = load i8*, i8** %5
%37 = load i8*, i8** %5
%38 = call i32 @strlen(i8* %37)
%39 = call i32 @memcpy(i8* %35, i8* %36, i32 %38)
%40 = load i8*, i8** %5
%41 = call i32 @strlen(i8* %40)
%42 = load i8*, i8** %10
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds i8, i8* %42, i64 %43
store i8* %44, i8** %10
%45 = load i8*, i8** %10
%46 = load i8*, i8** %6
%47 = ptrtoint i8* %45 to i64
%48 = ptrtoint i8* %46 to i64
%49 = sub i64 %47, %48
%50 = load i64*, i64** %7
%51 = load i64, i64* %50
%52 = icmp ne i64 %49, %51
br i1 %52, label %53, label %54
53: ; preds = %3
store i32 -1, i32* %4
br label %57
54: ; preds = %3
br label %55
55: ; preds = %54
br label %56
56: ; preds = %55
store i32 0, i32* %4
br label %57
57: ; preds = %56, %53
%58 = load i32, i32* %4
ret i32 %58
}

LLVM IR (-O2):
@.str = [26 x i8] c"com.lyndir.masterpassword\00"
define i32 @mpw_core_calculate_master_key_salt(i8* %0, i8* %1, i64* nocapture %2) {
%4 = alloca i8
%5 = tail call i32 @strlen(i8* %0)
%6 = trunc i32 %5 to i8
%7 = tail call signext i8 @myHtonl(i8 signext %6)
store i8 %7, i8* %4
%8 = tail call i32 @strlen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%9 = sext i32 %8 to i64
%10 = add nsw i64 %9, 1
%11 = tail call i32 @strlen(i8* %0)
%12 = sext i32 %11 to i64
%13 = add nsw i64 %10, %12
store i64 %13, i64* %2
%14 = tail call i32 @strlen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @memcpy(i8* %1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = tail call i32 @strlen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %1, i64 %17
%19 = call i32 @memcpy(i8* %18, i8* %4, i32 1)
%20 = getelementptr inbounds i8, i8* %18, i64 1
%21 = call i32 @strlen(i8* %0)
%22 = call i32 @memcpy(i8* %20, i8* %0, i32 %21)
%23 = call i32 @strlen(i8* %0)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %20, i64 %24
%26 = ptrtoint i8* %25 to i64
%27 = ptrtoint i8* %1 to i64
%28 = sub i64 %26, %27
%29 = load i64, i64* %2
%30 = icmp ne i64 %28, %29
%31 = sext i1 %30 to i32
ret i32 %31
}