#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_MAX;
int /*<<< orphan*/ printf(char *, char *);
double random();
int /*<<< orphan*/ scanf(char *, double *);
int /*<<< orphan*/ srandom(int);
void Gen_world(char prompt[], int wp[], int m, int n) {
  int i, j;
  double prob;
  printf("%s\n", prompt);
  scanf("%lf", &prob);
  srandom(1);
  for (i = 0; i < m; i++)
    for (j = 0; j < n; j++)
      if (random() / ((double)RAND_MAX) <= prob) {
        wp[i * n + j] = 1;
      } else {
        wp[i * n + j] = 0;
      }
}


x86 assembly (clang, -O0):
<Gen_world>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe9f(%rip),%rdi
call   1040 <printf@plt>
lea    0xe97(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <scanf@plt>
mov    $0x1,%edi
call   1030 <srandom@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    122a <Gen_world+0xea>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1217 <Gen_world+0xd7>
mov    $0x0,%al
call   1050 <random@plt>
movaps %xmm0,%xmm1
mov    0x2e31(%rip),%rax
cvtsi2sdq (%rax),%xmm0
divsd  %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11ec <Gen_world+0xac>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
imul   -0x18(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movl   $0x1,(%rax,%rcx,4)
jmp    1204 <Gen_world+0xc4>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
imul   -0x18(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    1209 <Gen_world+0xc9>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    119a <Gen_world+0x5a>
jmp    121c <Gen_world+0xdc>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1187 <Gen_world+0x47>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Gen_world>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,0x4(%rsp)
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rsi
lea    0xe9e(%rip),%rdi
call   1040 <printf@plt>
lea    0xe96(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1060 <scanf@plt>
mov    $0x1,%edi
call   1030 <srandom@plt>
test   %r14d,%r14d
jle    1202 <Gen_world+0xc2>
movslq 0x4(%rsp),%r12
mov    %r14d,%eax
mov    %rax,0x8(%rsp)
mov    %r12d,%ebp
shl    $0x2,%r12
mov    0x2e46(%rip),%r13
xor    %r15d,%r15d
jmp    11be <Gen_world+0x7e>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r15
add    %r12,%rbx
cmp    0x8(%rsp),%r15
je     1202 <Gen_world+0xc2>
cmpl   $0x0,0x4(%rsp)
jle    11b0 <Gen_world+0x70>
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <random@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq 0x0(%r13),%xmm1
divsd  %xmm1,%xmm0
movsd  0x10(%rsp),%xmm1
xor    %eax,%eax
ucomisd %xmm0,%xmm1
setae  %al
mov    %eax,(%rbx,%r14,4)
add    $0x1,%r14
cmp    %r14,%rbp
jne    11d0 <Gen_world+0x90>
jmp    11b0 <Gen_world+0x70>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [4 x i8] c"%lf\00"
@RAND_MAX = global i64 0
define void @Gen_world(i8* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i8*, i8** %5
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %11)
%15 = call i32 @srandom(i32 1)
store i32 0, i32* %9
br label %16
16: ; preds = %55, %4
%17 = load i32, i32* %9
%18 = load i32, i32* %7
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %58
20: ; preds = %16
store i32 0, i32* %10
br label %21
21: ; preds = %51, %20
%22 = load i32, i32* %10
%23 = load i32, i32* %8
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %54
25: ; preds = %21
%26 = call double (...) @random()
%27 = load i64, i64* @RAND_MAX
%28 = sitofp i64 %27 to double
%29 = fdiv double %26, %28
%30 = load double, double* %11
%31 = fcmp ole double %29, %30
br i1 %31, label %32, label %41
32: ; preds = %25
%33 = load i32*, i32** %6
%34 = load i32, i32* %9
%35 = load i32, i32* %8
%36 = mul nsw i32 %34, %35
%37 = load i32, i32* %10
%38 = add nsw i32 %36, %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %33, i64 %39
store i32 1, i32* %40
br label %50
41: ; preds = %25
%42 = load i32*, i32** %6
%43 = load i32, i32* %9
%44 = load i32, i32* %8
%45 = mul nsw i32 %43, %44
%46 = load i32, i32* %10
%47 = add nsw i32 %45, %46
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %42, i64 %48
store i32 0, i32* %49
br label %50
50: ; preds = %41, %32
br label %51
51: ; preds = %50
%52 = load i32, i32* %10
%53 = add nsw i32 %52, 1
store i32 %53, i32* %10
br label %21
54: ; preds = %21
br label %55
55: ; preds = %54
%56 = load i32, i32* %9
%57 = add nsw i32 %56, 1
store i32 %57, i32* %9
br label %16
58: ; preds = %16
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [4 x i8] c"%lf\00"
@RAND_MAX = global i64 0
define void @Gen_world(i8* %0, i32* nocapture writeonly %1, i32 %2, i32 %3) {
%5 = alloca double
%6 = bitcast double* %5 to i8*
%7 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %5)
%9 = call i32 @srandom(i32 1)
%10 = icmp sgt i32 %2, 0
br i1 %10, label %11, label %36
11: ; preds = %4
%12 = icmp sgt i32 %3, 0
%13 = sext i32 %3 to i64
%14 = zext i32 %2 to i64
%15 = zext i32 %3 to i64
br label %16
16: ; preds = %11, %33
%17 = phi i64 [ 0, %11 ], [ %34, %33 ]
br i1 %12, label %18, label %33
18: ; preds = %16
%19 = mul nsw i64 %17, %13
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ 0, %18 ], [ %31, %20 ]
%22 = call double (...) @random()
%23 = load i64, i64* @RAND_MAX
%24 = sitofp i64 %23 to double
%25 = fdiv double %22, %24
%26 = load double, double* %5
%27 = fcmp ole double %25, %26
%28 = add nsw i64 %21, %19
%29 = getelementptr inbounds i32, i32* %1, i64 %28
%30 = zext i1 %27 to i32
store i32 %30, i32* %29
%31 = add nuw nsw i64 %21, 1
%32 = icmp eq i64 %31, %15
br i1 %32, label %33, label %20
33: ; preds = %20, %16
%34 = add nuw nsw i64 %17, 1
%35 = icmp eq i64 %34, %14
br i1 %35, label %36, label %16
36: ; preds = %33, %4
ret void
}