#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ generate_random_salt(char *, unsigned int);
int /*<<< orphan*/ printf(char *);
const char *make_sha512_salt(unsigned int length) {
  static char salt[21];
  if (length > 16) {
    printf("SHA-512 salt length too long\n");
    exit(EXIT_FAILURE);
  }
  salt[0] = '$';
  salt[1] = '6';
  salt[2] = '$';
  generate_random_salt(&salt[3], length);
  salt[length + 3] = '$';
  salt[length + 4] = '\0';
  return salt;
}


x86 assembly (clang, -O0):
<make_sha512_salt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x10,-0x4(%rbp)
jbe    115f <make_sha512_salt+0x2f>
lea    0xeb4(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
movb   $0x24,0x2eea(%rip)
movb   $0x36,0x2ee4(%rip)
movb   $0x24,0x2ede(%rip)
mov    -0x4(%rbp),%esi
lea    0x2ed2(%rip),%rdi
add    $0x3,%rdi
call   1040 <generate_random_salt@plt>
mov    -0x4(%rbp),%eax
add    $0x3,%eax
mov    %eax,%eax
mov    %eax,%ecx
lea    0x2eb8(%rip),%rax
movb   $0x24,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
add    $0x4,%eax
mov    %eax,%eax
mov    %eax,%ecx
lea    0x2ea3(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e98(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_sha512_salt>:
push   %r14
push   %rbx
push   %rax
cmp    $0x11,%edi
jae    1175 <make_sha512_salt+0x45>
mov    %edi,%ebx
movw   $0x3624,0x2f0c(%rip)
24 36
lea    0x2f05(%rip),%r14
movb   $0x24,0x2f00(%rip)
lea    0x2efa(%rip),%rdi
mov    %ebx,%esi
call   1040 <generate_random_salt@plt>
mov    %ebx,%eax
movw   $0x24,0x3(%rax,%r14,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@make_sha512_salt.salt = internal global [21 x i8] zeroinitializer
@.str = [30 x i8] c"SHA-512 salt length too long\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @make_sha512_salt(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp ugt i32 %3, 16
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = call i32 @exit(i32 %7)
unreachable
9: ; preds = %1
store i8 36, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @make_sha512_salt.salt, i64 0, i64 0)
store i8 54, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @make_sha512_salt.salt, i64 0, i64 1)
store i8 36, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @make_sha512_salt.salt, i64 0, i64 2)
%10 = load i32, i32* %2
%11 = call i32 @generate_random_salt(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @make_sha512_salt.salt, i64 0, i64 3), i32 %10)
%12 = load i32, i32* %2
%13 = add i32 %12, 3
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds [21 x i8], [21 x i8]* @make_sha512_salt.salt, i64 0, i64 %14
store i8 36, i8* %15
%16 = load i32, i32* %2
%17 = add i32 %16, 4
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds [21 x i8], [21 x i8]* @make_sha512_salt.salt, i64 0, i64 %18
store i8 0, i8* %19
ret i8* getelementptr inbounds ([21 x i8], [21 x i8]* @make_sha512_salt.salt, i64 0, i64 0)
}

LLVM IR (-O2):
@make_sha512_salt.salt = internal global [21 x i8] zeroinitializer
@EXIT_FAILURE = global i32 0
@str = [29 x i8] c"SHA-512 salt length too long\00"
define i8* @make_sha512_salt(i32 %0) {
%2 = icmp ugt i32 %0, 16
br i1 %2, label %3, label %7
3: ; preds = %1
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%5 = load i32, i32* @EXIT_FAILURE
%6 = tail call i32 @exit(i32 %5)
unreachable
7: ; preds = %1
store i8 36, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @make_sha512_salt.salt, i64 0, i64 0)
store i8 54, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @make_sha512_salt.salt, i64 0, i64 1)
store i8 36, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @make_sha512_salt.salt, i64 0, i64 2)
%8 = tail call i32 @generate_random_salt(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @make_sha512_salt.salt, i64 0, i64 3), i32 %0)
%9 = add nuw nsw i32 %0, 3
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds [21 x i8], [21 x i8]* @make_sha512_salt.salt, i64 0, i64 %10
store i8 36, i8* %11
%12 = add nuw nsw i32 %0, 4
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds [21 x i8], [21 x i8]* @make_sha512_salt.salt, i64 0, i64 %13
store i8 0, i8* %14
ret i8* getelementptr inbounds ([21 x i8], [21 x i8]* @make_sha512_salt.salt, i64 0, i64 0)
}