#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 square_matrix(double *matrix, const uint64_t N) {
  for (int ii = 0; ii < N * N; ii++) {
    matrix[ii] *= matrix[ii];
  }
}


x86 assembly (clang, -O0):
<square_matrix>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
imul   -0xc(%rbp),%ecx
cmp    %ecx,%eax
jge    1151 <square_matrix+0x51>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1112 <square_matrix+0x12>
pop    %rbp
ret

x86 assembly (clang, -O2):
<square_matrix>:
imul   %esi,%esi
test   %esi,%esi
je     11d7 <square_matrix+0xd7>
mov    %esi,%eax
cmp    $0x4,%esi
jae    1119 <square_matrix+0x19>
xor    %ecx,%ecx
jmp    11c0 <square_matrix+0xc0>
mov    %eax,%ecx
and    $0xfffffffc,%ecx
lea    -0x4(%rcx),%rdx
mov    %rdx,%r8
shr    $0x2,%r8
add    $0x1,%r8
test   %rdx,%rdx
je     11d8 <square_matrix+0xd8>
mov    %r8,%rsi
and    $0xfffffffffffffffe,%rsi
xor    %edx,%edx
nop
movupd (%rdi,%rdx,8),%xmm0
movupd 0x10(%rdi,%rdx,8),%xmm1
movupd 0x20(%rdi,%rdx,8),%xmm2
movupd 0x30(%rdi,%rdx,8),%xmm3
mulpd  %xmm0,%xmm0
mulpd  %xmm1,%xmm1
movupd %xmm0,(%rdi,%rdx,8)
movupd %xmm1,0x10(%rdi,%rdx,8)
mulpd  %xmm2,%xmm2
mulpd  %xmm3,%xmm3
movupd %xmm2,0x20(%rdi,%rdx,8)
movupd %xmm3,0x30(%rdi,%rdx,8)
add    $0x8,%rdx
add    $0xfffffffffffffffe,%rsi
jne    1140 <square_matrix+0x40>
test   $0x1,%r8b
je     11ac <square_matrix+0xac>
movupd (%rdi,%rdx,8),%xmm0
movupd 0x10(%rdi,%rdx,8),%xmm1
mulpd  %xmm0,%xmm0
mulpd  %xmm1,%xmm1
movupd %xmm0,(%rdi,%rdx,8)
movupd %xmm1,0x10(%rdi,%rdx,8)
cmp    %rax,%rcx
je     11d7 <square_matrix+0xd7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%rdi,%rcx,8),%xmm0
mulsd  %xmm0,%xmm0
movsd  %xmm0,(%rdi,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    11c0 <square_matrix+0xc0>
ret
xor    %edx,%edx
test   $0x1,%r8b
jne    118e <square_matrix+0x8e>
jmp    11ac <square_matrix+0xac>

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

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