#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 uint32_t;
typedef int int32_t;

/* Variables and functions */
int bcm2835_read(int);
int32_t bcm2835_rng_read(uint32_t *value) {
  uint32_t count;
  uint32_t timeout = 0;
  while (1) {
    count = bcm2835_read(((0 + 0x104000) + 0x4)) >> 24;
    if (count != 0)
      break;
    timeout++;
    if (timeout > 100)
      return -1;
  }
  *value = bcm2835_read(((0 + 0x104000) + 0x8));
  return 4;
}


x86 assembly (clang, -O0):
<bcm2835_rng_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x104004,%edi
call   1030 <bcm2835_read@plt>
sar    $0x18,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1142 <bcm2835_rng_read+0x32>
jmp    1166 <bcm2835_rng_read+0x56>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x64,-0x18(%rbp)
jle    1161 <bcm2835_rng_read+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    117f <bcm2835_rng_read+0x6f>
jmp    1123 <bcm2835_rng_read+0x13>
mov    $0x104008,%edi
call   1030 <bcm2835_read@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x4,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bcm2835_rng_read>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x65,%ebp
nopl   0x0(%rax,%rax,1)
mov    $0x104004,%edi
call   1030 <bcm2835_read@plt>
cmp    $0xffffff,%eax
ja     113d <bcm2835_rng_read+0x2d>
add    $0xffffffff,%ebp
jne    1120 <bcm2835_rng_read+0x10>
mov    $0xffffffff,%eax
jmp    114e <bcm2835_rng_read+0x3e>
mov    $0x104008,%edi
call   1030 <bcm2835_read@plt>
mov    %eax,(%rbx)
mov    $0x4,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bcm2835_rng_read(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 0, i32* %5
br label %6
6: ; preds = %1, %18
%7 = call i32 @bcm2835_read(i32 1064964)
%8 = ashr i32 %7, 24
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %6
br label %19
12: ; preds = %6
%13 = load i32, i32* %5
%14 = add nsw i32 %13, 1
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = icmp sgt i32 %15, 100
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 -1, i32* %2
br label %22
18: ; preds = %12
br label %6
19: ; preds = %11
%20 = call i32 @bcm2835_read(i32 1064968)
%21 = load i32*, i32** %3
store i32 %20, i32* %21
store i32 4, i32* %2
br label %22
22: ; preds = %19, %17
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
define i32 @bcm2835_rng_read(i32* nocapture writeonly %0) {
br label %2
2: ; preds = %6, %1
%3 = phi i32 [ 0, %1 ], [ %7, %6 ]
%4 = tail call i32 @bcm2835_read(i32 1064964)
%5 = icmp ult i32 %4, 16777216
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = add nuw nsw i32 %3, 1
%8 = icmp eq i32 %7, 101
br i1 %8, label %11, label %2
9: ; preds = %2
%10 = tail call i32 @bcm2835_read(i32 1064968)
store i32 %10, i32* %0
br label %11
11: ; preds = %6, %9
%12 = phi i32 [ 4, %9 ], [ -1, %6 ]
ret i32 %12
}