; LLVM IR from liaojing/MorphLib :: Pyramids/image.ll (ZN5image4loadEiiPhPNS_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 }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5image4loadEiiPhPNS_4rgbaIfEE(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca float, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !9
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %108

17:                                               ; preds = %4
  %18 = load i32, ptr %7, align 4, !tbaa !5
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %108

20:                                               ; preds = %17
  %21 = load ptr, ptr %9, align 8, !tbaa !9
  %22 = load i32, ptr %7, align 4, !tbaa !5
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = call noundef i32 @_ZN5image4rgbaIfE6resizeEii(ptr noundef nonnull align 8 dereferenceable(40) %21, i32 noundef %22, i32 noundef %23)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store float 0x3F70101020000000, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = sub nsw i32 %25, 1
  store i32 %26, ptr %11, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %104, %20
  %28 = load i32, ptr %11, align 4, !tbaa !5
  %29 = icmp sge i32 %28, 0
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %107

31:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %100, %31
  %33 = load i32, ptr %13, align 4, !tbaa !5
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %32
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %103

37:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %38 = load i32, ptr %11, align 4, !tbaa !5
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = mul nsw i32 %38, %39
  %41 = load i32, ptr %13, align 4, !tbaa !5
  %42 = add nsw i32 %40, %41
  store i32 %42, ptr %14, align 4, !tbaa !5
  %43 = load ptr, ptr %8, align 8, !tbaa !9
  %44 = load i32, ptr %14, align 4, !tbaa !5
  %45 = mul nsw i32 %44, 3
  %46 = add nsw i32 %45, 0
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i8, ptr %43, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !13
  %50 = zext i8 %49 to i32
  %51 = sitofp i32 %50 to float
  %52 = fmul float %51, 0x3F70101020000000
  %53 = call noundef float @_ZN5colorL11srgbuncurveEf(float noundef %52)
  %54 = load ptr, ptr %9, align 8, !tbaa !9
  %55 = getelementptr inbounds %"class.image::rgba", ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !14
  %57 = load i32, ptr %14, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds float, ptr %56, i64 %58
  store float %53, ptr %59, align 4, !tbaa !11
  %60 = load ptr, ptr %8, align 8, !tbaa !9
  %61 = load i32, ptr %14, align 4, !tbaa !5
  %62 = mul nsw i32 %61, 3
  %63 = add nsw i32 %62, 1
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds i8, ptr %60, i64 %64
  %66 = load i8, ptr %65, align 1, !tbaa !13
  %67 = zext i8 %66 to i32
  %68 = sitofp i32 %67 to float
  %69 = fmul float %68, 0x3F70101020000000
  %70 = call noundef float @_ZN5colorL11srgbuncurveEf(float noundef %69)
  %71 = load ptr, ptr %9, align 8, !tbaa !9
  %72 = getelementptr inbounds %"class.image::rgba", ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !16
  %74 = load i32, ptr %14, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds float, ptr %73, i64 %75
  store float %70, ptr %76, align 4, !tbaa !11
  %77 = load ptr, ptr %8, align 8, !tbaa !9
  %78 = load i32, ptr %14, align 4, !tbaa !5
  %79 = mul nsw i32 %78, 3
  %80 = add nsw i32 %79, 2
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds i8, ptr %77, i64 %81
  %83 = load i8, ptr %82, align 1, !tbaa !13
  %84 = zext i8 %83 to i32
  %85 = sitofp i32 %84 to float
  %86 = fmul float %85, 0x3F70101020000000
  %87 = call noundef float @_ZN5colorL11srgbuncurveEf(float noundef %86)
  %88 = load ptr, ptr %9, align 8, !tbaa !9
  %89 = getelementptr inbounds %"class.image::rgba", ptr %88, i32 0, i32 2
  %90 = load ptr, ptr %89, align 8, !tbaa !17
  %91 = load i32, ptr %14, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds float, ptr %90, i64 %92
  store float %87, ptr %93, align 4, !tbaa !11
  %94 = load ptr, ptr %9, align 8, !tbaa !9
  %95 = getelementptr inbounds %"class.image::rgba", ptr %94, i32 0, i32 3
  %96 = load ptr, ptr %95, align 8, !tbaa !18
  %97 = load i32, ptr %14, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds float, ptr %96, i64 %98
  store float 1.000000e+00, ptr %99, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %100

100:                                              ; preds = %37
  %101 = load i32, ptr %13, align 4, !tbaa !5
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %13, align 4, !tbaa !5
  br label %32, !llvm.loop !19

103:                                              ; preds = %36
  br label %104

104:                                              ; preds = %103
  %105 = load i32, ptr %11, align 4, !tbaa !5
  %106 = add nsw i32 %105, -1
  store i32 %106, ptr %11, align 4, !tbaa !5
  br label %27, !llvm.loop !21

107:                                              ; preds = %30
  store i32 1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %109

108:                                              ; preds = %17, %4
  store i32 0, ptr %5, align 4
  br label %109

109:                                              ; preds = %108, %107
  %110 = load i32, ptr %5, align 4
  ret i32 %110
}

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

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

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

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

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


; 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: mustprogress nounwind uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN5image4loadEiiPhPNS_4rgbaIfEE(i32 noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = icmp ne i32 %0, 0
  %6 = icmp ne i32 %1, 0
  %or.cond = and i1 %5, %6
  br i1 %or.cond, label %7, label %.loopexit33

7:                                                ; preds = %4
  %8 = tail call noundef i32 @_ZN5image4rgbaIfE6resizeEii(ptr noundef nonnull align 8 dereferenceable(40) %3, i32 noundef %1, i32 noundef %0)
  %9 = icmp sgt i32 %1, 0
  br i1 %9, label %.preheader.lr.ph, label %.loopexit33

.preheader.lr.ph:                                 ; preds = %7
  %10 = icmp sgt i32 %0, 0
  %11 = getelementptr inbounds i8, ptr %3, i64 8
  %12 = getelementptr inbounds i8, ptr %3, i64 16
  %13 = getelementptr inbounds i8, ptr %3, i64 24
  br i1 %10, label %.preheader.us.preheader, label %.loopexit33

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %14 = zext nneg i32 %1 to i64
  %15 = zext nneg i32 %0 to i64
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %..loopexit_crit_edge.us
  %indvars.iv39.in = phi i64 [ %14, %.preheader.us.preheader ], [ %indvars.iv39, %..loopexit_crit_edge.us ]
  %indvars.iv39 = add nsw i64 %indvars.iv39.in, -1
  %16 = mul nsw i64 %indvars.iv39, %15
  br label %17

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

..loopexit_crit_edge.us:                          ; preds = %17
  %43 = icmp sgt i64 %indvars.iv39.in, 1
  br i1 %43, label %.preheader.us, label %.loopexit33, !llvm.loop !19

.loopexit33:                                      ; preds = %..loopexit_crit_edge.us, %.preheader.lr.ph, %7, %4
  %.0 = phi i32 [ 0, %4 ], [ 1, %7 ], [ 1, %.preheader.lr.ph ], [ 1, %..loopexit_crit_edge.us ]
  ret i32 %.0
}

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

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

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


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