#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 **new_matrix2(int, int);
double **new_diag_matrix2(double *diag, int n) {
  double **mat = new_matrix2(n, n);
  int i;
  for (i = 0; i < n; ++i) {
    mat[i][i] = diag[i];
  }
  return mat;
}


x86 assembly (clang, -O0):
<new_diag_matrix2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <new_matrix2@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1171 <new_diag_matrix2+0x61>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1135 <new_diag_matrix2+0x25>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<new_diag_matrix2>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,%edi
call   1030 <new_matrix2@plt>
test   %ebp,%ebp
jle    11b8 <new_diag_matrix2+0xa8>
mov    %ebp,%esi
lea    -0x1(%rsi),%rdx
mov    %esi,%ecx
and    $0x3,%ecx
cmp    $0x3,%rdx
jae    113c <new_diag_matrix2+0x2c>
xor    %edx,%edx
jmp    119a <new_diag_matrix2+0x8a>
and    $0xfffffffc,%esi
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%rbx,%rdx,8),%xmm0
mov    (%rax,%rdx,8),%rdi
movsd  %xmm0,(%rdi,%rdx,8)
movsd  0x8(%rbx,%rdx,8),%xmm0
mov    0x8(%rax,%rdx,8),%rdi
movsd  %xmm0,0x8(%rdi,%rdx,8)
movsd  0x10(%rbx,%rdx,8),%xmm0
mov    0x10(%rax,%rdx,8),%rdi
movsd  %xmm0,0x10(%rdi,%rdx,8)
movsd  0x18(%rbx,%rdx,8),%xmm0
mov    0x18(%rax,%rdx,8),%rdi
movsd  %xmm0,0x18(%rdi,%rdx,8)
add    $0x4,%rdx
cmp    %rdx,%rsi
jne    1150 <new_diag_matrix2+0x40>
test   %rcx,%rcx
je     11b8 <new_diag_matrix2+0xa8>
nop
movsd  (%rbx,%rdx,8),%xmm0
mov    (%rax,%rdx,8),%rsi
movsd  %xmm0,(%rsi,%rdx,8)
add    $0x1,%rdx
add    $0xffffffffffffffff,%rcx
jne    11a0 <new_diag_matrix2+0x90>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define double** @new_diag_matrix2(double* nocapture %0, i32 %1) {
%3 = tail call double** @new_matrix2(i32 %1, i32 %1)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %55
5: ; preds = %2
%6 = zext i32 %1 to i64
%7 = add nsw i64 %6, -1
%8 = and i64 %6, 3
%9 = icmp ult i64 %7, 3
br i1 %9, label %41, label %10
10: ; preds = %5
%11 = and i64 %6, 4294967292
br label %12
12: ; preds = %12, %10
%13 = phi i64 [ 0, %10 ], [ %38, %12 ]
%14 = phi i64 [ 0, %10 ], [ %39, %12 ]
%15 = getelementptr inbounds double, double* %0, i64 %13
%16 = load double, double* %15
%17 = getelementptr inbounds double*, double** %3, i64 %13
%18 = load double*, double** %17
%19 = getelementptr inbounds double, double* %18, i64 %13
store double %16, double* %19
%20 = or i64 %13, 1
%21 = getelementptr inbounds double, double* %0, i64 %20
%22 = load double, double* %21
%23 = getelementptr inbounds double*, double** %3, i64 %20
%24 = load double*, double** %23
%25 = getelementptr inbounds double, double* %24, i64 %20
store double %22, double* %25
%26 = or i64 %13, 2
%27 = getelementptr inbounds double, double* %0, i64 %26
%28 = load double, double* %27
%29 = getelementptr inbounds double*, double** %3, i64 %26
%30 = load double*, double** %29
%31 = getelementptr inbounds double, double* %30, i64 %26
store double %28, double* %31
%32 = or i64 %13, 3
%33 = getelementptr inbounds double, double* %0, i64 %32
%34 = load double, double* %33
%35 = getelementptr inbounds double*, double** %3, i64 %32
%36 = load double*, double** %35
%37 = getelementptr inbounds double, double* %36, i64 %32
store double %34, double* %37
%38 = add nuw nsw i64 %13, 4
%39 = add i64 %14, 4
%40 = icmp eq i64 %39, %11
br i1 %40, label %41, label %12
41: ; preds = %12, %5
%42 = phi i64 [ 0, %5 ], [ %38, %12 ]
%43 = icmp eq i64 %8, 0
br i1 %43, label %55, label %44
44: ; preds = %41, %44
%45 = phi i64 [ %52, %44 ], [ %42, %41 ]
%46 = phi i64 [ %53, %44 ], [ 0, %41 ]
%47 = getelementptr inbounds double, double* %0, i64 %45
%48 = load double, double* %47
%49 = getelementptr inbounds double*, double** %3, i64 %45
%50 = load double*, double** %49
%51 = getelementptr inbounds double, double* %50, i64 %45
store double %48, double* %51
%52 = add nuw nsw i64 %45, 1
%53 = add i64 %46, 1
%54 = icmp eq i64 %53, %8
br i1 %54, label %55, label %44
55: ; preds = %41, %44, %2
ret double** %3
}