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

; 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.image = type { i32, i32, ptr }

; 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: mustprogress uwtable
define dso_local noundef ptr @_ZN5image8padImageEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1) #2 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %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
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %13 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %14 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 16) #6
  %15 = getelementptr inbounds %class.image, ptr %13, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = mul nsw i32 2, %17
  %19 = add nsw i32 %16, %18
  %20 = getelementptr inbounds %class.image, ptr %13, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !13
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = mul nsw i32 2, %22
  %24 = add nsw i32 %21, %23
  invoke void @_ZN5imageC1Eii(ptr noundef nonnull align 8 dereferenceable(16) %14, i32 noundef %19, i32 noundef %24)
          to label %25 unwind label %36

25:                                               ; preds = %2
  store ptr %14, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = sub nsw i32 0, %26
  store i32 %27, ptr %10, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %116, %25
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = getelementptr inbounds %class.image, ptr %13, i32 0, i32 0
  %31 = load i32, ptr %30, align 8, !tbaa !11
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = add nsw i32 %31, %32
  %34 = icmp slt i32 %29, %33
  br i1 %34, label %40, label %35

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

36:                                               ; preds = %2
  %37 = landingpad { ptr, i32 }
          cleanup
  %38 = extractvalue { ptr, i32 } %37, 0
  store ptr %38, ptr %6, align 8
  %39 = extractvalue { ptr, i32 } %37, 1
  store i32 %39, ptr %7, align 4
  call void @_ZdlPvm(ptr noundef %14, i64 noundef 16) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %121

40:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %41 = load i32, ptr %4, align 4, !tbaa !9
  %42 = sub nsw i32 0, %41
  store i32 %42, ptr %12, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %112, %40
  %44 = load i32, ptr %12, align 4, !tbaa !9
  %45 = getelementptr inbounds %class.image, ptr %13, i32 0, i32 1
  %46 = load i32, ptr %45, align 4, !tbaa !13
  %47 = load i32, ptr %4, align 4, !tbaa !9
  %48 = add nsw i32 %46, %47
  %49 = icmp slt i32 %44, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %43
  store i32 5, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %115

51:                                               ; preds = %43
  %52 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %52, ptr %8, align 4, !tbaa !9
  %53 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %53, ptr %9, align 4, !tbaa !9
  %54 = load i32, ptr %8, align 4, !tbaa !9
  %55 = icmp slt i32 %54, 0
  br i1 %55, label %56, label %59

56:                                               ; preds = %51
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = sub nsw i32 0, %57
  store i32 %58, ptr %8, align 4, !tbaa !9
  br label %59

59:                                               ; preds = %56, %51
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = icmp slt i32 %60, 0
  br i1 %61, label %62, label %65

62:                                               ; preds = %59
  %63 = load i32, ptr %9, align 4, !tbaa !9
  %64 = sub nsw i32 0, %63
  store i32 %64, ptr %9, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %62, %59
  %66 = load i32, ptr %8, align 4, !tbaa !9
  %67 = getelementptr inbounds %class.image, ptr %13, i32 0, i32 0
  %68 = load i32, ptr %67, align 8, !tbaa !11
  %69 = mul nsw i32 2, %68
  %70 = srem i32 %66, %69
  store i32 %70, ptr %8, align 4, !tbaa !9
  %71 = load i32, ptr %9, align 4, !tbaa !9
  %72 = getelementptr inbounds %class.image, ptr %13, i32 0, i32 1
  %73 = load i32, ptr %72, align 4, !tbaa !13
  %74 = mul nsw i32 2, %73
  %75 = srem i32 %71, %74
  store i32 %75, ptr %9, align 4, !tbaa !9
  %76 = load i32, ptr %8, align 4, !tbaa !9
  %77 = getelementptr inbounds %class.image, ptr %13, i32 0, i32 0
  %78 = load i32, ptr %77, align 8, !tbaa !11
  %79 = icmp sge i32 %76, %78
  br i1 %79, label %80, label %87

80:                                               ; preds = %65
  %81 = getelementptr inbounds %class.image, ptr %13, i32 0, i32 0
  %82 = load i32, ptr %81, align 8, !tbaa !11
  %83 = mul nsw i32 2, %82
  %84 = load i32, ptr %8, align 4, !tbaa !9
  %85 = sub nsw i32 %83, %84
  %86 = sub nsw i32 %85, 1
  store i32 %86, ptr %8, align 4, !tbaa !9
  br label %87

87:                                               ; preds = %80, %65
  %88 = load i32, ptr %9, align 4, !tbaa !9
  %89 = getelementptr inbounds %class.image, ptr %13, i32 0, i32 1
  %90 = load i32, ptr %89, align 4, !tbaa !13
  %91 = icmp sge i32 %88, %90
  br i1 %91, label %92, label %99

92:                                               ; preds = %87
  %93 = getelementptr inbounds %class.image, ptr %13, i32 0, i32 1
  %94 = load i32, ptr %93, align 4, !tbaa !13
  %95 = mul nsw i32 2, %94
  %96 = load i32, ptr %9, align 4, !tbaa !9
  %97 = sub nsw i32 %95, %96
  %98 = sub nsw i32 %97, 1
  store i32 %98, ptr %9, align 4, !tbaa !9
  br label %99

99:                                               ; preds = %92, %87
  %100 = load i32, ptr %8, align 4, !tbaa !9
  %101 = load i32, ptr %9, align 4, !tbaa !9
  %102 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN5imageclEii(ptr noundef nonnull align 8 dereferenceable(16) %13, i32 noundef %100, i32 noundef %101)
  %103 = load double, ptr %102, align 8, !tbaa !14
  %104 = load ptr, ptr %5, align 8, !tbaa !5
  %105 = load i32, ptr %10, align 4, !tbaa !9
  %106 = load i32, ptr %4, align 4, !tbaa !9
  %107 = add nsw i32 %105, %106
  %108 = load i32, ptr %12, align 4, !tbaa !9
  %109 = load i32, ptr %4, align 4, !tbaa !9
  %110 = add nsw i32 %108, %109
  %111 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN5imageclEii(ptr noundef nonnull align 8 dereferenceable(16) %104, i32 noundef %107, i32 noundef %110)
  store double %103, ptr %111, align 8, !tbaa !14
  br label %112

112:                                              ; preds = %99
  %113 = load i32, ptr %12, align 4, !tbaa !9
  %114 = add nsw i32 %113, 1
  store i32 %114, ptr %12, align 4, !tbaa !9
  br label %43, !llvm.loop !16

115:                                              ; preds = %50
  br label %116

116:                                              ; preds = %115
  %117 = load i32, ptr %10, align 4, !tbaa !9
  %118 = add nsw i32 %117, 1
  store i32 %118, ptr %10, align 4, !tbaa !9
  br label %28, !llvm.loop !18

119:                                              ; preds = %35
  %120 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret ptr %120

121:                                              ; preds = %36
  %122 = load ptr, ptr %6, align 8
  %123 = load i32, ptr %7, align 4
  %124 = insertvalue { ptr, i32 } poison, ptr %122, 0
  %125 = insertvalue { ptr, i32 } %124, i32 %123, 1
  resume { ptr, i32 } %125
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #3

declare i32 @__gxx_personality_v0(...)

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

declare void @_ZN5imageC1Eii(ptr, i32, i32)

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 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }
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, !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 = !{!12, !10, i64 0}
!12 = !{!"_ZTS5image", !10, i64 0, !10, i64 4, !6, i64 8}
!13 = !{!12, !10, i64 4}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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: mustprogress uwtable
define dso_local noundef nonnull ptr @_ZN5image8padImageEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = tail call noalias noundef nonnull dereferenceable(16) ptr @_Znwm(i64 noundef 16) #5
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %5 = shl nsw i32 %1, 1
  %6 = add nsw i32 %4, %5
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !11
  %9 = add nsw i32 %8, %5
  invoke void @_ZN5imageC1Eii(ptr noundef nonnull align 8 dereferenceable(16) %3, i32 noundef %6, i32 noundef %9)
          to label %10 unwind label %20

10:                                               ; preds = %2
  %11 = sub nsw i32 0, %1
  %12 = load i32, ptr %0, align 8, !tbaa !5
  %13 = add nsw i32 %12, %1
  %14 = icmp sgt i32 %13, %11
  br i1 %14, label %.preheader.preheader, label %._crit_edge44

.preheader.preheader:                             ; preds = %10
  %.pre = load i32, ptr %7, align 4, !tbaa !11
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge
  %15 = phi i32 [ %22, %._crit_edge ], [ %12, %.preheader.preheader ]
  %16 = phi i32 [ %23, %._crit_edge ], [ %.pre, %.preheader.preheader ]
  %.03243 = phi i32 [ %24, %._crit_edge ], [ %11, %.preheader.preheader ]
  %17 = add nsw i32 %16, %1
  %18 = icmp sgt i32 %17, %11
  br i1 %18, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %spec.select = tail call i32 @llvm.abs.i32(i32 %.03243, i1 true)
  %19 = add nsw i32 %.03243, %1
  br label %27

._crit_edge44:                                    ; preds = %._crit_edge, %10
  ret ptr %3

20:                                               ; preds = %2
  %21 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZdlPvm(ptr noundef nonnull %3, i64 noundef 16) #6
  resume { ptr, i32 } %21

._crit_edge.loopexit:                             ; preds = %27
  %.pre45 = load i32, ptr %0, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %22 = phi i32 [ %.pre45, %._crit_edge.loopexit ], [ %15, %.preheader ]
  %23 = phi i32 [ %43, %._crit_edge.loopexit ], [ %16, %.preheader ]
  %24 = add nsw i32 %.03243, 1
  %25 = add nsw i32 %22, %1
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %.preheader, label %._crit_edge44, !llvm.loop !12

27:                                               ; preds = %.lr.ph, %27
  %28 = phi i32 [ %16, %.lr.ph ], [ %43, %27 ]
  %.042 = phi i32 [ %11, %.lr.ph ], [ %42, %27 ]
  %.033 = tail call i32 @llvm.abs.i32(i32 %.042, i1 true)
  %29 = load i32, ptr %0, align 8, !tbaa !5
  %30 = shl nsw i32 %29, 1
  %31 = srem i32 %spec.select, %30
  %32 = shl nsw i32 %28, 1
  %33 = srem i32 %.033, %32
  %.not = icmp slt i32 %31, %29
  %34 = xor i32 %31, -1
  %35 = add i32 %30, %34
  %.135 = select i1 %.not, i32 %31, i32 %35
  %.not41 = icmp slt i32 %33, %28
  %36 = xor i32 %33, -1
  %37 = add i32 %32, %36
  %.1 = select i1 %.not41, i32 %33, i32 %37
  %38 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN5imageclEii(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %.135, i32 noundef %.1)
  %39 = load double, ptr %38, align 8, !tbaa !14
  %40 = add nsw i32 %.042, %1
  %41 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN5imageclEii(ptr noundef nonnull align 8 dereferenceable(16) %3, i32 noundef %19, i32 noundef %40)
  store double %39, ptr %41, align 8, !tbaa !14
  %42 = add nsw i32 %.042, 1
  %43 = load i32, ptr %7, align 4, !tbaa !11
  %44 = add nsw i32 %43, %1
  %45 = icmp slt i32 %42, %44
  br i1 %45, label %27, label %._crit_edge.loopexit, !llvm.loop !16
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #2

declare i32 @__gxx_personality_v0(...)

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

declare void @_ZN5imageC1Eii(ptr, i32, i32) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #4

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 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 = { 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 #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { builtin allocsize(0) }
attributes #6 = { 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 0}
!6 = !{!"_ZTS5image", !7, i64 0, !7, i64 4, !10, i64 8}
!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 4}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !8, i64 0}
!16 = distinct !{!16, !13}


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