#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;
double rand();
void init(int m[40][40]) {
  int i, j;
  for (i = 0; i < 40; i++) {
    for (j = 0; j < 40; j++)
      m[i][j] = (rand() / ((double)RAND_MAX + 1)) > 0.5 ? 1 : -1;
  }
}


x86 assembly (clang, -O0):
<init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x28,-0xc(%rbp)
jge    11b4 <init+0xa4>
movl   $0x0,-0x10(%rbp)
cmpl   $0x28,-0x10(%rbp)
jge    11a1 <init+0x91>
mov    $0x0,%al
call   1030 <rand@plt>
mov    0x2e9c(%rip),%rax
cvtsi2sdq (%rax),%xmm1
movsd  0xeaf(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  0xe97(%rip),%xmm1
mov    $0xffffffff,%edx
mov    $0x1,%eax
ucomisd %xmm1,%xmm0
cmova  %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
imul   $0xa0,%rcx,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1134 <init+0x24>
jmp    11a6 <init+0x96>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <init+0x13>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
mov    0x2ec6(%rip),%r14
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <rand@plt>
movsd  0xeb1(%rip),%xmm2
xorps  %xmm1,%xmm1
cvtsi2sdq (%r14),%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
xor    %eax,%eax
ucomisd 0xe9f(%rip),%xmm0
seta   %al
add    %eax,%eax
add    $0xffffffff,%eax
mov    %eax,(%r12,%rbx,4)
add    $0x1,%rbx
cmp    $0x28,%rbx
jne    1140 <init+0x30>
add    $0x1,%r15
add    $0xa0,%r12
cmp    $0x28,%r15
jne    1130 <init+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
define void @init([40 x i32]* %0) {
%2 = alloca [40 x i32]*
%3 = alloca i32
%4 = alloca i32
store [40 x i32]* %0, [40 x i32]** %2
store i32 0, i32* %3
br label %5
5: ; preds = %32, %1
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 40
br i1 %7, label %8, label %35
8: ; preds = %5
store i32 0, i32* %4
br label %9
9: ; preds = %28, %8
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 40
br i1 %11, label %12, label %31
12: ; preds = %9
%13 = call double (...) @rand()
%14 = load i64, i64* @RAND_MAX
%15 = sitofp i64 %14 to double
%16 = fadd double %15, 1.000000e+00
%17 = fdiv double %13, %16
%18 = fcmp ogt double %17, 5.000000e-01
%19 = zext i1 %18 to i64
%20 = select i1 %18, i32 1, i32 -1
%21 = load [40 x i32]*, [40 x i32]** %2
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [40 x i32], [40 x i32]* %21, i64 %23
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [40 x i32], [40 x i32]* %24, i64 0, i64 %26
store i32 %20, i32* %27
br label %28
28: ; preds = %12
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %9
31: ; preds = %9
br label %32
32: ; preds = %31
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
store i32 %34, i32* %3
br label %5
35: ; preds = %5
ret void
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
define void @init([40 x i32]* nocapture writeonly %0) {
br label %2
2: ; preds = %1, %16
%3 = phi i64 [ 0, %1 ], [ %17, %16 ]
br label %4
4: ; preds = %2, %4
%5 = phi i64 [ 0, %2 ], [ %14, %4 ]
%6 = tail call double (...) @rand()
%7 = load i64, i64* @RAND_MAX
%8 = sitofp i64 %7 to double
%9 = fadd double %8, 1.000000e+00
%10 = fdiv double %6, %9
%11 = fcmp ogt double %10, 5.000000e-01
%12 = select i1 %11, i32 1, i32 -1
%13 = getelementptr inbounds [40 x i32], [40 x i32]* %0, i64 %3, i64 %5
store i32 %12, i32* %13
%14 = add nuw nsw i64 %5, 1
%15 = icmp eq i64 %14, 40
br i1 %15, label %16, label %4
16: ; preds = %4
%17 = add nuw nsw i64 %3, 1
%18 = icmp eq i64 %17, 40
br i1 %18, label %19, label %2
19: ; preds = %16
ret void
}