#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 */
scalar_t__ rand_pcg();
int /*<<< orphan*/ srand_pcg(unsigned int);
void populate_lattice(double probability, int *lattice, int rows, int columns,
                      unsigned int seed) {
  int i;
  double q;
  if (seed > 0) {
    srand_pcg(seed);
  }
  for (i = 0; i < rows * columns; i++) {
    q = ((double)rand_pcg()) / 4294967295;
    if (q <= probability) {
      lattice[i] = 1;
    } else {
      lattice[i] = 0;
    }
  }
  return;
}


x86 assembly (clang, -O0):
<populate_lattice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jbe    114c <populate_lattice+0x2c>
mov    -0x1c(%rbp),%edi
call   1030 <srand_pcg@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x14(%rbp),%ecx
imul   -0x18(%rbp),%ecx
cmp    %ecx,%eax
jge    11cc <populate_lattice+0xac>
mov    $0x0,%al
call   1040 <rand_pcg@plt>
cvtsi2sd %rax,%xmm0
movsd  0xe87(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11aa <populate_lattice+0x8a>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
jmp    11b9 <populate_lattice+0x99>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    11be <populate_lattice+0x9e>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1153 <populate_lattice+0x33>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<populate_lattice>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%r15
test   %ecx,%ecx
movsd  %xmm0,(%rsp)
je     113f <populate_lattice+0x1f>
mov    %ecx,%edi
call   1030 <srand_pcg@plt>
imul   %r14d,%ebp
test   %ebp,%ebp
jle    1182 <populate_lattice+0x62>
mov    %ebp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand_pcg@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  0xe99(%rip),%xmm0
xor    %eax,%eax
movsd  (%rsp),%xmm1
ucomisd %xmm0,%xmm1
setae  %al
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <populate_lattice+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @populate_lattice(double %0, i32* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca double
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca double
store double %0, double* %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%13 = load i32, i32* %10
%14 = icmp ugt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %5
%16 = load i32, i32* %10
%17 = call i32 @srand_pcg(i32 %16)
br label %18
18: ; preds = %15, %5
store i32 0, i32* %11
br label %19
19: ; preds = %43, %18
%20 = load i32, i32* %11
%21 = load i32, i32* %8
%22 = load i32, i32* %9
%23 = mul nsw i32 %21, %22
%24 = icmp slt i32 %20, %23
br i1 %24, label %25, label %46
25: ; preds = %19
%26 = call i64 (...) @rand_pcg()
%27 = sitofp i64 %26 to double
%28 = fdiv double %27, 0x41EFFFFFFFE00000
store double %28, double* %12
%29 = load double, double* %12
%30 = load double, double* %6
%31 = fcmp ole double %29, %30
br i1 %31, label %32, label %37
32: ; preds = %25
%33 = load i32*, i32** %7
%34 = load i32, i32* %11
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
store i32 1, i32* %36
br label %42
37: ; preds = %25
%38 = load i32*, i32** %7
%39 = load i32, i32* %11
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
store i32 0, i32* %41
br label %42
42: ; preds = %37, %32
br label %43
43: ; preds = %42
%44 = load i32, i32* %11
%45 = add nsw i32 %44, 1
store i32 %45, i32* %11
br label %19
46: ; preds = %19
ret void
}

LLVM IR (-O2):
define void @populate_lattice(double %0, i32* nocapture writeonly %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp eq i32 %4, 0
br i1 %6, label %9, label %7
7: ; preds = %5
%8 = tail call i32 @srand_pcg(i32 %4)
br label %9
9: ; preds = %7, %5
%10 = mul i32 %3, %2
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %9
%13 = zext i32 %10 to i64
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ 0, %12 ], [ %22, %14 ]
%16 = tail call i64 (...) @rand_pcg()
%17 = sitofp i64 %16 to double
%18 = fdiv double %17, 0x41EFFFFFFFE00000
%19 = fcmp ole double %18, %0
%20 = zext i1 %19 to i32
%21 = getelementptr inbounds i32, i32* %1, i64 %15
store i32 %20, i32* %21
%22 = add nuw nsw i64 %15, 1
%23 = icmp eq i64 %22, %13
br i1 %23, label %24, label %14
24: ; preds = %14, %9
ret void
}