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

; 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 speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #0

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5image8getWidthEv(ptr noundef nonnull align 8 dereferenceable(16)) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN5image8padImageEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #4 align 2

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #5

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN13imageIntegralC2EP5image(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr noundef %1) unnamed_addr #4 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %class.imageIntegral, ptr %6, i32 0, i32 3
  store i32 312, ptr %7, align 8, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call noundef i32 @_ZN5image8getWidthEv(ptr noundef nonnull align 8 dereferenceable(16) %8)
  %10 = getelementptr inbounds %class.imageIntegral, ptr %6, i32 0, i32 3
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = mul nsw i32 2, %11
  %13 = add nsw i32 %9, %12
  %14 = getelementptr inbounds %class.imageIntegral, ptr %6, i32 0, i32 0
  store i32 %13, ptr %14, align 8, !tbaa !12
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = call noundef i32 @_ZN5image9getHeightEv(ptr noundef nonnull align 8 dereferenceable(16) %15)
  %17 = getelementptr inbounds %class.imageIntegral, ptr %6, i32 0, i32 3
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %19 = mul nsw i32 2, %18
  %20 = add nsw i32 %16, %19
  %21 = getelementptr inbounds %class.imageIntegral, ptr %6, i32 0, i32 1
  store i32 %20, ptr %21, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %class.imageIntegral, ptr %6, i32 0, i32 3
  %24 = load i32, ptr %23, align 8, !tbaa !9
  %25 = call noundef ptr @_ZN5image8padImageEi(ptr noundef nonnull align 8 dereferenceable(16) %22, i32 noundef %24)
  store ptr %25, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %class.imageIntegral, ptr %6, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !12
  %28 = getelementptr inbounds %class.imageIntegral, ptr %6, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !13
  %30 = mul nsw i32 %27, %29
  %31 = sext i32 %30 to i64
  %32 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %31, i64 8)
  %33 = extractvalue { i64, i1 } %32, 1
  %34 = extractvalue { i64, i1 } %32, 0
  %35 = select i1 %33, i64 -1, i64 %34
  %36 = call noalias noundef nonnull ptr @_Znam(i64 noundef %35) #8
  %37 = getelementptr inbounds %class.imageIntegral, ptr %6, i32 0, i32 2
  store ptr %36, ptr %37, align 8, !tbaa !14
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN13imageIntegral20computeIntegralImageEP5image(ptr noundef nonnull align 8 dereferenceable(20) %6, ptr noundef %38)
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = icmp eq ptr %39, null
  br i1 %40, label %42, label %41

41:                                               ; preds = %2
  call void @_ZN5imageD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %39) #7
  call void @_ZdlPvm(ptr noundef %39, i64 noundef 16) #9
  br label %42

42:                                               ; preds = %41, %2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN13imageIntegral20computeIntegralImageEP5image(ptr noundef nonnull align 8 dereferenceable(20), ptr noundef) #4 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5imageD2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #6 align 2

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nobuiltin allocsize(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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #5 = { nobuiltin 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 #6 = { 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 #7 = { nounwind }
attributes #8 = { builtin allocsize(0) }
attributes #9 = { builtin 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, !11, i64 16}
!10 = !{!"_ZTS13imageIntegral", !11, i64 0, !11, i64 4, !6, i64 8, !11, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!10, !11, i64 4}
!14 = !{!10, !6, i64 8}


; 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN5image8padImageEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #2 align 2

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN13imageIntegralC2EP5image(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr noundef nonnull %1) unnamed_addr #2 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 312, ptr %3, align 8, !tbaa !5
  %4 = tail call noundef i32 @_ZN5image8getWidthEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  %5 = load i32, ptr %3, align 8, !tbaa !5
  %6 = shl nsw i32 %5, 1
  %7 = add nsw i32 %6, %4
  store i32 %7, ptr %0, align 8, !tbaa !11
  %8 = tail call noundef i32 @_ZN5image9getHeightEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  %9 = load i32, ptr %3, align 8, !tbaa !5
  %10 = shl nsw i32 %9, 1
  %11 = add nsw i32 %10, %8
  %12 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %11, ptr %12, align 4, !tbaa !12
  %13 = tail call noundef ptr @_ZN5image8padImageEi(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %9)
  %14 = load i32, ptr %0, align 8, !tbaa !11
  %15 = load i32, ptr %12, align 4, !tbaa !12
  %16 = mul nsw i32 %15, %14
  %17 = sext i32 %16 to i64
  %18 = icmp slt i32 %16, 0
  %19 = shl nsw i64 %17, 3
  %20 = select i1 %18, i64 -1, i64 %19
  %21 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %20) #5
  %22 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %21, ptr %22, align 8, !tbaa !13
  tail call void @_ZN13imageIntegral20computeIntegralImageEP5image(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr noundef %13)
  %23 = icmp eq ptr %13, null
  br i1 %23, label %25, label %24

24:                                               ; preds = %2
  tail call void @_ZN5imageD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %13) #6
  tail call void @_ZdlPvm(ptr noundef nonnull %13, i64 noundef 16) #7
  br label %25

25:                                               ; preds = %24, %2
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN13imageIntegral20computeIntegralImageEP5image(ptr noundef nonnull align 8 dereferenceable(20), ptr noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5imageD2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #4 align 2

attributes #0 = { nobuiltin allocsize(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 = { 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 = { nobuiltin 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 = { 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 #5 = { builtin allocsize(0) }
attributes #6 = { nounwind }
attributes #7 = { builtin 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, !7, i64 16}
!6 = !{!"_ZTS13imageIntegral", !7, i64 0, !7, i64 4, !10, i64 8, !7, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 4}
!13 = !{!6, !10, i64 8}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass