; LLVM IR from HRI-EU/Rcs :: src/RcsCore (Rcs_MatNd)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct._MatNd = type { ptr, i32, i32, i32, i8 }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local void @MatNd_mul(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @MatNd_nullspace(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  call void @MatNd_mul(ptr noundef %10, ptr noundef %11, ptr noundef %12)
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %67, %3
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._MatNd, ptr %15, i32 0, i32 2
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = icmp ult i32 %14, %17
  br i1 %18, label %19, label %70

19:                                               ; preds = %13
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %63, %19
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._MatNd, ptr %22, i32 0, i32 2
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %25 = icmp ult i32 %21, %24
  br i1 %25, label %26, label %66

26:                                               ; preds = %20
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._MatNd, ptr %28, i32 0, i32 2
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = mul i32 %27, %30
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = add i32 %31, %32
  store i32 %33, ptr %9, align 4, !tbaa !9
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = icmp eq i32 %34, %35
  br i1 %36, label %37, label %46

37:                                               ; preds = %26
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._MatNd, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds double, ptr %40, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !15
  %45 = fsub double 1.000000e+00, %44
  br label %55

46:                                               ; preds = %26
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._MatNd, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !14
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = zext i32 %50 to i64
  %52 = getelementptr inbounds double, ptr %49, i64 %51
  %53 = load double, ptr %52, align 8, !tbaa !15
  %54 = fneg double %53
  br label %55

55:                                               ; preds = %46, %37
  %56 = phi double [ %45, %37 ], [ %54, %46 ]
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct._MatNd, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !14
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = zext i32 %60 to i64
  %62 = getelementptr inbounds double, ptr %59, i64 %61
  store double %56, ptr %62, align 8, !tbaa !15
  br label %63

63:                                               ; preds = %55
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = add i32 %64, 1
  store i32 %65, ptr %8, align 4, !tbaa !9
  br label %20, !llvm.loop !17

66:                                               ; preds = %20
  br label %67

67:                                               ; preds = %66
  %68 = load i32, ptr %7, align 4, !tbaa !9
  %69 = add i32 %68, 1
  store i32 %69, ptr %7, align 4, !tbaa !9
  br label %13, !llvm.loop !19

70:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 12}
!12 = !{!"_MatNd", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !13, i64 20}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!12, !6, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nounwind uwtable
declare dso_local void @MatNd_mul(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @MatNd_nullspace(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  tail call void @MatNd_mul(ptr noundef %0, ptr noundef %1, ptr noundef %2)
  %4 = getelementptr inbounds i8, ptr %2, i64 12
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %._crit_edge, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %3
  %6 = load ptr, ptr %0, align 8, !tbaa !12
  %wide.trip.count27 = zext i32 %5 to i64
  %7 = add nsw i64 %wide.trip.count27, -1
  %min.iters.check = icmp ult i32 %5, 4
  %8 = trunc i64 %7 to i32
  %9 = icmp ugt i64 %7, 4294967295
  %n.vec = and i64 %wide.trip.count27, 4294967292
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count27
  %xtraiter = and i64 %wide.trip.count27, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  %10 = add nsw i64 %wide.trip.count27, -1
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %.loopexit
  %indvars.iv24 = phi i64 [ 0, %.preheader.lr.ph ], [ %indvars.iv.next25, %.loopexit ]
  %11 = trunc nuw i64 %indvars.iv24 to i32
  %12 = mul i32 %5, %11
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %.preheader
  %13 = trunc i64 %indvars.iv24 to i32
  %14 = mul i32 %5, %13
  %15 = xor i32 %14, -1
  %16 = icmp ult i32 %15, %8
  %17 = or i1 %16, %9
  br i1 %17, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.scevcheck
  %broadcast.splatinsert = insertelement <2 x i64> poison, i64 %indvars.iv24, i64 0
  %broadcast.splat = shufflevector <2 x i64> %broadcast.splatinsert, <2 x i64> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <2 x i64> [ <i64 0, i64 1>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %step.add = add <2 x i64> %vec.ind, <i64 2, i64 2>
  %18 = trunc i64 %index to i32
  %19 = add i32 %12, %18
  %20 = icmp eq <2 x i64> %broadcast.splat, %vec.ind
  %21 = icmp eq <2 x i64> %broadcast.splat, %step.add
  %22 = zext i32 %19 to i64
  %23 = getelementptr inbounds double, ptr %6, i64 %22
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  %wide.load = load <2 x double>, ptr %23, align 8, !tbaa !13
  %wide.load30 = load <2 x double>, ptr %24, align 8, !tbaa !13
  %25 = fneg <2 x double> %wide.load
  %26 = fneg <2 x double> %wide.load30
  %27 = fsub <2 x double> <double 1.000000e+00, double 1.000000e+00>, %wide.load
  %28 = fsub <2 x double> <double 1.000000e+00, double 1.000000e+00>, %wide.load30
  %29 = select <2 x i1> %20, <2 x double> %27, <2 x double> %25
  %30 = select <2 x i1> %21, <2 x double> %28, <2 x double> %26
  store <2 x double> %29, ptr %23, align 8, !tbaa !13
  store <2 x double> %30, ptr %24, align 8, !tbaa !13
  %index.next = add nuw i64 %index, 4
  %vec.ind.next = add <2 x i64> %vec.ind, <i64 4, i64 4>
  %31 = icmp eq i64 %index.next, %n.vec
  br i1 %31, label %middle.block, label %vector.body, !llvm.loop !15

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.scevcheck, %.preheader
  %indvars.iv.ph = phi i64 [ 0, %vector.scevcheck ], [ 0, %.preheader ], [ %n.vec, %middle.block ]
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %32 = trunc nuw i64 %indvars.iv.ph to i32
  %33 = add i32 %12, %32
  %34 = icmp eq i64 %indvars.iv24, %indvars.iv.ph
  %35 = zext i32 %33 to i64
  %36 = getelementptr inbounds double, ptr %6, i64 %35
  %37 = load double, ptr %36, align 8, !tbaa !13
  %38 = fneg double %37
  %39 = fsub double 1.000000e+00, %37
  %40 = select i1 %34, double %39, double %38
  %41 = getelementptr inbounds double, ptr %6, i64 %35
  store double %40, ptr %41, align 8, !tbaa !13
  %indvars.iv.next.prol = or disjoint i64 %indvars.iv.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %42 = icmp eq i64 %indvars.iv.ph, %10
  br i1 %42, label %.loopexit, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %43 = trunc nuw i64 %indvars.iv to i32
  %44 = add i32 %12, %43
  %45 = icmp eq i64 %indvars.iv24, %indvars.iv
  %46 = zext i32 %44 to i64
  %47 = getelementptr inbounds double, ptr %6, i64 %46
  %48 = load double, ptr %47, align 8, !tbaa !13
  %49 = fneg double %48
  %50 = fsub double 1.000000e+00, %48
  %51 = select i1 %45, double %50, double %49
  %52 = getelementptr inbounds double, ptr %6, i64 %46
  store double %51, ptr %52, align 8, !tbaa !13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %53 = trunc nuw i64 %indvars.iv.next to i32
  %54 = add i32 %12, %53
  %55 = icmp eq i64 %indvars.iv24, %indvars.iv.next
  %56 = zext i32 %54 to i64
  %57 = getelementptr inbounds double, ptr %6, i64 %56
  %58 = load double, ptr %57, align 8, !tbaa !13
  %59 = fneg double %58
  %60 = fsub double 1.000000e+00, %58
  %61 = select i1 %55, double %60, double %59
  %62 = getelementptr inbounds double, ptr %6, i64 %56
  store double %61, ptr %62, align 8, !tbaa !13
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, %wide.trip.count27
  br i1 %exitcond.not.1, label %.loopexit, label %scalar.ph, !llvm.loop !19

.loopexit:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %indvars.iv.next25 = add nuw nsw i64 %indvars.iv24, 1
  %exitcond28.not = icmp eq i64 %indvars.iv.next25, %wide.trip.count27
  br i1 %exitcond28.not, label %._crit_edge, label %.preheader, !llvm.loop !20

._crit_edge:                                      ; preds = %.loopexit, %3
  ret void
}

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !10, i64 12}
!6 = !{!"_MatNd", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !11, i64 20}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !8, i64 0}
!15 = distinct !{!15, !16, !17, !18}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!"llvm.loop.isvectorized", i32 1}
!18 = !{!"llvm.loop.unroll.runtime.disable"}
!19 = distinct !{!19, !16, !17}
!20 = distinct !{!20, !16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass