#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*/ tbuf;
typedef int /*<<< orphan*/ salt;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ generate_random_salt(char *, unsigned int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
const char *make_blowfish_salt(unsigned int rounds, unsigned int length) {
  static char salt[31];
  char tbuf[3];
  if (length < 22) {
    printf("Blowfish salt length too short\n");
    exit(EXIT_FAILURE);
  }
  snprintf(tbuf, sizeof(tbuf), "%02u", rounds);
  snprintf(salt, sizeof(salt), "$2a$%s$", tbuf);
  generate_random_salt(&salt[7], length);
  salt[length + 7] = '$';
  salt[length + 8] = '\0';
  return salt;
}


x86 assembly (clang, -O0):
<make_blowfish_salt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x16,-0x8(%rbp)
jae    1172 <make_blowfish_salt+0x32>
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
lea    -0xb(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0x3,%esi
lea    0xe9b(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
lea    -0xb(%rbp),%rcx
lea    0x2eb9(%rip),%rdi
mov    $0x1f,%esi
lea    0xe82(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    -0x8(%rbp),%esi
lea    0x2e9c(%rip),%rdi
add    $0x7,%rdi
call   1040 <generate_random_salt@plt>
mov    -0x8(%rbp),%eax
add    $0x7,%eax
mov    %eax,%eax
mov    %eax,%ecx
lea    0x2e82(%rip),%rax
movb   $0x24,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x8,%eax
mov    %eax,%eax
mov    %eax,%ecx
lea    0x2e6d(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e62(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_blowfish_salt>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x15,%esi
jbe    11b8 <make_blowfish_salt+0x78>
mov    %esi,%ebx
mov    %edi,%ecx
lea    0xea7(%rip),%rdx
lea    0xd(%rsp),%r14
mov    %r14,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <snprintf@plt>
lea    0x2edc(%rip),%r15
lea    0xe8a(%rip),%rdx
mov    %r15,%rdi
mov    $0x1f,%esi
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <snprintf@plt>
lea    0x2ec3(%rip),%rdi
mov    %ebx,%esi
call   1040 <generate_random_salt@plt>
lea    0x7(%rbx),%eax
movb   $0x24,(%rax,%r15,1)
add    $0x8,%ebx
movb   $0x0,(%rbx,%r15,1)
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe4e(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@make_blowfish_salt.salt = internal global [31 x i8] zeroinitializer
@.str = [32 x i8] c"Blowfish salt length too short\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"%02u\00"
@.str.2 = [8 x i8] c"$2a$%s$\00"
define i8* @make_blowfish_salt(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [3 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp ult i32 %6, 22
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%14 = load i32, i32* %3
%15 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %13, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%17 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @make_blowfish_salt.salt, i64 0, i64 0), i32 31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = load i32, i32* %4
%19 = call i32 @generate_random_salt(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @make_blowfish_salt.salt, i64 0, i64 7), i32 %18)
%20 = load i32, i32* %4
%21 = add i32 %20, 7
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [31 x i8], [31 x i8]* @make_blowfish_salt.salt, i64 0, i64 %22
store i8 36, i8* %23
%24 = load i32, i32* %4
%25 = add i32 %24, 8
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds [31 x i8], [31 x i8]* @make_blowfish_salt.salt, i64 0, i64 %26
store i8 0, i8* %27
ret i8* getelementptr inbounds ([31 x i8], [31 x i8]* @make_blowfish_salt.salt, i64 0, i64 0)
}

LLVM IR (-O2):
@make_blowfish_salt.salt = internal global [31 x i8] zeroinitializer
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"%02u\00"
@.str.2 = [8 x i8] c"$2a$%s$\00"
@str = [31 x i8] c"Blowfish salt length too short\00"
define i8* @make_blowfish_salt(i32 %0, i32 %1) {
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%5 = icmp ult i32 %1, 22
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %4, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%12 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @make_blowfish_salt.salt, i64 0, i64 0), i32 31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%13 = call i32 @generate_random_salt(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @make_blowfish_salt.salt, i64 0, i64 7), i32 %1)
%14 = add i32 %1, 7
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [31 x i8], [31 x i8]* @make_blowfish_salt.salt, i64 0, i64 %15
store i8 36, i8* %16
%17 = add i32 %1, 8
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds [31 x i8], [31 x i8]* @make_blowfish_salt.salt, i64 0, i64 %18
store i8 0, i8* %19
ret i8* getelementptr inbounds ([31 x i8], [31 x i8]* @make_blowfish_salt.salt, i64 0, i64 0)
}