#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(int /*<<< orphan*/);
int /*<<< orphan*/ generate_random_salt(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
char *make_bf_salt(int rounds, int length) {
  static char salt[31];
  char tbuf[3];
  if (length > 22) {
    printf("BlowFish salt length too long\n");
    exit(0);
  }
  sprintf(tbuf, "%02d", rounds);
  sprintf(salt, "$2a$%s$", tbuf);
  generate_random_salt(&salt[7], length);
  salt[length + 7] = '$';
  salt[length + 8] = '\0';
  return salt;
}


x86 assembly (clang, -O0):
<make_bf_salt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x16,-0x8(%rbp)
jle    116b <make_bf_salt+0x2b>
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
lea    -0xb(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xea6(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    -0xb(%rbp),%rdx
lea    0x2ec5(%rip),%rdi
lea    0xe92(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%esi
lea    0x2ead(%rip),%rdi
add    $0x7,%rdi
call   1040 <generate_random_salt@plt>
mov    -0x8(%rbp),%eax
add    $0x7,%eax
movslq %eax,%rcx
lea    0x2e94(%rip),%rax
movb   $0x24,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x8,%eax
movslq %eax,%rcx
lea    0x2e80(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e75(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_bf_salt>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x17,%esi
jge    11a9 <make_bf_salt+0x69>
mov    %esi,%ebx
mov    %edi,%edx
lea    0xea7(%rip),%rsi
lea    0xd(%rsp),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    0x2ee1(%rip),%r15
lea    0xe8f(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    0x2ecd(%rip),%rdi
mov    %ebx,%esi
call   1040 <generate_random_salt@plt>
movslq %ebx,%rax
movw   $0x24,0x7(%rax,%r15,1)
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe5d(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@make_bf_salt.salt = internal global [31 x i8] zeroinitializer
@.str = [31 x i8] c"BlowFish salt length too long\0A\00"
@.str.1 = [5 x i8] c"%02d\00"
@.str.2 = [8 x i8] c"$2a$%s$\00"
define i8* @make_bf_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 sgt i32 %6, 22
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 0)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%13 = load i32, i32* %3
%14 = call i32 (i8*, i8*, ...) @sprintf(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%16 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @make_bf_salt.salt, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = load i32, i32* %4
%18 = call i32 @generate_random_salt(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @make_bf_salt.salt, i64 0, i64 7), i32 %17)
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [31 x i8], [31 x i8]* @make_bf_salt.salt, i64 0, i64 %21
store i8 36, i8* %22
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [31 x i8], [31 x i8]* @make_bf_salt.salt, i64 0, i64 %25
store i8 0, i8* %26
ret i8* getelementptr inbounds ([31 x i8], [31 x i8]* @make_bf_salt.salt, i64 0, i64 0)
}

LLVM IR (-O2):
@make_bf_salt.salt = internal global [31 x i8] zeroinitializer
@.str.1 = [5 x i8] c"%02d\00"
@.str.2 = [8 x i8] c"$2a$%s$\00"
@str = [30 x i8] c"BlowFish salt length too long\00"
define i8* @make_bf_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 sgt i32 %1, 22
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %2
%10 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%11 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @make_bf_salt.salt, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%12 = call i32 @generate_random_salt(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @make_bf_salt.salt, i64 0, i64 7), i32 %1)
%13 = add nsw i32 %1, 7
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [31 x i8], [31 x i8]* @make_bf_salt.salt, i64 0, i64 %14
store i8 36, i8* %15
%16 = add nsw i32 %1, 8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [31 x i8], [31 x i8]* @make_bf_salt.salt, i64 0, i64 %17
store i8 0, i8* %18
ret i8* getelementptr inbounds ([31 x i8], [31 x i8]* @make_bf_salt.salt, i64 0, i64 0)
}