; LLVM IR from facebookresearch/habitat-sim :: src/deps/basis-universal/encoder/basisu_ssim.ll (ZN6basisu9avg_imageERKNS_6imagefE)

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

%"class.basisu::vec" = type { [4 x float] }

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6basisu6imagef9get_widthEv(ptr noundef nonnull align 8 dereferenceable(32)) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6basisu6imagef10get_heightEv(ptr noundef nonnull align 8 dereferenceable(32)) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN6basisu3vecILj4EfEC2Effff(ptr noundef nonnull align 4 dereferenceable(16), float noundef, float noundef, float noundef, float noundef) unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN6basisu3vecILj4EfEC2Ef(ptr noundef nonnull align 4 dereferenceable(16), float noundef) unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK6basisu3vecILj4EfEixEj(ptr noundef nonnull align 4 dereferenceable(16), i32 noundef) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(16) ptr @_ZNK6basisu6imagefclEjj(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef, i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6basisu9avg_imageERKNS_6imagefE(ptr dead_on_unwind noalias writable sret(%"class.basisu::vec") align 4 %0, ptr noundef nonnull align 8 dereferenceable(32) %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca %"class.basisu::vec", align 4
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @_ZN6basisu3vecILj4EfEC2Ef(ptr noundef nonnull align 4 dereferenceable(16) %0, float noundef 0.000000e+00)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %41, %2
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = call noundef i32 @_ZNK6basisu6imagef10get_heightEv(ptr noundef nonnull align 8 dereferenceable(32) %12)
  %14 = icmp ult i32 %11, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %10
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %44

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

17:                                               ; preds = %37, %16
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = call noundef i32 @_ZNK6basisu6imagef9get_widthEv(ptr noundef nonnull align 8 dereferenceable(32) %19)
  %21 = icmp ult i32 %18, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %17
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %40

23:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNK6basisu6imagefclEjj(ptr noundef nonnull align 8 dereferenceable(32) %24, i32 noundef %25, i32 noundef %26)
  store ptr %27, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #4
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = call noundef float @_ZNK6basisu3vecILj4EfEixEj(ptr noundef nonnull align 4 dereferenceable(16) %28, i32 noundef 0)
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = call noundef float @_ZNK6basisu3vecILj4EfEixEj(ptr noundef nonnull align 4 dereferenceable(16) %30, i32 noundef 1)
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = call noundef float @_ZNK6basisu3vecILj4EfEixEj(ptr noundef nonnull align 4 dereferenceable(16) %32, i32 noundef 2)
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = call noundef float @_ZNK6basisu3vecILj4EfEixEj(ptr noundef nonnull align 4 dereferenceable(16) %34, i32 noundef 3)
  call void @_ZN6basisu3vecILj4EfEC2Effff(ptr noundef nonnull align 4 dereferenceable(16) %9, float noundef %29, float noundef %31, float noundef %33, float noundef %35)
  %36 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZN6basisu3vecILj4EfEpLERKS1_(ptr noundef nonnull align 4 dereferenceable(16) %0, ptr noundef nonnull align 4 dereferenceable(16) %9)
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %37

37:                                               ; preds = %23
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = add i32 %38, 1
  store i32 %39, ptr %7, align 4, !tbaa !9
  br label %17, !llvm.loop !11

40:                                               ; preds = %22
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = add i32 %42, 1
  store i32 %43, ptr %5, align 4, !tbaa !9
  br label %10, !llvm.loop !13

44:                                               ; preds = %15
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = call noundef i32 @_ZNK6basisu6imagef16get_total_pixelsEv(ptr noundef nonnull align 8 dereferenceable(32) %45)
  %47 = uitofp i32 %46 to float
  %48 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZN6basisu3vecILj4EfEdVEf(ptr noundef nonnull align 4 dereferenceable(16) %0, float noundef %47)
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(16) ptr @_ZN6basisu3vecILj4EfEpLERKS1_(ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16)) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6basisu6imagef16get_total_pixelsEv(ptr noundef nonnull align 8 dereferenceable(32)) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(16) ptr @_ZN6basisu3vecILj4EfEdVEf(ptr noundef nonnull align 4 dereferenceable(16), float noundef) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint mustprogress 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 = { inlinehint mustprogress 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 = { mustprogress 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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

%"class.basisu::vec" = type { [4 x float] }

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6basisu6imagef9get_widthEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6basisu6imagef10get_heightEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN6basisu3vecILj4EfEC2Effff(ptr noundef nonnull align 4 dereferenceable(16), float noundef, float noundef, float noundef, float noundef) unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN6basisu3vecILj4EfEC2Ef(ptr noundef nonnull align 4 dereferenceable(16), float noundef) unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK6basisu3vecILj4EfEixEj(ptr noundef nonnull align 4 dereferenceable(16), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(16) ptr @_ZNK6basisu6imagefclEjj(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef, i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6basisu9avg_imageERKNS_6imagefE(ptr dead_on_unwind noalias nonnull writable sret(%"class.basisu::vec") align 4 %0, ptr noundef nonnull align 8 dereferenceable(32) %1) local_unnamed_addr #3 {
  %3 = alloca %"class.basisu::vec", align 4
  tail call void @_ZN6basisu3vecILj4EfEC2Ef(ptr noundef nonnull align 4 dereferenceable(16) %0, float noundef 0.000000e+00)
  %4 = tail call noundef i32 @_ZNK6basisu6imagef10get_heightEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %._crit_edge16, label %.preheader

.preheader:                                       ; preds = %2, %._crit_edge
  %.015 = phi i32 [ %9, %._crit_edge ], [ 0, %2 ]
  %5 = call noundef i32 @_ZNK6basisu6imagef9get_widthEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  %.not17 = icmp eq i32 %5, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph

._crit_edge16:                                    ; preds = %._crit_edge, %2
  %6 = call noundef i32 @_ZNK6basisu6imagef16get_total_pixelsEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  %7 = uitofp i32 %6 to float
  %8 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZN6basisu3vecILj4EfEdVEf(ptr noundef nonnull align 4 dereferenceable(16) %0, float noundef %7)
  ret void

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %9 = add nuw i32 %.015, 1
  %10 = call noundef i32 @_ZNK6basisu6imagef10get_heightEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  %11 = icmp ult i32 %9, %10
  br i1 %11, label %.preheader, label %._crit_edge16, !llvm.loop !5

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.01314 = phi i32 [ %18, %.lr.ph ], [ 0, %.preheader ]
  %12 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNK6basisu6imagefclEjj(ptr noundef nonnull align 8 dereferenceable(32) %1, i32 noundef %.01314, i32 noundef %.015)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  %13 = call noundef float @_ZNK6basisu3vecILj4EfEixEj(ptr noundef nonnull align 4 dereferenceable(16) %12, i32 noundef 0)
  %14 = call noundef float @_ZNK6basisu3vecILj4EfEixEj(ptr noundef nonnull align 4 dereferenceable(16) %12, i32 noundef 1)
  %15 = call noundef float @_ZNK6basisu3vecILj4EfEixEj(ptr noundef nonnull align 4 dereferenceable(16) %12, i32 noundef 2)
  %16 = call noundef float @_ZNK6basisu3vecILj4EfEixEj(ptr noundef nonnull align 4 dereferenceable(16) %12, i32 noundef 3)
  call void @_ZN6basisu3vecILj4EfEC2Effff(ptr noundef nonnull align 4 dereferenceable(16) %3, float noundef %13, float noundef %14, float noundef %15, float noundef %16)
  %17 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZN6basisu3vecILj4EfEpLERKS1_(ptr noundef nonnull align 4 dereferenceable(16) %0, ptr noundef nonnull align 4 dereferenceable(16) %3)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  %18 = add nuw i32 %.01314, 1
  %19 = call noundef i32 @_ZNK6basisu6imagef9get_widthEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  %20 = icmp ult i32 %18, %19
  br i1 %20, label %.lr.ph, label %._crit_edge, !llvm.loop !7
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(16) ptr @_ZN6basisu3vecILj4EfEpLERKS1_(ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6basisu6imagef16get_total_pixelsEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(16) ptr @_ZN6basisu3vecILj4EfEdVEf(ptr noundef nonnull align 4 dereferenceable(16), float noundef) local_unnamed_addr #1 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint mustprogress 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 = { inlinehint mustprogress 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 = { mustprogress 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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass