#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__ malloc(int);
scalar_t__ rand();
char *gen_salt_alloc(int count) {
  char *salt = (char *)malloc(count + 1);
  if (salt) {
    int n;
    for (n = 0; n < count; n++)
      salt[n] = (((int)rand()) % 255) + 1;
    salt[n] = 0;
  }
  return salt;
}


x86 assembly (clang, -O0):
<gen_salt_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118f <gen_salt_alloc+0x6f>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1183 <gen_salt_alloc+0x63>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0xff,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
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    114c <gen_salt_alloc+0x2c>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_salt_alloc>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%r14d
lea    0x1(%r14),%edi
call   1030 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     118c <gen_salt_alloc+0x6c>
test   %r14d,%r14d
jle    1184 <gen_salt_alloc+0x64>
mov    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
shr    $0x7,%ecx
add    %edx,%ecx
add    %eax,%ecx
add    $0x1,%cl
mov    %cl,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <gen_salt_alloc+0x30>
jmp    1187 <gen_salt_alloc+0x67>
xor    %r14d,%r14d
movb   $0x0,(%r15,%r14,1)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @gen_salt_alloc(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = add nsw i32 %5, 1
%7 = call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %34
11: ; preds = %1
store i32 0, i32* %4
br label %12
12: ; preds = %26, %11
%13 = load i32, i32* %4
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %29
16: ; preds = %12
%17 = call i64 (...) @rand()
%18 = trunc i64 %17 to i32
%19 = srem i32 %18, 255
%20 = add nsw i32 %19, 1
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %3
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 %21, i8* %25
br label %26
26: ; preds = %16
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %12
29: ; preds = %12
%30 = load i8*, i8** %3
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 0, i8* %33
br label %34
34: ; preds = %29, %1
%35 = load i8*, i8** %3
ret i8* %35
}

LLVM IR (-O2):
define i8* @gen_salt_alloc(i32 %0) {
%2 = add nsw i32 %0, 1
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %25, label %6
6: ; preds = %1
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %22
8: ; preds = %6
%9 = zext i32 %0 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %18, %10 ]
%12 = tail call i64 (...) @rand()
%13 = trunc i64 %12 to i32
%14 = srem i32 %13, 255
%15 = trunc i32 %14 to i8
%16 = add i8 %15, 1
%17 = getelementptr inbounds i8, i8* %4, i64 %11
store i8 %16, i8* %17
%18 = add nuw nsw i64 %11, 1
%19 = icmp eq i64 %18, %9
br i1 %19, label %20, label %10
20: ; preds = %10
%21 = zext i32 %0 to i64
br label %22
22: ; preds = %6, %20
%23 = phi i64 [ %21, %20 ], [ 0, %6 ]
%24 = getelementptr inbounds i8, i8* %4, i64 %23
store i8 0, i8* %24
br label %25
25: ; preds = %22, %1
ret i8* %4
}