#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*/ uint64_t;

/* Variables and functions */
int rdrand_64(int /*<<< orphan*/ *, int);
int rdrand_get_n_64(unsigned int n, uint64_t *dest) {
  int success;
  int count;
  unsigned int i;
  for (i = 0; i < n; i++) {
    count = 0;
    do {
      success = rdrand_64(dest, 1);
    } while ((success == 0) && (count++ < 10));
    if (success != 1)
      return success;
    dest = &(dest[1]);
  }
  return 1;
}


x86 assembly (clang, -O0):
<rdrand_get_n_64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    11a7 <rdrand_get_n_64+0x97>
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1030 <rdrand_64@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x1d(%rbp)
jne    116d <rdrand_get_n_64+0x5d>
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0xa,%eax
setl   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1139 <rdrand_get_n_64+0x29>
cmpl   $0x1,-0x14(%rbp)
je     118d <rdrand_get_n_64+0x7d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ae <rdrand_get_n_64+0x9e>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1126 <rdrand_get_n_64+0x16>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rdrand_get_n_64>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
je     116d <rdrand_get_n_64+0x5d>
mov    %rsi,%rbx
mov    %edi,%r14d
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <rdrand_64@plt>
test   %eax,%eax
jne    115b <rdrand_get_n_64+0x4b>
lea    0x1(%rbp),%ecx
cmp    $0xa,%ebp
mov    %ecx,%ebp
jb     1140 <rdrand_get_n_64+0x30>
cmp    $0x1,%eax
jne    1172 <rdrand_get_n_64+0x62>
add    $0x4,%rbx
add    $0x1,%r15d
cmp    %r14d,%r15d
jne    1130 <rdrand_get_n_64+0x20>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @rdrand_get_n_64(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 0, i32* %8
br label %9
9: ; preds = %34, %2
%10 = load i32, i32* %8
%11 = load i32, i32* %4
%12 = icmp ult i32 %10, %11
br i1 %12, label %13, label %37
13: ; preds = %9
store i32 0, i32* %7
br label %14
14: ; preds = %24, %13
%15 = load i32*, i32** %5
%16 = call i32 @rdrand_64(i32* %15, i32 1)
store i32 %16, i32* %6
br label %17
17: ; preds = %14
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* %7
%22 = add nsw i32 %21, 1
store i32 %22, i32* %7
%23 = icmp slt i32 %21, 10
br label %24
24: ; preds = %20, %17
%25 = phi i1 [ false, %17 ], [ %23, %20 ]
br i1 %25, label %14, label %26
26: ; preds = %24
%27 = load i32, i32* %6
%28 = icmp ne i32 %27, 1
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = load i32, i32* %6
store i32 %30, i32* %3
br label %38
31: ; preds = %26
%32 = load i32*, i32** %5
%33 = getelementptr inbounds i32, i32* %32, i64 1
store i32* %33, i32** %5
br label %34
34: ; preds = %31
%35 = load i32, i32* %8
%36 = add i32 %35, 1
store i32 %36, i32* %8
br label %9
37: ; preds = %9
store i32 1, i32* %3
br label %38
38: ; preds = %37, %29
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
define i32 @rdrand_get_n_64(i32 %0, i32* %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %20, label %4
4: ; preds = %2, %16
%5 = phi i32 [ %18, %16 ], [ 0, %2 ]
%6 = phi i32* [ %17, %16 ], [ %1, %2 ]
br label %7
7: ; preds = %4, %7
%8 = phi i32 [ %11, %7 ], [ 0, %4 ]
%9 = tail call i32 @rdrand_64(i32* %6, i32 1)
%10 = icmp eq i32 %9, 0
%11 = add nuw nsw i32 %8, 1
%12 = icmp ult i32 %8, 10
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %7, label %14
14: ; preds = %7
%15 = icmp eq i32 %9, 1
br i1 %15, label %16, label %20
16: ; preds = %14
%17 = getelementptr inbounds i32, i32* %6, i64 1
%18 = add nuw i32 %5, 1
%19 = icmp eq i32 %18, %0
br i1 %19, label %20, label %4
20: ; preds = %14, %16, %2
%21 = phi i32 [ 1, %2 ], [ 1, %16 ], [ %9, %14 ]
ret i32 %21
}