#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 */
int rand();
void init_array(uintptr_t *const a, const size_t n) {
  for (size_t i = 0; i < n; ++i) {
    do {
      a[i] = rand() * 2;
    } while (a[i] == 0);
  }
}


x86 assembly (clang, -O0):
<init_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    117d <init_array+0x6d>
jmp    113b <init_array+0x2b>
mov    $0x0,%al
call   1030 <rand@plt>
shl    $0x1,%eax
movslq %eax,%rdx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     113b <init_array+0x2b>
jmp    116c <init_array+0x5c>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1128 <init_array+0x18>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_array>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     114e <init_array+0x3e>
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <rand@plt>
lea    (%rax,%rax,1),%ecx
movslq %ecx,%rcx
mov    %rcx,(%r15,%rbx,8)
test   %eax,%eax
je     1130 <init_array+0x20>
add    $0x1,%rbx
cmp    %r14,%rbx
jne    1130 <init_array+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @init_array(i64* %0, i64 %1) {
%3 = alloca i64*
%4 = alloca i64
%5 = alloca i64
store i64* %0, i64** %3
store i64 %1, i64* %4
store i64 0, i64* %5
br label %6
6: ; preds = %25, %2
%7 = load i64, i64* %5
%8 = load i64, i64* %4
%9 = icmp ult i64 %7, %8
br i1 %9, label %10, label %28
10: ; preds = %6
br label %11
11: ; preds = %18, %10
%12 = call i32 (...) @rand()
%13 = mul nsw i32 %12, 2
%14 = sext i32 %13 to i64
%15 = load i64*, i64** %3
%16 = load i64, i64* %5
%17 = getelementptr inbounds i64, i64* %15, i64 %16
store i64 %14, i64* %17
br label %18
18: ; preds = %11
%19 = load i64*, i64** %3
%20 = load i64, i64* %5
%21 = getelementptr inbounds i64, i64* %19, i64 %20
%22 = load i64, i64* %21
%23 = icmp eq i64 %22, 0
br i1 %23, label %11, label %24
24: ; preds = %18
br label %25
25: ; preds = %24
%26 = load i64, i64* %5
%27 = add i64 %26, 1
store i64 %27, i64* %5
br label %6
28: ; preds = %6
ret void
}

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