#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);
int /*<<< orphan*/ l64a(int /*<<< orphan*/);
int /*<<< orphan*/ random();
int /*<<< orphan*/ seedRNG();
int /*<<< orphan*/ strcat(char *, int /*<<< orphan*/);
size_t strlen(char *);
const char *gensalt(size_t salt_size) {
  static char salt[32];
  salt[0] = '\0';
  assert(salt_size >= 8 && salt_size <= 16);
  seedRNG();
  strcat(salt, l64a(random()));
  do {
    strcat(salt, l64a(random()));
  } while (strlen(salt) < salt_size);
  salt[salt_size] = '\0';
  return salt;
}


x86 assembly (clang, -O0):
<gensalt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,0x2eed(%rip)
xor    %eax,%eax
cmpq   $0x8,-0x8(%rbp)
mov    %al,-0x9(%rbp)
jb     118e <gensalt+0x2e>
cmpq   $0x10,-0x8(%rbp)
setbe  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x0,%al
call   1030 <seedRNG@plt>
mov    $0x0,%al
call   1070 <random@plt>
mov    %eax,%edi
call   1060 <l64a@plt>
mov    %eax,%esi
lea    0x2ea7(%rip),%rdi
call   1080 <strcat@plt>
mov    $0x0,%al
call   1070 <random@plt>
mov    %eax,%edi
call   1060 <l64a@plt>
mov    %eax,%esi
lea    0x2e8b(%rip),%rdi
call   1080 <strcat@plt>
lea    0x2e7f(%rip),%rdi
call   1040 <strlen@plt>
cmp    -0x8(%rbp),%rax
jb     11be <gensalt+0x5e>
mov    -0x8(%rbp),%rcx
lea    0x2e65(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e5a(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gensalt>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movb   $0x0,0x2ef2(%rip)
lea    0x2eeb(%rip),%r14
lea    -0x8(%rdi),%rax
xor    %edi,%edi
cmp    $0x9,%rax
setb   %dil
call   1050 <assert@plt>
xor    %eax,%eax
call   1030 <seedRNG@plt>
xor    %eax,%eax
call   1070 <random@plt>
mov    %eax,%edi
call   1060 <l64a@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1080 <strcat@plt>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <random@plt>
mov    %eax,%edi
call   1060 <l64a@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1080 <strcat@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %rbx,%rax
jb     11b0 <gensalt+0x50>
movb   $0x0,(%rbx,%r14,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@gensalt.salt = internal global [32 x i8] zeroinitializer
define i8* @gensalt(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
store i8 0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @gensalt.salt, i64 0, i64 0)
%3 = load i64, i64* %2
%4 = icmp uge i64 %3, 8
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = load i64, i64* %2
%7 = icmp ule i64 %6, 16
br label %8
8: ; preds = %5, %1
%9 = phi i1 [ false, %1 ], [ %7, %5 ]
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = call i32 (...) @seedRNG()
%13 = call i32 (...) @random()
%14 = call i32 @l64a(i32 %13)
%15 = call i32 @strcat(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @gensalt.salt, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %20, %8
%17 = call i32 (...) @random()
%18 = call i32 @l64a(i32 %17)
%19 = call i32 @strcat(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @gensalt.salt, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %16
%21 = call i64 @strlen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @gensalt.salt, i64 0, i64 0))
%22 = load i64, i64* %2
%23 = icmp ult i64 %21, %22
br i1 %23, label %16, label %24
24: ; preds = %20
%25 = load i64, i64* %2
%26 = getelementptr inbounds [32 x i8], [32 x i8]* @gensalt.salt, i64 0, i64 %25
store i8 0, i8* %26
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @gensalt.salt, i64 0, i64 0)
}

LLVM IR (-O2):
@gensalt.salt = internal global [32 x i8] zeroinitializer
define i8* @gensalt(i64 %0) {
store i8 0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @gensalt.salt, i64 0, i64 0)
%2 = add i64 %0, -8
%3 = icmp ult i64 %2, 9
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i32 (...) @seedRNG()
%7 = tail call i32 (...) @random()
%8 = tail call i32 @l64a(i32 %7)
%9 = tail call i32 @strcat(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @gensalt.salt, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %10, %1
%11 = tail call i32 (...) @random()
%12 = tail call i32 @l64a(i32 %11)
%13 = tail call i32 @strcat(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @gensalt.salt, i64 0, i64 0), i32 %12)
%14 = tail call i64 @strlen(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @gensalt.salt, i64 0, i64 0))
%15 = icmp ult i64 %14, %0
br i1 %15, label %10, label %16
16: ; preds = %10
%17 = getelementptr inbounds [32 x i8], [32 x i8]* @gensalt.salt, i64 0, i64 %0
store i8 0, i8* %17
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @gensalt.salt, i64 0, i64 0)
}