; LLVM IR from liaojing/MorphLib :: Pyramids/image.ll (ZN5image5storeEPhRKNS_4rgbaIfEE)

; 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::rgba" = type { ptr, ptr, ptr, ptr, i32, i32 }

@_ZL5clamp = external hidden global { ptr }, align 8

; 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: mustprogress uwtable
define dso_local noundef i32 @_ZN5image5storeEPhRKNS_4rgbaIfEE(ptr noundef %0, ptr noundef nonnull align 8 dereferenceable(40) %1) #1 {
  %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 i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca float, align 4
  %12 = alloca float, align 4
  %13 = alloca float, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call noundef i32 @_ZNK5image4rgbaIfE6heightEv(ptr noundef nonnull align 8 dereferenceable(40) %14)
  store i32 %15, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call noundef i32 @_ZNK5image4rgbaIfE5widthEv(ptr noundef nonnull align 8 dereferenceable(40) %16)
  store i32 %17, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = sub nsw i32 %18, 1
  store i32 %19, ptr %7, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %94, %2
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = icmp sge i32 %21, 0
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %97

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

25:                                               ; preds = %90, %24
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %93

30:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = mul nsw i32 %31, %32
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = add nsw i32 %33, %34
  store i32 %35, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %"class.image::rgba", ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds float, ptr %38, i64 %40
  %42 = load float, ptr %41, align 4, !tbaa !13
  %43 = call noundef float @_ZNK9extension5clampclEf(ptr noundef nonnull align 8 dereferenceable(8) @_ZL5clamp, float noundef %42)
  %44 = call noundef float @_ZN5colorL9srgbcurveEf(float noundef %43)
  store float %44, ptr %11, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %"class.image::rgba", ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !15
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds float, ptr %47, i64 %49
  %51 = load float, ptr %50, align 4, !tbaa !13
  %52 = call noundef float @_ZNK9extension5clampclEf(ptr noundef nonnull align 8 dereferenceable(8) @_ZL5clamp, float noundef %51)
  %53 = call noundef float @_ZN5colorL9srgbcurveEf(float noundef %52)
  store float %53, ptr %12, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %"class.image::rgba", ptr %54, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  %57 = load i32, ptr %10, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds float, ptr %56, i64 %58
  %60 = load float, ptr %59, align 4, !tbaa !13
  %61 = call noundef float @_ZNK9extension5clampclEf(ptr noundef nonnull align 8 dereferenceable(8) @_ZL5clamp, float noundef %60)
  %62 = call noundef float @_ZN5colorL9srgbcurveEf(float noundef %61)
  store float %62, ptr %13, align 4, !tbaa !13
  %63 = load float, ptr %13, align 4, !tbaa !13
  %64 = fmul float 2.550000e+02, %63
  %65 = fptoui float %64 to i8
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = load i32, ptr %10, align 4, !tbaa !9
  %68 = mul nsw i32 %67, 3
  %69 = add nsw i32 %68, 0
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds i8, ptr %66, i64 %70
  store i8 %65, ptr %71, align 1, !tbaa !17
  %72 = load float, ptr %12, align 4, !tbaa !13
  %73 = fmul float 2.550000e+02, %72
  %74 = fptoui float %73 to i8
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = mul nsw i32 %76, 3
  %78 = add nsw i32 %77, 1
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds i8, ptr %75, i64 %79
  store i8 %74, ptr %80, align 1, !tbaa !17
  %81 = load float, ptr %11, align 4, !tbaa !13
  %82 = fmul float 2.550000e+02, %81
  %83 = fptoui float %82 to i8
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = load i32, ptr %10, align 4, !tbaa !9
  %86 = mul nsw i32 %85, 3
  %87 = add nsw i32 %86, 2
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds i8, ptr %84, i64 %88
  store i8 %83, ptr %89, align 1, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %90

90:                                               ; preds = %30
  %91 = load i32, ptr %9, align 4, !tbaa !9
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %9, align 4, !tbaa !9
  br label %25, !llvm.loop !18

93:                                               ; preds = %29
  br label %94

94:                                               ; preds = %93
  %95 = load i32, ptr %7, align 4, !tbaa !9
  %96 = add nsw i32 %95, -1
  store i32 %96, ptr %7, align 4, !tbaa !9
  br label %20, !llvm.loop !20

97:                                               ; preds = %23
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret i32 1
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK5image4rgbaIfE6heightEv(ptr noundef nonnull align 8 dereferenceable(40)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK5image4rgbaIfE5widthEv(ptr noundef nonnull align 8 dereferenceable(40)) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef float @_ZN5colorL9srgbcurveEf(float noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK9extension5clampclEf(ptr noundef nonnull align 8 dereferenceable(8), float noundef) unnamed_addr #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = { 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, !6, i64 0}
!12 = !{!"_ZTSN5image4rgbaIfEE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = !{!12, !6, i64 8}
!16 = !{!12, !6, i64 16}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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

@_ZL5clamp = external hidden global { ptr }, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN5image5storeEPhRKNS_4rgbaIfEE(ptr nocapture noundef writeonly %0, ptr noundef nonnull align 8 dereferenceable(40) %1) local_unnamed_addr #0 {
  %3 = tail call noundef i32 @_ZNK5image4rgbaIfE6heightEv(ptr noundef nonnull align 8 dereferenceable(40) %1)
  %4 = tail call noundef i32 @_ZNK5image4rgbaIfE5widthEv(ptr noundef nonnull align 8 dereferenceable(40) %1)
  %5 = icmp sgt i32 %3, 0
  br i1 %5, label %.preheader.lr.ph, label %._crit_edge

.preheader.lr.ph:                                 ; preds = %2
  %6 = icmp sgt i32 %4, 0
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = getelementptr inbounds i8, ptr %1, i64 16
  br i1 %6, label %.preheader.us.preheader, label %._crit_edge

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %9 = zext nneg i32 %3 to i64
  %10 = zext nneg i32 %4 to i64
  %wide.trip.count = zext nneg i32 %4 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %..loopexit_crit_edge.us
  %indvars.iv32.in = phi i64 [ %9, %.preheader.us.preheader ], [ %indvars.iv32, %..loopexit_crit_edge.us ]
  %indvars.iv32 = add nsw i64 %indvars.iv32.in, -1
  %11 = mul nsw i64 %indvars.iv32, %10
  br label %12

12:                                               ; preds = %.preheader.us, %12
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %12 ]
  %13 = add nsw i64 %indvars.iv, %11
  %14 = load ptr, ptr %1, align 8, !tbaa !5
  %15 = getelementptr inbounds float, ptr %14, i64 %13
  %16 = load float, ptr %15, align 4, !tbaa !11
  %17 = tail call noundef float @_ZNK9extension5clampclEf(ptr noundef nonnull align 8 dereferenceable(8) @_ZL5clamp, float noundef %16)
  %18 = tail call noundef float @_ZN5colorL9srgbcurveEf(float noundef %17)
  %19 = load ptr, ptr %7, align 8, !tbaa !13
  %20 = getelementptr inbounds float, ptr %19, i64 %13
  %21 = load float, ptr %20, align 4, !tbaa !11
  %22 = tail call noundef float @_ZNK9extension5clampclEf(ptr noundef nonnull align 8 dereferenceable(8) @_ZL5clamp, float noundef %21)
  %23 = tail call noundef float @_ZN5colorL9srgbcurveEf(float noundef %22)
  %24 = load ptr, ptr %8, align 8, !tbaa !14
  %25 = getelementptr inbounds float, ptr %24, i64 %13
  %26 = load float, ptr %25, align 4, !tbaa !11
  %27 = tail call noundef float @_ZNK9extension5clampclEf(ptr noundef nonnull align 8 dereferenceable(8) @_ZL5clamp, float noundef %26)
  %28 = tail call noundef float @_ZN5colorL9srgbcurveEf(float noundef %27)
  %29 = fmul float %28, 2.550000e+02
  %30 = fptoui float %29 to i8
  %31 = mul nsw i64 %13, 3
  %32 = getelementptr inbounds i8, ptr %0, i64 %31
  store i8 %30, ptr %32, align 1, !tbaa !15
  %33 = fmul float %23, 2.550000e+02
  %34 = fptoui float %33 to i8
  %35 = getelementptr i8, ptr %32, i64 1
  store i8 %34, ptr %35, align 1, !tbaa !15
  %36 = fmul float %18, 2.550000e+02
  %37 = fptoui float %36 to i8
  %38 = getelementptr i8, ptr %32, i64 2
  store i8 %37, ptr %38, align 1, !tbaa !15
  %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 %..loopexit_crit_edge.us, label %12, !llvm.loop !16

..loopexit_crit_edge.us:                          ; preds = %12
  %39 = icmp sgt i64 %indvars.iv32.in, 1
  br i1 %39, label %.preheader.us, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %..loopexit_crit_edge.us, %.preheader.lr.ph, %2
  ret i32 1
}

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef float @_ZN5colorL9srgbcurveEf(float noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK9extension5clampclEf(ptr noundef nonnull align 8 dereferenceable(8), float noundef) unnamed_addr #0 align 2

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

!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 = !{!"_ZTSN5image4rgbaIfEE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 36}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !8, i64 0}
!13 = !{!6, !7, i64 8}
!14 = !{!6, !7, i64 16}
!15 = !{!8, !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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