; LLVM IR from rdguez-mariano/fast_imas_IPOL :: libLocalDesc/surf/image.ll (ZN13imageIntegral20computeIntegralImageEP5image)

; 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.imageIntegral = type <{ i32, i32, ptr, i32, [4 x 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN5imageclEii(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef) #1 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN13imageIntegral20computeIntegralImageEP5image(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr noundef %1) #2 align 2 {
  %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 i64, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN5imageclEii(ptr noundef nonnull align 8 dereferenceable(16) %11, i32 noundef 0, i32 noundef 0)
  %13 = load double, ptr %12, align 8, !tbaa !9
  %14 = fptosi double %13 to i64
  %15 = getelementptr inbounds %class.imageIntegral, ptr %10, i32 0, i32 2
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = getelementptr inbounds i64, ptr %16, i64 0
  store i64 %14, ptr %17, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 1, ptr %5, align 4, !tbaa !16
  br label %18

18:                                               ; preds = %44, %2
  %19 = load i32, ptr %5, align 4, !tbaa !16
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = call noundef i32 @_ZN5image8getWidthEv(ptr noundef nonnull align 8 dereferenceable(16) %20)
  %22 = icmp slt i32 %19, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %47

24:                                               ; preds = %18
  %25 = getelementptr inbounds %class.imageIntegral, ptr %10, i32 0, i32 2
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = load i32, ptr %5, align 4, !tbaa !16
  %28 = sub nsw i32 %27, 1
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i64, ptr %26, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !14
  %32 = sitofp i64 %31 to double
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !16
  %35 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN5imageclEii(ptr noundef nonnull align 8 dereferenceable(16) %33, i32 noundef %34, i32 noundef 0)
  %36 = load double, ptr %35, align 8, !tbaa !9
  %37 = fadd double %32, %36
  %38 = fptosi double %37 to i64
  %39 = getelementptr inbounds %class.imageIntegral, ptr %10, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  %41 = load i32, ptr %5, align 4, !tbaa !16
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i64, ptr %40, i64 %42
  store i64 %38, ptr %43, align 8, !tbaa !14
  br label %44

44:                                               ; preds = %24
  %45 = load i32, ptr %5, align 4, !tbaa !16
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %5, align 4, !tbaa !16
  br label %18, !llvm.loop !17

47:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 1, ptr %6, align 4, !tbaa !16
  br label %48

48:                                               ; preds = %99, %47
  %49 = load i32, ptr %6, align 4, !tbaa !16
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = call noundef i32 @_ZN5image9getHeightEv(ptr noundef nonnull align 8 dereferenceable(16) %50)
  %52 = icmp slt i32 %49, %51
  br i1 %52, label %54, label %53

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

54:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !16
  br label %55

55:                                               ; preds = %95, %54
  %56 = load i32, ptr %9, align 4, !tbaa !16
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = call noundef i32 @_ZN5image8getWidthEv(ptr noundef nonnull align 8 dereferenceable(16) %57)
  %59 = icmp slt i32 %56, %58
  br i1 %59, label %61, label %60

60:                                               ; preds = %55
  store i32 8, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %98

61:                                               ; preds = %55
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = load i32, ptr %9, align 4, !tbaa !16
  %64 = load i32, ptr %6, align 4, !tbaa !16
  %65 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN5imageclEii(ptr noundef nonnull align 8 dereferenceable(16) %62, i32 noundef %63, i32 noundef %64)
  %66 = load double, ptr %65, align 8, !tbaa !9
  %67 = load i64, ptr %8, align 8, !tbaa !14
  %68 = sitofp i64 %67 to double
  %69 = fadd double %68, %66
  %70 = fptosi double %69 to i64
  store i64 %70, ptr %8, align 8, !tbaa !14
  %71 = getelementptr inbounds %class.imageIntegral, ptr %10, i32 0, i32 2
  %72 = load ptr, ptr %71, align 8, !tbaa !11
  %73 = load i32, ptr %9, align 4, !tbaa !16
  %74 = getelementptr inbounds %class.imageIntegral, ptr %10, i32 0, i32 0
  %75 = load i32, ptr %74, align 8, !tbaa !19
  %76 = load i32, ptr %6, align 4, !tbaa !16
  %77 = sub nsw i32 %76, 1
  %78 = mul nsw i32 %75, %77
  %79 = add nsw i32 %73, %78
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds i64, ptr %72, i64 %80
  %82 = load i64, ptr %81, align 8, !tbaa !14
  %83 = load i64, ptr %8, align 8, !tbaa !14
  %84 = add nsw i64 %82, %83
  %85 = getelementptr inbounds %class.imageIntegral, ptr %10, i32 0, i32 2
  %86 = load ptr, ptr %85, align 8, !tbaa !11
  %87 = load i32, ptr %9, align 4, !tbaa !16
  %88 = getelementptr inbounds %class.imageIntegral, ptr %10, i32 0, i32 0
  %89 = load i32, ptr %88, align 8, !tbaa !19
  %90 = load i32, ptr %6, align 4, !tbaa !16
  %91 = mul nsw i32 %89, %90
  %92 = add nsw i32 %87, %91
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds i64, ptr %86, i64 %93
  store i64 %84, ptr %94, align 8, !tbaa !14
  br label %95

95:                                               ; preds = %61
  %96 = load i32, ptr %9, align 4, !tbaa !16
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %9, align 4, !tbaa !16
  br label %55, !llvm.loop !20

98:                                               ; preds = %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %99

99:                                               ; preds = %98
  %100 = load i32, ptr %6, align 4, !tbaa !16
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr %6, align 4, !tbaa !16
  br label %48, !llvm.loop !21

102:                                              ; preds = %53
  ret void
}

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 = { 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 = { 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 = !{!"double", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTS13imageIntegral", !13, i64 0, !13, i64 4, !6, i64 8, !13, i64 16}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!13, !13, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!12, !13, i64 0}
!20 = distinct !{!20, !18}
!21 = distinct !{!21, !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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN5imageclEii(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5image8getWidthEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5image9getHeightEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN13imageIntegral20computeIntegralImageEP5image(ptr nocapture noundef nonnull readonly align 8 dereferenceable(20) %0, ptr noundef nonnull %1) local_unnamed_addr #1 align 2 {
  %3 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN5imageclEii(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef 0, i32 noundef 0)
  %4 = load double, ptr %3, align 8, !tbaa !5
  %5 = fptosi double %4 to i64
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  store i64 %5, ptr %7, align 8, !tbaa !13
  %8 = tail call noundef i32 @_ZN5image8getWidthEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  %9 = icmp sgt i32 %8, 1
  br i1 %9, label %.lr.ph, label %.preheader26

.preheader26:                                     ; preds = %.lr.ph, %2
  %10 = tail call noundef i32 @_ZN5image9getHeightEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  %11 = icmp sgt i32 %10, 1
  br i1 %11, label %.preheader, label %._crit_edge32

.lr.ph:                                           ; preds = %2, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %2 ]
  %12 = load ptr, ptr %6, align 8, !tbaa !9
  %13 = getelementptr i64, ptr %12, i64 %indvars.iv
  %14 = getelementptr i8, ptr %13, i64 -8
  %15 = load i64, ptr %14, align 8, !tbaa !13
  %16 = sitofp i64 %15 to double
  %17 = trunc nuw nsw i64 %indvars.iv to i32
  %18 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN5imageclEii(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %17, i32 noundef 0)
  %19 = load double, ptr %18, align 8, !tbaa !5
  %20 = fadd double %19, %16
  %21 = fptosi double %20 to i64
  %22 = load ptr, ptr %6, align 8, !tbaa !9
  %23 = getelementptr inbounds i64, ptr %22, i64 %indvars.iv
  store i64 %21, ptr %23, align 8, !tbaa !13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %24 = tail call noundef i32 @_ZN5image8getWidthEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  %25 = sext i32 %24 to i64
  %26 = icmp slt i64 %indvars.iv.next, %25
  br i1 %26, label %.lr.ph, label %.preheader26, !llvm.loop !15

.preheader:                                       ; preds = %.preheader26, %._crit_edge
  %.02431 = phi i32 [ %30, %._crit_edge ], [ 1, %.preheader26 ]
  %27 = tail call noundef i32 @_ZN5image8getWidthEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %.lr.ph30, label %._crit_edge

.lr.ph30:                                         ; preds = %.preheader
  %29 = add nsw i32 %.02431, -1
  br label %33

._crit_edge32:                                    ; preds = %._crit_edge, %.preheader26
  ret void

._crit_edge:                                      ; preds = %33, %.preheader
  %30 = add nuw nsw i32 %.02431, 1
  %31 = tail call noundef i32 @_ZN5image9getHeightEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %.preheader, label %._crit_edge32, !llvm.loop !17

33:                                               ; preds = %.lr.ph30, %33
  %.029 = phi i32 [ 0, %.lr.ph30 ], [ %51, %33 ]
  %.02328 = phi i64 [ 0, %.lr.ph30 ], [ %38, %33 ]
  %34 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN5imageclEii(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %.029, i32 noundef %.02431)
  %35 = load double, ptr %34, align 8, !tbaa !5
  %36 = sitofp i64 %.02328 to double
  %37 = fadd double %35, %36
  %38 = fptosi double %37 to i64
  %39 = load ptr, ptr %6, align 8, !tbaa !9
  %40 = load i32, ptr %0, align 8, !tbaa !18
  %41 = mul nsw i32 %40, %29
  %42 = add nsw i32 %41, %.029
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i64, ptr %39, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !13
  %46 = add nsw i64 %45, %38
  %47 = mul nsw i32 %40, %.02431
  %48 = add nsw i32 %47, %.029
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i64, ptr %39, i64 %49
  store i64 %46, ptr %50, align 8, !tbaa !13
  %51 = add nuw nsw i32 %.029, 1
  %52 = tail call noundef i32 @_ZN5image8getWidthEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  %53 = icmp slt i32 %51, %52
  br i1 %53, label %33, label %._crit_edge, !llvm.loop !19
}

attributes #0 = { 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 #1 = { 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" }

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !12, i64 8}
!10 = !{!"_ZTS13imageIntegral", !11, i64 0, !11, i64 4, !12, i64 8, !11, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = !{!10, !11, i64 0}
!19 = distinct !{!19, !16}


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