#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 */
scalar_t__ calloc(unsigned int, int);
int rand();
int /*<<< orphan*/ srand(int);
char *saltgen(unsigned int length) {
  char *psalt = (char *)calloc(length, sizeof(char));
  srand(rand());
  int i = 0;
  for (; i < length; i++) {
    psalt[i] = rand() % 256;
  }
  return psalt;
}


x86 assembly (clang, -O0):
<saltgen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    1195 <saltgen+0x65>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1161 <saltgen+0x31>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<saltgen>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1050 <rand@plt>
mov    %eax,%edi
call   1030 <srand@plt>
test   %ebp,%ebp
je     1174 <saltgen+0x44>
mov    %ebp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <rand@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <saltgen+0x30>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @saltgen(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i64 @calloc(i32 %5, i32 1)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %3
%8 = call i32 (...) @rand()
%9 = call i32 @srand(i32 %8)
store i32 0, i32* %4
br label %10
10: ; preds = %22, %1
%11 = load i32, i32* %4
%12 = load i32, i32* %2
%13 = icmp ult i32 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = call i32 (...) @rand()
%16 = srem i32 %15, 256
%17 = trunc i32 %16 to i8
%18 = load i8*, i8** %3
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
store i8 %17, i8* %21
br label %22
22: ; preds = %14
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %10
25: ; preds = %10
%26 = load i8*, i8** %3
ret i8* %26
}

LLVM IR (-O2):
define i8* @saltgen(i32 %0) {
%2 = tail call i64 @calloc(i32 %0, i32 1)
%3 = inttoptr i64 %2 to i8*
%4 = tail call i32 (...) @rand()
%5 = tail call i32 @srand(i32 %4)
%6 = icmp eq i32 %0, 0
br i1 %6, label %16, label %7
7: ; preds = %1
%8 = zext i32 %0 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %14, %9 ]
%11 = tail call i32 (...) @rand()
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds i8, i8* %3, i64 %10
store i8 %12, i8* %13
%14 = add nuw nsw i64 %10, 1
%15 = icmp eq i64 %14, %8
br i1 %15, label %16, label %9
16: ; preds = %9, %1
ret i8* %3
}