#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*/ assert(int);
scalar_t__ crypto_file_rng(char *, int /*<<< orphan*/ *, unsigned char *, int);
scalar_t__ crypto_sha256(unsigned char *, unsigned int const, unsigned char *);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(unsigned int const);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *,
                          unsigned int const);
extern int crypto_salted_sha256(const unsigned char *data,
                                const unsigned int length,
                                unsigned char *salted_hash) {
  int ret;
  unsigned char *buf = malloc(length + 8);
  assert(data && salted_hash);
  if (!buf)
    return 1;
  if (crypto_file_rng("/dev/urandom", NULL, buf, 8) != 0) {
    ret = 2;
    goto cleanup;
  }
  memcpy(salted_hash, buf, 8);
  memcpy(buf + 8, data, length);
  if (crypto_sha256(buf, length + 8, salted_hash + 8) != 0) {
    ret = 3;
    goto cleanup;
  }
  ret = 0;
cleanup:
  free(buf);
  return ret;
}


x86 assembly (clang, -O0):
<crypto_salted_sha256>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x14(%rbp),%edi
add    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x31(%rbp)
je     119d <crypto_salted_sha256+0x3d>
cmpq   $0x0,-0x20(%rbp)
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x30(%rbp)
jne    11c1 <crypto_salted_sha256+0x61>
movl   $0x1,-0x4(%rbp)
jmp    1259 <crypto_salted_sha256+0xf9>
mov    -0x30(%rbp),%rdx
lea    0xe34(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x8,%ecx
call   1080 <crypto_file_rng@plt>
cmp    $0x0,%rax
je     11f0 <crypto_salted_sha256+0x90>
movl   $0x2,-0x24(%rbp)
jmp    124a <crypto_salted_sha256+0xea>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x8,%edx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rdi
add    $0x8,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x8,%esi
mov    -0x20(%rbp),%rdx
add    $0x8,%rdx
call   1070 <crypto_sha256@plt>
cmp    $0x0,%rax
je     1243 <crypto_salted_sha256+0xe3>
movl   $0x3,-0x24(%rbp)
jmp    124a <crypto_salted_sha256+0xea>
movl   $0x0,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_salted_sha256>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r12d
mov    %rdi,%r13
lea    0x8(%r12),%r15d
mov    %r15d,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %r13,%r13
setne  %al
test   %r14,%r14
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
test   %rbx,%rbx
je     1208 <crypto_salted_sha256+0xa8>
lea    0xe5a(%rip),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    $0x8,%ecx
call   1080 <crypto_file_rng@plt>
mov    $0x2,%ebp
test   %rax,%rax
jne    11fe <crypto_salted_sha256+0x9e>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1050 <memcpy@plt>
mov    %rbx,%rdi
add    $0x8,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
call   1050 <memcpy@plt>
add    $0x8,%r14
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14,%rdx
call   1070 <crypto_sha256@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    (%rcx,%rcx,2),%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    120d <crypto_salted_sha256+0xad>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
define i32 @crypto_salted_sha256(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%10 = load i32, i32* %6
%11 = add i32 %10, 8
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %9
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load i8*, i8** %7
%17 = icmp ne i8* %16, null
br label %18
18: ; preds = %15, %3
%19 = phi i1 [ false, %3 ], [ %17, %15 ]
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i8*, i8** %9
%23 = icmp ne i8* %22, null
br i1 %23, label %25, label %24
24: ; preds = %18
store i32 1, i32* %4
br label %52
25: ; preds = %18
%26 = load i8*, i8** %9
%27 = call i64 @crypto_file_rng(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32* null, i8* %26, i32 8)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 2, i32* %8
br label %48
30: ; preds = %25
%31 = load i8*, i8** %7
%32 = load i8*, i8** %9
%33 = call i32 @memcpy(i8* %31, i8* %32, i32 8)
%34 = load i8*, i8** %9
%35 = getelementptr inbounds i8, i8* %34, i64 8
%36 = load i8*, i8** %5
%37 = load i32, i32* %6
%38 = call i32 @memcpy(i8* %35, i8* %36, i32 %37)
%39 = load i8*, i8** %9
%40 = load i32, i32* %6
%41 = add i32 %40, 8
%42 = load i8*, i8** %7
%43 = getelementptr inbounds i8, i8* %42, i64 8
%44 = call i64 @crypto_sha256(i8* %39, i32 %41, i8* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %30
store i32 3, i32* %8
br label %48
47: ; preds = %30
store i32 0, i32* %8
br label %48
48: ; preds = %47, %46, %29
%49 = load i8*, i8** %9
%50 = call i32 @free(i8* %49)
%51 = load i32, i32* %8
store i32 %51, i32* %4
br label %52
52: ; preds = %48, %24
%53 = load i32, i32* %4
ret i32 %53
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
define i32 @crypto_salted_sha256(i8* %0, i32 %1, i8* %2) {
%4 = add i32 %1, 8
%5 = tail call i8* @malloc(i32 %4)
%6 = icmp ne i8* %0, null
%7 = icmp ne i8* %2, null
%8 = and i1 %6, %7
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = icmp eq i8* %5, null
br i1 %11, label %26, label %12
12: ; preds = %3
%13 = tail call i64 @crypto_file_rng(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32* null, i8* %5, i32 8)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = tail call i32 @memcpy(i8* %2, i8* %5, i32 8)
%17 = getelementptr inbounds i8, i8* %5, i64 8
%18 = tail call i32 @memcpy(i8* %17, i8* %0, i32 %1)
%19 = getelementptr inbounds i8, i8* %2, i64 8
%20 = tail call i64 @crypto_sha256(i8* %5, i32 %4, i8* %19)
%21 = icmp eq i64 %20, 0
%22 = select i1 %21, i32 0, i32 3
br label %23
23: ; preds = %15, %12
%24 = phi i32 [ 2, %12 ], [ %22, %15 ]
%25 = tail call i32 @free(i8* %5)
br label %26
26: ; preds = %3, %23
%27 = phi i32 [ %24, %23 ], [ 1, %3 ]
ret i32 %27
}