#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 */
int random();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
char *random_buffer(char buf[], size_t size) {
  char *ptr = buf;
  int i = 0;
  if (buf == NULL)
    return ptr;
  srand(0);
  for (i = 0; i < size; i++) {
    buf[i] = 0x65 + random() % 10;
  }
  return ptr;
}


x86 assembly (clang, -O0):
<random_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1157 <random_buffer+0x37>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a6 <random_buffer+0x86>
xor    %edi,%edi
call   1030 <srand@plt>
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    119e <random_buffer+0x7e>
mov    $0x0,%al
call   1040 <random@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x65,%edx
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1165 <random_buffer+0x45>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_buffer>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
test   %rdi,%rdi
je     1173 <random_buffer+0x53>
mov    %rsi,%r14
xor    %edi,%edi
call   1030 <srand@plt>
test   %r14,%r14
je     1173 <random_buffer+0x53>
xor    %ebx,%ebx
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <random@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
add    $0x65,%al
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1140 <random_buffer+0x20>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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