; 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nounwind uwtable
declare dso_local void @MatNd_reshape(ptr noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @MatNd_setZero(ptr noundef) #2

; 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_set(ptr noundef, i32 noundef, i32 noundef, double noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @MatNd_getRowPtr(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @MatNd_interpolateLinear(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._MatNd, ptr %16, i32 0, i32 1
  %18 = load i32, ptr %17, align 8, !tbaa !11
  store i32 %18, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._MatNd, ptr %19, i32 0, i32 2
  %21 = load i32, ptr %20, align 4, !tbaa !14
  store i32 %21, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = sub i32 %22, 1
  store i32 %23, ptr %12, align 4, !tbaa !9
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = load i32, ptr %12, align 4, !tbaa !9
  %27 = mul i32 %25, %26
  %28 = add i32 %27, 1
  %29 = load i32, ptr %8, align 4, !tbaa !9
  call void @MatNd_reshape(ptr noundef %24, i32 noundef %28, i32 noundef %29)
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  call void @MatNd_setZero(ptr noundef %30)
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %91, %3
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = load i32, ptr %12, align 4, !tbaa !9
  %34 = icmp ult i32 %32, %33
  br i1 %34, label %35, label %94

35:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = call ptr @MatNd_getRowPtr(ptr noundef %36, i32 noundef %37)
  store ptr %38, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = add i32 %40, 1
  %42 = call ptr @MatNd_getRowPtr(ptr noundef %39, i32 noundef %41)
  store ptr %42, ptr %14, align 8, !tbaa !5
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %87, %35
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = icmp ule i32 %44, %45
  br i1 %46, label %47, label %90

47:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = uitofp i32 %48 to double
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = uitofp i32 %50 to double
  %52 = fdiv double %49, %51
  store double %52, ptr %15, align 8, !tbaa !15
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %83, %47
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = icmp ult i32 %54, %55
  br i1 %56, label %57, label %86

57:                                               ; preds = %53
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = load i32, ptr %9, align 4, !tbaa !9
  %60 = load i32, ptr %6, align 4, !tbaa !9
  %61 = mul i32 %59, %60
  %62 = load i32, ptr %10, align 4, !tbaa !9
  %63 = add i32 %61, %62
  %64 = load i32, ptr %11, align 4, !tbaa !9
  %65 = load ptr, ptr %13, align 8, !tbaa !5
  %66 = load i32, ptr %11, align 4, !tbaa !9
  %67 = zext i32 %66 to i64
  %68 = getelementptr inbounds double, ptr %65, i64 %67
  %69 = load double, ptr %68, align 8, !tbaa !15
  %70 = load double, ptr %15, align 8, !tbaa !15
  %71 = load ptr, ptr %14, align 8, !tbaa !5
  %72 = load i32, ptr %11, align 4, !tbaa !9
  %73 = zext i32 %72 to i64
  %74 = getelementptr inbounds double, ptr %71, i64 %73
  %75 = load double, ptr %74, align 8, !tbaa !15
  %76 = load ptr, ptr %13, align 8, !tbaa !5
  %77 = load i32, ptr %11, align 4, !tbaa !9
  %78 = zext i32 %77 to i64
  %79 = getelementptr inbounds double, ptr %76, i64 %78
  %80 = load double, ptr %79, align 8, !tbaa !15
  %81 = fsub double %75, %80
  %82 = call double @llvm.fmuladd.f64(double %70, double %81, double %69)
  call void @MatNd_set(ptr noundef %58, i32 noundef %63, i32 noundef %64, double noundef %82)
  br label %83

83:                                               ; preds = %57
  %84 = load i32, ptr %11, align 4, !tbaa !9
  %85 = add i32 %84, 1
  store i32 %85, ptr %11, align 4, !tbaa !9
  br label %53, !llvm.loop !17

86:                                               ; preds = %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  br label %87

87:                                               ; preds = %86
  %88 = load i32, ptr %10, align 4, !tbaa !9
  %89 = add i32 %88, 1
  store i32 %89, ptr %10, align 4, !tbaa !9
  br label %43, !llvm.loop !19

90:                                               ; preds = %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %91

91:                                               ; preds = %90
  %92 = load i32, ptr %9, align 4, !tbaa !9
  %93 = add i32 %92, 1
  store i32 %93, ptr %9, align 4, !tbaa !9
  br label %31, !llvm.loop !20

94:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @MatNd_set(ptr noundef, i32 noundef, i32 noundef, double noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @MatNd_getRowPtr(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @MatNd_interpolateLinear(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 12
  %7 = load i32, ptr %6, align 4, !tbaa !12
  %8 = add i32 %5, -1
  %9 = mul i32 %8, %2
  %10 = add i32 %9, 1
  tail call void @MatNd_reshape(ptr noundef %0, i32 noundef %10, i32 noundef %7)
  tail call void @MatNd_setZero(ptr noundef %0)
  %.not40 = icmp eq i32 %8, 0
  br i1 %.not40, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %11 = uitofp i32 %2 to double
  %.not41 = icmp eq i32 %7, 0
  br i1 %.not41, label %.split, label %.split.us.us.preheader

.split.us.us.preheader:                           ; preds = %.lr.ph
  %wide.trip.count = zext i32 %7 to i64
  br label %.split.us.us

.split.us.us:                                     ; preds = %.split.us.us.preheader, %.loopexit.split.us.us
  %.039.us = phi i32 [ %13, %.loopexit.split.us.us ], [ 0, %.split.us.us.preheader ]
  %12 = tail call ptr @MatNd_getRowPtr(ptr noundef %1, i32 noundef %.039.us)
  %13 = add nuw i32 %.039.us, 1
  %14 = tail call ptr @MatNd_getRowPtr(ptr noundef %1, i32 noundef %13)
  %15 = mul i32 %.039.us, %2
  br label %.lr.ph.us.us

.lr.ph.us.us:                                     ; preds = %._crit_edge.us.us, %.split.us.us
  %.03438.us.us = phi i32 [ 0, %.split.us.us ], [ %27, %._crit_edge.us.us ]
  %16 = uitofp i32 %.03438.us.us to double
  %17 = fdiv double %16, %11
  %18 = add i32 %.03438.us.us, %15
  br label %19

19:                                               ; preds = %19, %.lr.ph.us.us
  %indvars.iv = phi i64 [ %indvars.iv.next, %19 ], [ 0, %.lr.ph.us.us ]
  %20 = getelementptr inbounds double, ptr %12, i64 %indvars.iv
  %21 = load double, ptr %20, align 8, !tbaa !13
  %22 = getelementptr inbounds double, ptr %14, i64 %indvars.iv
  %23 = load double, ptr %22, align 8, !tbaa !13
  %24 = fsub double %23, %21
  %25 = tail call double @llvm.fmuladd.f64(double %17, double %24, double %21)
  %26 = trunc nuw i64 %indvars.iv to i32
  tail call void @MatNd_set(ptr noundef %0, i32 noundef %18, i32 noundef %26, double noundef %25)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.us.us, label %19, !llvm.loop !15

._crit_edge.us.us:                                ; preds = %19
  %27 = add i32 %.03438.us.us, 1
  %.not.us.us = icmp ugt i32 %27, %2
  br i1 %.not.us.us, label %.loopexit.split.us.us, label %.lr.ph.us.us, !llvm.loop !17

.loopexit.split.us.us:                            ; preds = %._crit_edge.us.us
  %exitcond44.not = icmp eq i32 %13, %8
  br i1 %exitcond44.not, label %._crit_edge, label %.split.us.us, !llvm.loop !18

.split:                                           ; preds = %.lr.ph, %.split
  %.039 = phi i32 [ %29, %.split ], [ 0, %.lr.ph ]
  %28 = tail call ptr @MatNd_getRowPtr(ptr noundef %1, i32 noundef %.039)
  %29 = add nuw i32 %.039, 1
  %30 = tail call ptr @MatNd_getRowPtr(ptr noundef %1, i32 noundef %29)
  %exitcond45.not = icmp eq i32 %29, %8
  br i1 %exitcond45.not, label %._crit_edge, label %.split, !llvm.loop !18

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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" }

!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 8}
!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 12}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}


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