#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);
int rand();
int /*<<< orphan*/ srand(scalar_t__);
scalar_t__ time(int /*<<< orphan*/);
unsigned char *rand_str(int in_len) {
  unsigned char *__r = (unsigned char *)malloc(in_len + 1);
  int i;
  if (__r == 0) {
    return 0;
  }
  srand(time(0) + rand());
  for (i = 0; i < in_len; i++) {
    __r[i] = rand() % 94 + 32;
  }
  __r[i] = 0;
  return __r;
}


x86 assembly (clang, -O0):
<rand_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1172 <rand_str+0x32>
movq   $0x0,-0x8(%rbp)
jmp    11e4 <rand_str+0xa4>
xor    %edi,%edi
call   1040 <time@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    -0x28(%rbp),%rdi
cltq
add    %rax,%rdi
call   1030 <srand@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d0 <rand_str+0x90>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x5e,%ecx
cltd
idiv   %ecx
add    $0x20,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1199 <rand_str+0x59>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_str>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %edi,%r14d
lea    0x1(%r14),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11cd <rand_str+0x8d>
mov    %rax,%r13
xor    %r12d,%r12d
xor    %edi,%edi
call   1040 <time@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1060 <rand@plt>
movslq %eax,%rdi
add    %r15,%rdi
call   1030 <srand@plt>
test   %r14d,%r14d
jle    11c5 <rand_str+0x85>
mov    %r14d,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0xffffffffae4c415d,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
shr    $0x6,%ecx
add    %edx,%ecx
imul   $0x5e,%ecx,%ecx
sub    %ecx,%eax
add    $0x20,%al
mov    %al,0x0(%r13,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1190 <rand_str+0x50>
movb   $0x0,0x0(%r13,%r12,1)
jmp    11d0 <rand_str+0x90>
xor    %r13d,%r13d
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @rand_str(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 %29, label %6
6: ; preds = %1
%7 = tail call i64 @time(i32 0)
%8 = tail call i32 (...) @rand()
%9 = sext i32 %8 to i64
%10 = add nsw i64 %7, %9
%11 = tail call i32 @srand(i64 %10)
%12 = icmp sgt i32 %0, 0
br i1 %12, label %13, label %26
13: ; preds = %6
%14 = zext i32 %0 to i64
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ 0, %13 ], [ %22, %15 ]
%17 = tail call i32 (...) @rand()
%18 = srem i32 %17, 94
%19 = trunc i32 %18 to i8
%20 = add nsw i8 %19, 32
%21 = getelementptr inbounds i8, i8* %4, i64 %16
store i8 %20, i8* %21
%22 = add nuw nsw i64 %16, 1
%23 = icmp eq i64 %22, %14
br i1 %23, label %24, label %15
24: ; preds = %15
%25 = zext i32 %0 to i64
br label %26
26: ; preds = %6, %24
%27 = phi i64 [ %25, %24 ], [ 0, %6 ]
%28 = getelementptr inbounds i8, i8* %4, i64 %27
store i8 0, i8* %28
br label %29
29: ; preds = %1, %26
%30 = phi i8* [ %4, %26 ], [ null, %1 ]
ret i8* %30
}