#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 */
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int rand();
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *generate_salt(int type) {
  char *salt, *rsalt;
  int i, size;
  size = 8;
  if (type > 0x31)
    size *= 2;
  if ((salt = malloc(sizeof(char) * (size + 4))) == NULL)
    return (char *)0;
  rsalt = salt;
  memset(salt, 0, sizeof(char) * (size + 4));
  sprintf(salt, "$%c$", type);
  rsalt += 3;
  srand(time(NULL));
  for (i = 0; i < size; i++) {
    int key = rand() % 64;
    *rsalt =
        "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/."[key];
    rsalt++;
  }
  rsalt = 0;
  return salt;
}


x86 assembly (clang, -O0):
<generate_salt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
movl   $0x8,-0x28(%rbp)
cmpl   $0x31,-0xc(%rbp)
jle    1185 <generate_salt+0x25>
mov    -0x28(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    $0x4,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b3 <generate_salt+0x53>
movq   $0x0,-0x8(%rbp)
jmp    1266 <generate_salt+0x106>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%eax
add    $0x4,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe1e(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1256 <generate_salt+0xf6>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x40,%ecx
cltd
idiv   %ecx
mov    %edx,-0x2c(%rbp)
movslq -0x2c(%rbp),%rcx
lea    0xdd2(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    120a <generate_salt+0xaa>
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_salt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
xor    %ebx,%ebx
cmp    $0x32,%edi
setge  %bl
lea    0xc(,%rbx,8),%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     11f8 <generate_salt+0x98>
lea    0x8(,%rbx,8),%ebx
mov    %r15,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1030 <memset@plt>
lea    0xe5e(%rip),%rsi
mov    %r15,%rdi
mov    %r14d,%edx
call   1070 <sprintf@plt>
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    %ebx,%ebp
lea    0xe41(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <rand@plt>
lea    0x3f(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffffffc0,%ecx
sub    %ecx,%eax
cltq
movzbl (%rax,%r14,1),%eax
mov    %al,0x3(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %ebx,%ebp
jne    11d0 <generate_salt+0x70>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"$%c$\00"
@.str.1 = [65 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/.\00"
define i8* @generate_salt(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 8, i32* %7
%9 = load i32, i32* %3
%10 = icmp sgt i32 %9, 49
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* %7
%13 = mul nsw i32 %12, 2
store i32 %13, i32* %7
br label %14
14: ; preds = %11, %1
%15 = load i32, i32* %7
%16 = add nsw i32 %15, 4
%17 = sext i32 %16 to i64
%18 = mul i64 1, %17
%19 = trunc i64 %18 to i32
%20 = call i8* @malloc(i32 %19)
store i8* %20, i8** %4
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %14
store i8* null, i8** %2
br label %58
23: ; preds = %14
%24 = load i8*, i8** %4
store i8* %24, i8** %5
%25 = load i8*, i8** %4
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 4
%28 = sext i32 %27 to i64
%29 = mul i64 1, %28
%30 = trunc i64 %29 to i32
%31 = call i32 @memset(i8* %25, i32 0, i32 %30)
%32 = load i8*, i8** %4
%33 = load i32, i32* %3
%34 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %33)
%35 = load i8*, i8** %5
%36 = getelementptr inbounds i8, i8* %35, i64 3
store i8* %36, i8** %5
%37 = call i32 @time(i32* null)
%38 = call i32 @srand(i32 %37)
store i32 0, i32* %6
br label %39
39: ; preds = %53, %23
%40 = load i32, i32* %6
%41 = load i32, i32* %7
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %56
43: ; preds = %39
%44 = call i32 (...) @rand()
%45 = srem i32 %44, 64
store i32 %45, i32* %8
%46 = load i32, i32* %8
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [65 x i8], [65 x i8]* @.str.1, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = load i8*, i8** %5
store i8 %49, i8* %50
%51 = load i8*, i8** %5
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %5
br label %53
53: ; preds = %43
%54 = load i32, i32* %6
%55 = add nsw i32 %54, 1
store i32 %55, i32* %6
br label %39
56: ; preds = %39
store i8* null, i8** %5
%57 = load i8*, i8** %4
store i8* %57, i8** %2
br label %58
58: ; preds = %56, %22
%59 = load i8*, i8** %2
ret i8* %59
}

LLVM IR (-O2):
@.str = [5 x i8] c"$%c$\00"
@.str.1 = [65 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/.\00"
define i8* @generate_salt(i32 %0) {
%2 = icmp sgt i32 %0, 49
%3 = select i1 %2, i32 16, i32 8
%4 = or i32 %3, 4
%5 = tail call i8* @malloc(i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %24, label %7
7: ; preds = %1
%8 = tail call i32 @memset(i8* %5, i32 0, i32 %4)
%9 = tail call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %0)
%10 = getelementptr inbounds i8, i8* %5, i64 3
%11 = tail call i32 @time(i32* null)
%12 = tail call i32 @srand(i32 %11)
br label %13
13: ; preds = %7, %13
%14 = phi i32 [ 0, %7 ], [ %22, %13 ]
%15 = phi i8* [ %10, %7 ], [ %21, %13 ]
%16 = tail call i32 (...) @rand()
%17 = srem i32 %16, 64
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [65 x i8], [65 x i8]* @.str.1, i64 0, i64 %18
%20 = load i8, i8* %19
store i8 %20, i8* %15
%21 = getelementptr inbounds i8, i8* %15, i64 1
%22 = add nuw nsw i32 %14, 1
%23 = icmp eq i32 %22, %3
br i1 %23, label %24, label %13
24: ; preds = %13, %1
ret i8* %5
}