#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 */
typedef int uint64_t;

/* Variables and functions */
void fill_matrix(double *matrix, const uint64_t N) {
  for (int ii = 0; ii < N; ii++) {
    for (int jj = 0; jj < N; jj++) {
      matrix[(ii * N + jj)] = 1;
    }
  }
}


x86 assembly (clang, -O0):
<fill_matrix>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1170 <fill_matrix+0x70>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    115d <fill_matrix+0x5d>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
imul   -0xc(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movsd  0xeb6(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1125 <fill_matrix+0x25>
jmp    1162 <fill_matrix+0x62>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1112 <fill_matrix+0x12>
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %esi,%esi
jle    1232 <fill_matrix+0x132>
mov    %esi,%eax
mov    %eax,%r11d
and    $0xfffffffc,%r11d
lea    -0x4(%r11),%r9
mov    %r9,%r8
shr    $0x2,%r8
add    $0x1,%r8
mov    %r8d,%r10d
and    $0x3,%r10d
and    $0xfffffffffffffffc,%r8
lea    0x70(%rdi),%rdx
lea    0x0(,%rax,8),%r14
lea    0x10(%rdi),%r15
mov    %r10,%r13
shl    $0x5,%r13
xor    %r12d,%r12d
movabs $0x3ff0000000000000,%rbx
movaps 0xea0(%rip),%xmm0
jmp    1186 <fill_matrix+0x86>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r12
add    %r14,%rdx
add    %r14,%r15
add    %r14,%rdi
cmp    %rax,%r12
je     1232 <fill_matrix+0x132>
cmp    $0x4,%esi
jae    11a0 <fill_matrix+0xa0>
xor    %ecx,%ecx
jmp    1220 <fill_matrix+0x120>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0xc,%r9
jae    11b0 <fill_matrix+0xb0>
xor    %ecx,%ecx
jmp    11f1 <fill_matrix+0xf1>
nopw   0x0(%rax,%rax,1)
mov    %r8,%rbp
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
movups %xmm0,-0x70(%rdx,%rcx,8)
movups %xmm0,-0x60(%rdx,%rcx,8)
movups %xmm0,-0x50(%rdx,%rcx,8)
movups %xmm0,-0x40(%rdx,%rcx,8)
movups %xmm0,-0x30(%rdx,%rcx,8)
movups %xmm0,-0x20(%rdx,%rcx,8)
movups %xmm0,-0x10(%rdx,%rcx,8)
movups %xmm0,(%rdx,%rcx,8)
add    $0x10,%rcx
add    $0xfffffffffffffffc,%rbp
jne    11c0 <fill_matrix+0xc0>
test   %r10,%r10
je     1212 <fill_matrix+0x112>
lea    (%r15,%rcx,8),%rcx
xor    %ebp,%ebp
nopl   0x0(%rax)
movups %xmm0,-0x10(%rcx,%rbp,1)
movups %xmm0,(%rcx,%rbp,1)
add    $0x20,%rbp
cmp    %rbp,%r13
jne    1200 <fill_matrix+0x100>
mov    %r11,%rcx
cmp    %rax,%r11
je     1170 <fill_matrix+0x70>
xchg   %ax,%ax
mov    %rbx,(%rdi,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1220 <fill_matrix+0x120>
jmp    1170 <fill_matrix+0x70>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @fill_matrix(double* nocapture writeonly %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %67
4: ; preds = %2
%5 = zext i32 %1 to i64
%6 = zext i32 %1 to i64
%7 = and i64 %6, 4294967292
%8 = add nsw i64 %7, -4
%9 = lshr exact i64 %8, 2
%10 = add nuw nsw i64 %9, 1
%11 = icmp ult i32 %1, 4
%12 = and i64 %6, 4294967292
%13 = and i64 %10, 3
%14 = icmp ult i64 %8, 12
%15 = and i64 %10, 9223372036854775804
%16 = icmp eq i64 %13, 0
%17 = icmp eq i64 %12, %6
br label %18
18: ; preds = %68, %4
%19 = phi i64 [ 0, %4 ], [ %69, %68 ]
%20 = mul nsw i64 %19, %5
br i1 %11, label %65, label %21
21: ; preds = %18
br i1 %14, label %51, label %22
22: ; preds = %21, %22
%23 = phi i64 [ %48, %22 ], [ 0, %21 ]
%24 = phi i64 [ %49, %22 ], [ 0, %21 ]
%25 = add nuw nsw i64 %23, %20
%26 = getelementptr inbounds double, double* %0, i64 %25
%27 = bitcast double* %26 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %27
%28 = getelementptr inbounds double, double* %26, i64 2
%29 = bitcast double* %28 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %29
%30 = or i64 %23, 4
%31 = add nuw nsw i64 %30, %20
%32 = getelementptr inbounds double, double* %0, i64 %31
%33 = bitcast double* %32 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %33
%34 = getelementptr inbounds double, double* %32, i64 2
%35 = bitcast double* %34 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %35
%36 = or i64 %23, 8
%37 = add nuw nsw i64 %36, %20
%38 = getelementptr inbounds double, double* %0, i64 %37
%39 = bitcast double* %38 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %39
%40 = getelementptr inbounds double, double* %38, i64 2
%41 = bitcast double* %40 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %41
%42 = or i64 %23, 12
%43 = add nuw nsw i64 %42, %20
%44 = getelementptr inbounds double, double* %0, i64 %43
%45 = bitcast double* %44 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %45
%46 = getelementptr inbounds double, double* %44, i64 2
%47 = bitcast double* %46 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %47
%48 = add nuw i64 %23, 16
%49 = add nuw i64 %24, 4
%50 = icmp eq i64 %49, %15
br i1 %50, label %51, label %22
51: ; preds = %22, %21
%52 = phi i64 [ 0, %21 ], [ %48, %22 ]
br i1 %16, label %64, label %53
53: ; preds = %51, %53
%54 = phi i64 [ %61, %53 ], [ %52, %51 ]
%55 = phi i64 [ %62, %53 ], [ 0, %51 ]
%56 = add nuw nsw i64 %54, %20
%57 = getelementptr inbounds double, double* %0, i64 %56
%58 = bitcast double* %57 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %58
%59 = getelementptr inbounds double, double* %57, i64 2
%60 = bitcast double* %59 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %60
%61 = add nuw i64 %54, 4
%62 = add i64 %55, 1
%63 = icmp eq i64 %62, %13
br i1 %63, label %64, label %53
64: ; preds = %53, %51
br i1 %17, label %68, label %65
65: ; preds = %18, %64
%66 = phi i64 [ 0, %18 ], [ %12, %64 ]
br label %71
67: ; preds = %68, %2
ret void
68: ; preds = %71, %64
%69 = add nuw nsw i64 %19, 1
%70 = icmp eq i64 %69, %6
br i1 %70, label %67, label %18
71: ; preds = %65, %71
%72 = phi i64 [ %75, %71 ], [ %66, %65 ]
%73 = add nuw nsw i64 %72, %20
%74 = getelementptr inbounds double, double* %0, i64 %73
store double 1.000000e+00, double* %74
%75 = add nuw nsw i64 %72, 1
%76 = icmp eq i64 %75, %6
br i1 %76, label %68, label %71
}