#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 */
double random_double();
double **safeMatrixAlloc(int, int);
double **randomHypercycleAlloc(int n) {
  int i;
  double **a = safeMatrixAlloc(n, n);
  for (i = 0; i < n; i++) {
    a[i][(i + 1) % n] = random_double();
  }
  return a;
}


x86 assembly (clang, -O0):
<randomHypercycleAlloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1030 <safeMatrixAlloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1188 <randomHypercycleAlloc+0x68>
mov    $0x0,%al
call   1040 <random_double@plt>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltd
idivl  -0x4(%rbp)
mov    -0x18(%rbp),%rax
movslq %edx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1141 <randomHypercycleAlloc+0x21>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomHypercycleAlloc>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
mov    %edi,%esi
call   1030 <safeMatrixAlloc@plt>
mov    %rax,%r14
test   %ebp,%ebp
jle    1172 <randomHypercycleAlloc+0x52>
mov    %ebp,%ebp
neg    %rbp
mov    $0x1,%ebx
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <random_double@plt>
mov    -0x8(%r14,%rbx,8),%rax
mov    %rbp,%rcx
add    %rbx,%rcx
mov    $0x0,%ecx
cmovne %rbx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
lea    (%rbx,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
jne    1140 <randomHypercycleAlloc+0x20>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define double** @randomHypercycleAlloc(i32 %0) {
%2 = tail call double** @safeMatrixAlloc(i32 %0, i32 %0)
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %17
4: ; preds = %1
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %11, %6 ]
%8 = tail call double (...) @random_double()
%9 = getelementptr inbounds double*, double** %2, i64 %7
%10 = load double*, double** %9
%11 = add nuw nsw i64 %7, 1
%12 = icmp eq i64 %11, %5
%13 = and i64 %11, 4294967295
%14 = select i1 %12, i64 0, i64 %13
%15 = getelementptr inbounds double, double* %10, i64 %14
store double %8, double* %15
%16 = icmp eq i64 %11, %5
br i1 %16, label %17, label %6
17: ; preds = %6, %1
ret double** %2
}