; 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 }

@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.73 = external hidden unnamed_addr constant [17 x i8], align 1
@__func__.MatNd_columnSum = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

declare void @print_trace() #1

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

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

; Function Attrs: noreturn nounwind
declare void @abort() #3

; Function Attrs: nounwind uwtable
define dso_local double @MatNd_columnSum(ptr noundef %0, i32 noundef %1) #4 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store double 0.000000e+00, ptr %5, align 8, !tbaa !11
  br label %7

7:                                                ; preds = %2
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct._MatNd, ptr %9, i32 0, i32 2
  %11 = load i32, ptr %10, align 4, !tbaa !13
  %12 = icmp ult i32 %8, %11
  br i1 %12, label %16, label %13

13:                                               ; preds = %7
  %14 = load ptr, ptr @stderr, align 8, !tbaa !5
  %15 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef @.str.5, ptr noundef @.str.1, ptr noundef @__func__.MatNd_columnSum, i32 noundef 2448, ptr noundef @.str.73) #5
  call void @print_trace()
  call void @abort() #6
  unreachable

16:                                               ; preds = %7
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %19

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

25:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %45

26:                                               ; preds = %19
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._MatNd, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !17
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._MatNd, ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 4, !tbaa !13
  %34 = mul i32 %30, %33
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = add i32 %34, %35
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds double, ptr %29, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !11
  %40 = load double, ptr %5, align 8, !tbaa !11
  %41 = fadd double %40, %39
  store double %41, ptr %5, align 8, !tbaa !11
  br label %42

42:                                               ; preds = %26
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = add i32 %43, 1
  store i32 %44, ptr %6, align 4, !tbaa !9
  br label %19, !llvm.loop !18

45:                                               ; preds = %25
  %46 = load double, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret double %46
}

attributes #0 = { nounwind "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 #1 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { noreturn nounwind "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 #4 = { 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 #5 = { nounwind }
attributes #6 = { noreturn 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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !10, i64 12}
!14 = !{!"_MatNd", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !15, i64 20}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!14, !10, i64 8}
!17 = !{!14, !6, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; 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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.73 = external hidden unnamed_addr constant [17 x i8], align 1
@__func__.MatNd_columnSum = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

declare void @print_trace() local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local double @MatNd_columnSum(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #3 {
  %3 = getelementptr inbounds i8, ptr %0, i64 12
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp ugt i32 %4, %1
  br i1 %5, label %.preheader, label %10

.preheader:                                       ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i32, ptr %6, align 8, !tbaa !12
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %8 = load ptr, ptr %0, align 8, !tbaa !13
  %wide.trip.count = zext i32 %7 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %9 = icmp ult i32 %7, 4
  br i1 %9, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 4294967292
  br label %20

10:                                               ; preds = %2
  %11 = load ptr, ptr @stderr, align 8, !tbaa !14
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.MatNd_columnSum, i32 noundef 2448, ptr noundef nonnull @.str.73) #4
  tail call void @print_trace() #5
  tail call void @abort() #6
  unreachable

._crit_edge.loopexit.unr-lcssa:                   ; preds = %20, %.lr.ph
  %.lcssa.ph = phi double [ poison, %.lr.ph ], [ %51, %20 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.3, %20 ]
  %.01012.unr = phi double [ 0.000000e+00, %.lr.ph ], [ %51, %20 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.01012.epil = phi double [ %19, %.epil.preheader ], [ %.01012.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %13 = trunc nuw i64 %indvars.iv.epil to i32
  %14 = mul i32 %4, %13
  %15 = add i32 %14, %1
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds double, ptr %8, i64 %16
  %18 = load double, ptr %17, align 8, !tbaa !15
  %19 = fadd double %.01012.epil, %18
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.epil.preheader, !llvm.loop !17

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader, %.preheader
  %.010.lcssa = phi double [ 0.000000e+00, %.preheader ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %19, %.epil.preheader ]
  ret double %.010.lcssa

20:                                               ; preds = %20, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.3, %20 ]
  %.01012 = phi double [ 0.000000e+00, %.lr.ph.new ], [ %51, %20 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %20 ]
  %21 = trunc nuw i64 %indvars.iv to i32
  %22 = mul i32 %4, %21
  %23 = add i32 %22, %1
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds double, ptr %8, i64 %24
  %26 = load double, ptr %25, align 8, !tbaa !15
  %27 = fadd double %.01012, %26
  %28 = trunc i64 %indvars.iv to i32
  %29 = or disjoint i32 %28, 1
  %30 = mul i32 %4, %29
  %31 = add i32 %30, %1
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds double, ptr %8, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !15
  %35 = fadd double %27, %34
  %36 = trunc i64 %indvars.iv to i32
  %37 = or disjoint i32 %36, 2
  %38 = mul i32 %4, %37
  %39 = add i32 %38, %1
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds double, ptr %8, i64 %40
  %42 = load double, ptr %41, align 8, !tbaa !15
  %43 = fadd double %35, %42
  %44 = trunc i64 %indvars.iv to i32
  %45 = or disjoint i32 %44, 3
  %46 = mul i32 %4, %45
  %47 = add i32 %46, %1
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds double, ptr %8, i64 %48
  %50 = load double, ptr %49, align 8, !tbaa !15
  %51 = fadd double %43, %50
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %20, !llvm.loop !19
}

attributes #0 = { nofree nounwind "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 #1 = { "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 = { noreturn nounwind "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 #3 = { 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 #4 = { cold nounwind }
attributes #5 = { nounwind }
attributes #6 = { noreturn 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, !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, !10, i64 8}
!13 = !{!6, !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !8, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass