#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ uint64_t;
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ random_uint32();
void randombytes(uint8_t *target, uint64_t n) {
  uint32_t random;
  uint8_t *random_pos = (uint8_t *)&random;
  unsigned _n = 0;
  while (n--) {
    if (!(_n++ & 0x3)) {
      random = random_uint32();
      random_pos = (uint8_t *)&random;
    }
    *target++ = *random_pos++;
  }
}


x86 assembly (clang, -O0):
<randombytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     1192 <randombytes+0x82>
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
and    $0x3,%eax
cmp    $0x0,%eax
jne    116b <randombytes+0x5b>
mov    $0x0,%al
call   1030 <random_uint32@plt>
mov    %eax,-0x10(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x8(%rbp)
mov    %ecx,(%rax)
jmp    112e <randombytes+0x1e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randombytes>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     1158 <randombytes+0x48>
mov    %rdi,%r14
mov    %esi,%r12d
lea    0x4(%rsp),%r15
xor    %ebx,%ebx
mov    %r15,%rcx
jmp    114f <randombytes+0x3f>
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <random_uint32@plt>
mov    %eax,0x4(%rsp)
mov    %r15,%rcx
add    $0x4,%rcx
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    %ebx,%r12d
je     1158 <randombytes+0x48>
test   $0x3,%bl
je     1130 <randombytes+0x20>
mov    (%rcx),%eax
jmp    113e <randombytes+0x2e>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @randombytes(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32* %5, i32** %6
store i32 0, i32* %7
br label %8
8: ; preds = %19, %2
%9 = load i32, i32* %4
%10 = add nsw i32 %9, -1
store i32 %10, i32* %4
%11 = icmp ne i32 %9, 0
br i1 %11, label %12, label %25
12: ; preds = %8
%13 = load i32, i32* %7
%14 = add i32 %13, 1
store i32 %14, i32* %7
%15 = and i32 %13, 3
%16 = icmp ne i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = call i32 (...) @random_uint32()
store i32 %18, i32* %5
store i32* %5, i32** %6
br label %19
19: ; preds = %17, %12
%20 = load i32*, i32** %6
%21 = getelementptr inbounds i32, i32* %20, i32 1
store i32* %21, i32** %6
%22 = load i32, i32* %20
%23 = load i32*, i32** %3
%24 = getelementptr inbounds i32, i32* %23, i32 1
store i32* %24, i32** %3
store i32 %22, i32* %23
br label %8
25: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @randombytes(i32* nocapture writeonly %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %1, 0
br i1 %5, label %25, label %6
6: ; preds = %2, %19
%7 = phi i32 [ %11, %19 ], [ %1, %2 ]
%8 = phi i32 [ %12, %19 ], [ 0, %2 ]
%9 = phi i32* [ %22, %19 ], [ %3, %2 ]
%10 = phi i32* [ %23, %19 ], [ %0, %2 ]
%11 = add nsw i32 %7, -1
%12 = add nuw i32 %8, 1
%13 = and i32 %8, 3
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %6
%16 = load i32, i32* %9
br label %19
17: ; preds = %6
%18 = tail call i32 (...) @random_uint32()
store i32 %18, i32* %3
br label %19
19: ; preds = %15, %17
%20 = phi i32 [ %16, %15 ], [ %18, %17 ]
%21 = phi i32* [ %9, %15 ], [ %3, %17 ]
%22 = getelementptr inbounds i32, i32* %21, i64 1
%23 = getelementptr inbounds i32, i32* %10, i64 1
store i32 %20, i32* %10
%24 = icmp eq i32 %11, 0
br i1 %24, label %25, label %6
25: ; preds = %19, %2
ret void
}