#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 */
void *qrand();
void seed_qrand_r(unsigned *seeds, unsigned num) {
  unsigned i;
  for (i = 0; i < num; i++) {
    int random_value = 0;
    while (!random_value)
      random_value = qrand();
    int j = 0;
    while (j++ != random_value)
      qrand();
    seeds[i] = qrand();
  }
}


x86 assembly (clang, -O0):
<seed_qrand_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11a6 <seed_qrand_r+0x96>
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    114f <seed_qrand_r+0x3f>
jmp    115e <seed_qrand_r+0x4e>
mov    $0x0,%al
call   1030 <qrand@plt>
mov    %eax,-0x14(%rbp)
jmp    1139 <seed_qrand_r+0x29>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
cmp    -0x14(%rbp),%eax
je     1185 <seed_qrand_r+0x75>
mov    $0x0,%al
call   1030 <qrand@plt>
jmp    1165 <seed_qrand_r+0x55>
mov    $0x0,%al
call   1030 <qrand@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <seed_qrand_r+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seed_qrand_r>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     1160 <seed_qrand_r+0x50>
mov    %rdi,%r14
mov    %esi,%r15d
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1030 <qrand@plt>
mov    %rax,%rbx
test   %ebx,%ebx
je     1130 <seed_qrand_r+0x20>
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <qrand@plt>
add    $0xffffffff,%ebx
jne    1140 <seed_qrand_r+0x30>
xor    %eax,%eax
call   1030 <qrand@plt>
mov    %eax,(%r14,%r12,4)
add    $0x1,%r12
cmp    %r15,%r12
jne    1130 <seed_qrand_r+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @seed_qrand_r(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 0, i32* %5
br label %8
8: ; preds = %35, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp ult i32 %9, %10
br i1 %11, label %12, label %38
12: ; preds = %8
store i32 0, i32* %6
br label %13
13: ; preds = %17, %12
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = call i8* (...) @qrand()
%19 = ptrtoint i8* %18 to i32
store i32 %19, i32* %6
br label %13
20: ; preds = %13
store i32 0, i32* %7
br label %21
21: ; preds = %26, %20
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
%24 = load i32, i32* %6
%25 = icmp ne i32 %22, %24
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i8* (...) @qrand()
br label %21
28: ; preds = %21
%29 = call i8* (...) @qrand()
%30 = ptrtoint i8* %29 to i32
%31 = load i32*, i32** %3
%32 = load i32, i32* %5
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
store i32 %30, i32* %34
br label %35
35: ; preds = %28
%36 = load i32, i32* %5
%37 = add i32 %36, 1
store i32 %37, i32* %5
br label %8
38: ; preds = %8
ret void
}

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