#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 *, int *, int);
int rand();
int my_better_rand_bytes(unsigned char *buf, int num_bytes) {
  for (int i = 0; i < num_bytes; i += 4) {
    int rand_int = rand();
    memcpy(buf + i, &rand_int,
           (((num_bytes - i) < (4)) ? (num_bytes - i) : (4)));
  }
  return 1;
}


x86 assembly (clang, -O0):
<my_better_rand_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a3 <my_better_rand_bytes+0x83>
mov    $0x0,%al
call   1040 <rand@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
cmp    $0x4,%eax
jge    1178 <my_better_rand_bytes+0x58>
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1185 <my_better_rand_bytes+0x65>
mov    $0x4,%eax
mov    %eax,-0x24(%rbp)
jmp    1185 <my_better_rand_bytes+0x65>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    -0x14(%rbp),%rsi
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <my_better_rand_bytes+0x16>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_better_rand_bytes>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    116e <my_better_rand_bytes+0x4e>
mov    %esi,%r12d
mov    %rdi,%r14
lea    0xc(%rsp),%r15
mov    %esi,%ebp
xor    %ebx,%ebx
nop
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,0xc(%rsp)
lea    (%r14,%rbx,1),%rdi
cmp    $0x4,%ebp
mov    $0x4,%edx
cmovl  %ebp,%edx
mov    %r15,%rsi
call   1030 <memcpy@plt>
add    $0x4,%rbx
add    $0xfffffffc,%ebp
cmp    %r12d,%ebx
jl     1140 <my_better_rand_bytes+0x20>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @my_better_rand_bytes(i8* %0, i32 %1) {
%3 = alloca i32
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = bitcast i32* %3 to i8*
br label %8
7: ; preds = %8, %2
ret i32 1
8: ; preds = %5, %8
%9 = phi i64 [ 0, %5 ], [ %17, %8 ]
%10 = call i32 (...) @rand()
store i32 %10, i32* %3
%11 = getelementptr inbounds i8, i8* %0, i64 %9
%12 = trunc i64 %9 to i32
%13 = sub nsw i32 %1, %12
%14 = icmp slt i32 %13, 4
%15 = select i1 %14, i32 %13, i32 4
%16 = call i32 @memcpy(i8* %11, i32* %3, i32 %15)
%17 = add nuw i64 %9, 4
%18 = trunc i64 %17 to i32
%19 = icmp slt i32 %18, %1
br i1 %19, label %8, label %7
}