#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 *calloc(size_t, size_t);
int /*<<< orphan*/ memset(char *, char, size_t);
int random();
char *random_buf(size_t len, size_t typesiz) {
  char *buf = calloc(len + 1, typesiz);
  memset(buf, (random() % 255 - 32) + 32, len * typesiz);
  memset(buf + (len * typesiz), '\0', typesiz);
  return buf;
}


x86 assembly (clang, -O0):
<random_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <random@plt>
mov    -0x20(%rbp),%rdi
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
sub    $0x20,%eax
add    $0x20,%eax
mov    -0x8(%rbp),%rdx
imul   -0x10(%rbp),%rdx
movsbl %al,%esi
call   1030 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
imul   -0x10(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_buf>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
add    $0x1,%rdi
call   1040 <calloc@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1050 <random@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
imul   %r14,%rbx
movsbl %cl,%esi
mov    %r15,%rdi
mov    %rbx,%rdx
call   1030 <memset@plt>
add    %r15,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1030 <memset@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @random_buf(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
store i64 %0, i64* %3
store i64 %1, i64* %4
%6 = load i64, i64* %3
%7 = add i64 %6, 1
%8 = load i64, i64* %4
%9 = call i8* @calloc(i64 %7, i64 %8)
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = call i32 (...) @random()
%12 = srem i32 %11, 255
%13 = sub nsw i32 %12, 32
%14 = add nsw i32 %13, 32
%15 = trunc i32 %14 to i8
%16 = load i64, i64* %3
%17 = load i64, i64* %4
%18 = mul i64 %16, %17
%19 = call i32 @memset(i8* %10, i8 signext %15, i64 %18)
%20 = load i8*, i8** %5
%21 = load i64, i64* %3
%22 = load i64, i64* %4
%23 = mul i64 %21, %22
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = load i64, i64* %4
%26 = call i32 @memset(i8* %24, i8 signext 0, i64 %25)
%27 = load i8*, i8** %5
ret i8* %27
}

LLVM IR (-O2):
define i8* @random_buf(i64 %0, i64 %1) {
%3 = add i64 %0, 1
%4 = tail call i8* @calloc(i64 %3, i64 %1)
%5 = tail call i32 (...) @random()
%6 = srem i32 %5, 255
%7 = trunc i32 %6 to i8
%8 = mul i64 %1, %0
%9 = tail call i32 @memset(i8* %4, i8 signext %7, i64 %8)
%10 = getelementptr inbounds i8, i8* %4, i64 %8
%11 = tail call i32 @memset(i8* %10, i8 signext 0, i64 %1)
ret i8* %4
}