#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 /*<<< orphan*/ memcpy(unsigned char *, long *, long);
long random();
int getRandom(unsigned char *Buffer, int len) {
  long i = 0, reman = 0, rand = 0;
  reman = len % 4;
  for (i = 0; i < len / 4; i++) {
    rand = random();
    memcpy(Buffer + i * 4, &rand, 4);
  }
  if (reman > 0) {
    rand = random();
    memcpy(Buffer + i * 4, &rand, reman);
  }
  return 0;
}


x86 assembly (clang, -O0):
<getRandom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
cmp    %rcx,%rax
jge    11bf <getRandom+0x9f>
mov    $0x0,%al
call   1040 <random@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1161 <getRandom+0x41>
cmpq   $0x0,-0x20(%rbp)
jle    11f1 <getRandom+0xd1>
mov    $0x0,%al
call   1040 <random@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rsi
call   1030 <memcpy@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getRandom>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0x3(%rsi),%eax
test   %esi,%esi
cmovns %esi,%eax
movq   $0x0,(%rsp)
mov    %eax,%ecx
and    $0xfffffffc,%ecx
mov    %esi,%r13d
sub    %ecx,%r13d
cmp    $0x4,%esi
jl     1190 <getRandom+0x70>
sar    $0x2,%eax
movslq %eax,%r12
mov    %rsp,%r15
mov    %r14,%rbx
mov    %r12,%rbp
nopl   (%rax)
xor    %eax,%eax
call   1040 <random@plt>
mov    %rax,(%rsp)
mov    $0x4,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <memcpy@plt>
add    $0x4,%rbx
add    $0xffffffffffffffff,%rbp
jne    1160 <getRandom+0x40>
shl    $0x2,%r12
test   %r13d,%r13d
jg     1198 <getRandom+0x78>
jmp    11b7 <getRandom+0x97>
xor    %r12d,%r12d
test   %r13d,%r13d
jle    11b7 <getRandom+0x97>
movslq %r13d,%rbx
xor    %eax,%eax
call   1040 <random@plt>
mov    %rax,(%rsp)
add    %r12,%r14
mov    %rsp,%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1030 <memcpy@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @getRandom(i8* %0, i32 %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%5 = srem i32 %1, 4
%6 = sext i32 %5 to i64
%7 = sdiv i32 %1, 4
%8 = sext i32 %7 to i64
%9 = icmp sgt i32 %1, 3
br i1 %9, label %10, label %20
10: ; preds = %2, %10
%11 = phi i64 [ %16, %10 ], [ 0, %2 ]
%12 = call i64 (...) @random()
store i64 %12, i64* %3
%13 = shl nsw i64 %11, 2
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = call i32 @memcpy(i8* %14, i64* %3, i64 4)
%16 = add nuw nsw i64 %11, 1
%17 = icmp eq i64 %16, %8
br i1 %17, label %18, label %10
18: ; preds = %10
%19 = shl nsw i64 %8, 2
br label %20
20: ; preds = %18, %2
%21 = phi i64 [ 0, %2 ], [ %19, %18 ]
%22 = icmp sgt i32 %5, 0
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = call i64 (...) @random()
store i64 %24, i64* %3
%25 = getelementptr inbounds i8, i8* %0, i64 %21
%26 = call i32 @memcpy(i8* %25, i64* %3, i64 %6)
br label %27
27: ; preds = %23, %20
ret i32 0
}