; LLVM IR from InsightSoftwareConsortium/ITK :: Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmrle/rle.ll (ZN3rle11rle_decoderD2Ev)

; 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.rle::rle_decoder" = type { ptr }
%"struct.rle::rle_decoder::internal" = type { %"class.rle::image_info", %"struct.rle::header", ptr, i32, %"class.std::vector", [16 x [128 x i8]], [16 x i32] }
%"class.rle::image_info" = type { i32, i32, %"class.rle::pixel_info", i8, i8 }
%"class.rle::pixel_info" = type { i8, i8 }
%"struct.rle::header" = type { i32, [15 x i32] }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<char, std::allocator<char>>::_Vector_impl" }
%"struct.std::_Vector_base<char, std::allocator<char>>::_Vector_impl" = type { %"struct.std::_Vector_base<char, std::allocator<char>>::_Vector_impl_data" }
%"struct.std::_Vector_base<char, std::allocator<char>>::_Vector_impl_data" = type { ptr, ptr, ptr }

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

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3rle11rle_decoderD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %0) unnamed_addr #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %5

5:                                                ; preds = %28, %1
  %6 = load i32, ptr %3, align 4, !tbaa !9
  %7 = getelementptr inbounds %"class.rle::rle_decoder", ptr %4, i32 0, i32 0
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = getelementptr inbounds %"struct.rle::rle_decoder::internal", ptr %8, i32 0, i32 3
  %10 = load i32, ptr %9, align 8, !tbaa !13
  %11 = icmp slt i32 %6, %10
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %5
  %14 = getelementptr inbounds %"class.rle::rle_decoder", ptr %4, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = getelementptr inbounds %"struct.rle::rle_decoder::internal", ptr %15, i32 0, i32 2
  %17 = load ptr, ptr %16, align 8, !tbaa !23
  %18 = load i32, ptr %3, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds ptr, ptr %17, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = icmp eq ptr %21, null
  br i1 %22, label %27, label %23

23:                                               ; preds = %13
  %24 = load ptr, ptr %21, align 8, !tbaa !24
  %25 = getelementptr inbounds ptr, ptr %24, i64 6
  %26 = load ptr, ptr %25, align 8
  call void %26(ptr noundef nonnull align 8 dereferenceable(8) %21) #4
  br label %27

27:                                               ; preds = %23, %13
  br label %28

28:                                               ; preds = %27
  %29 = load i32, ptr %3, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %3, align 4, !tbaa !9
  br label %5, !llvm.loop !26

31:                                               ; preds = %12
  %32 = getelementptr inbounds %"class.rle::rle_decoder", ptr %4, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %34 = getelementptr inbounds %"struct.rle::rle_decoder::internal", ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !23
  %36 = icmp eq ptr %35, null
  br i1 %36, label %38, label %37

37:                                               ; preds = %31
  call void @_ZdaPv(ptr noundef %35) #5
  br label %38

38:                                               ; preds = %37, %31
  %39 = getelementptr inbounds %"class.rle::rle_decoder", ptr %4, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  %41 = icmp eq ptr %40, null
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  call void @_ZN3rle11rle_decoder8internalD2Ev(ptr noundef nonnull align 8 dereferenceable(2232) %40) #4
  call void @_ZdlPvm(ptr noundef %40, i64 noundef 2232) #5
  br label %43

43:                                               ; preds = %42, %38
  ret void
}

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3rle11rle_decoder8internalD2Ev(ptr noundef nonnull align 8 dereferenceable(2232)) unnamed_addr #3 align 2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }
attributes #5 = { 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, !6, i64 0}
!12 = !{!"_ZTSN3rle11rle_decoderE", !6, i64 0}
!13 = !{!14, !10, i64 88}
!14 = !{!"_ZTSN3rle11rle_decoder8internalE", !15, i64 0, !18, i64 12, !6, i64 80, !10, i64 88, !19, i64 96, !7, i64 120, !7, i64 2168}
!15 = !{!"_ZTSN3rle10image_infoE", !10, i64 0, !10, i64 4, !16, i64 8, !17, i64 10, !17, i64 11}
!16 = !{!"_ZTSN3rle10pixel_infoE", !7, i64 0, !7, i64 1}
!17 = !{!"bool", !7, i64 0}
!18 = !{!"_ZTSN3rle6headerE", !10, i64 0, !7, i64 4}
!19 = !{!"_ZTSSt6vectorIcSaIcEE", !20, i64 0}
!20 = !{!"_ZTSSt12_Vector_baseIcSaIcEE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseIcSaIcEE12_Vector_implE", !22, i64 0}
!22 = !{!"_ZTSNSt12_Vector_baseIcSaIcEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!23 = !{!14, !6, i64 80}
!24 = !{!25, !25, i64 0}
!25 = !{!"vtable pointer", !8, i64 0}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}


; 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 nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3rle11rle_decoderD2Ev(ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %0) unnamed_addr #1 align 2 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 88
  %4 = load i32, ptr %3, align 8, !tbaa !10
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %19, %1
  %.lcssa = phi ptr [ %2, %1 ], [ %20, %19 ]
  %6 = getelementptr inbounds i8, ptr %.lcssa, i64 80
  %7 = load ptr, ptr %6, align 8, !tbaa !21
  %8 = icmp eq ptr %7, null
  br i1 %8, label %.thread, label %25

.lr.ph:                                           ; preds = %1, %19
  %9 = phi ptr [ %20, %19 ], [ %2, %1 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %19 ], [ 0, %1 ]
  %10 = getelementptr inbounds i8, ptr %9, i64 80
  %11 = load ptr, ptr %10, align 8, !tbaa !21
  %12 = getelementptr inbounds ptr, ptr %11, i64 %indvars.iv
  %13 = load ptr, ptr %12, align 8, !tbaa !22
  %14 = icmp eq ptr %13, null
  br i1 %14, label %19, label %15

15:                                               ; preds = %.lr.ph
  %16 = load ptr, ptr %13, align 8, !tbaa !23
  %17 = getelementptr inbounds i8, ptr %16, i64 48
  %18 = load ptr, ptr %17, align 8
  tail call void %18(ptr noundef nonnull align 8 dereferenceable(8) %13) #3
  %.pre = load ptr, ptr %0, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %.lr.ph, %15
  %20 = phi ptr [ %9, %.lr.ph ], [ %.pre, %15 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = getelementptr inbounds i8, ptr %20, i64 88
  %22 = load i32, ptr %21, align 8, !tbaa !10
  %23 = sext i32 %22 to i64
  %24 = icmp slt i64 %indvars.iv.next, %23
  br i1 %24, label %.lr.ph, label %._crit_edge, !llvm.loop !25

25:                                               ; preds = %._crit_edge
  tail call void @_ZdaPv(ptr noundef nonnull %7) #4
  %.pre9 = load ptr, ptr %0, align 8, !tbaa !5
  %26 = icmp eq ptr %.pre9, null
  br i1 %26, label %28, label %.thread

.thread:                                          ; preds = %._crit_edge, %25
  %27 = phi ptr [ %.pre9, %25 ], [ %.lcssa, %._crit_edge ]
  tail call void @_ZN3rle11rle_decoder8internalD2Ev(ptr noundef nonnull align 8 dereferenceable(2232) %27) #3
  tail call void @_ZdlPvm(ptr noundef nonnull %27, i64 noundef 2232) #4
  br label %28

28:                                               ; preds = %.thread, %25
  ret void
}

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3rle11rle_decoder8internalD2Ev(ptr noundef nonnull align 8 dereferenceable(2232)) unnamed_addr #2 align 2

attributes #0 = { 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 #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 = { 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 #3 = { nounwind }
attributes #4 = { 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 = !{!"_ZTSN3rle11rle_decoderE", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !13, i64 88}
!11 = !{!"_ZTSN3rle11rle_decoder8internalE", !12, i64 0, !16, i64 12, !7, i64 80, !13, i64 88, !17, i64 96, !8, i64 120, !8, i64 2168}
!12 = !{!"_ZTSN3rle10image_infoE", !13, i64 0, !13, i64 4, !14, i64 8, !15, i64 10, !15, i64 11}
!13 = !{!"int", !8, i64 0}
!14 = !{!"_ZTSN3rle10pixel_infoE", !8, i64 0, !8, i64 1}
!15 = !{!"bool", !8, i64 0}
!16 = !{!"_ZTSN3rle6headerE", !13, i64 0, !8, i64 4}
!17 = !{!"_ZTSSt6vectorIcSaIcEE", !18, i64 0}
!18 = !{!"_ZTSSt12_Vector_baseIcSaIcEE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseIcSaIcEE12_Vector_implE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseIcSaIcEE17_Vector_impl_dataE", !7, i64 0, !7, i64 8, !7, i64 16}
!21 = !{!11, !7, i64 80}
!22 = !{!7, !7, i64 0}
!23 = !{!24, !24, i64 0}
!24 = !{!"vtable pointer", !9, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


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