#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 */
unsigned int r();
void init(unsigned int *p, int count, int mod) {
  int i;
  for (i = 0; i < count; i++) {
    unsigned int v = r();
    if (mod)
      v = (v % 31) + 1;
    p[i] = v;
  }
}


x86 assembly (clang, -O0):
<init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1177 <init+0x67>
mov    $0x0,%al
call   1030 <r@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     115b <init+0x4b>
mov    -0x18(%rbp),%eax
mov    $0x1f,%ecx
xor    %edx,%edx
div    %ecx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1129 <init+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
jle    116f <init+0x5f>
mov    %edx,%r14d
mov    %rdi,%r15
mov    %esi,%ebp
xor    %ebx,%ebx
jmp    113d <init+0x2d>
nopw   0x0(%rax,%rax,1)
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     116f <init+0x5f>
xor    %eax,%eax
call   1030 <r@plt>
test   %r14d,%r14d
je     1130 <init+0x20>
mov    %eax,%ecx
imul   $0x8421085,%rcx,%rcx
shr    $0x20,%rcx
mov    %eax,%edx
sub    %ecx,%edx
shr    %edx
add    %ecx,%edx
shr    $0x4,%edx
mov    %edx,%ecx
shl    $0x5,%ecx
sub    %ecx,%edx
add    %edx,%eax
add    $0x1,%eax
jmp    1130 <init+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @init(i32* %0, i32 %1, i32 %2) {
%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 %2, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %27, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %30
13: ; preds = %9
%14 = call i32 (...) @r()
store i32 %14, i32* %8
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i32, i32* %8
%19 = urem i32 %18, 31
%20 = add i32 %19, 1
store i32 %20, i32* %8
br label %21
21: ; preds = %17, %13
%22 = load i32, i32* %8
%23 = load i32*, i32** %4
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
store i32 %22, i32* %26
br label %27
27: ; preds = %21
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %9
30: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @init(i32* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %19
5: ; preds = %3
%6 = icmp eq i32 %2, 0
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %5, %14
%9 = phi i64 [ 0, %5 ], [ %17, %14 ]
%10 = tail call i32 (...) @r()
br i1 %6, label %14, label %11
11: ; preds = %8
%12 = urem i32 %10, 31
%13 = add nuw nsw i32 %12, 1
br label %14
14: ; preds = %11, %8
%15 = phi i32 [ %13, %11 ], [ %10, %8 ]
%16 = getelementptr inbounds i32, i32* %0, i64 %9
store i32 %15, i32* %16
%17 = add nuw nsw i64 %9, 1
%18 = icmp eq i64 %17, %7
br i1 %18, label %19, label %8
19: ; preds = %14, %3
ret void
}