; LLVM IR from giacomo-ascari/dichotomic-compression :: src/dc/dc-utils (dc-pixel-matrix)

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

%struct._dc_corners = type { i64, i64, i64, i64 }
%class.dc_pixel_matrix = type { ptr, i64, i64 }
%class.dc_pixel = type { i8, i8, i8 }
%struct._dc_light_sector = type { %class.dc_pixel, i8, i8 }

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

declare noundef i64 @_Z2ixmmm(i64 noundef, i64 noundef, i64 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i8 @_ZN8dc_pixel5get_rEv(ptr noundef nonnull align 1 dereferenceable(3)) #2 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i8 @_ZN8dc_pixel5get_gEv(ptr noundef nonnull align 1 dereferenceable(3)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i8 @_ZN8dc_pixel5get_bEv(ptr noundef nonnull align 1 dereferenceable(3)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN15dc_pixel_matrix13draw_n_occupyER11_dc_cornersPhR16_dc_light_sector11dc_channels(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef %2, ptr noundef nonnull align 1 dereferenceable(5) %3, i32 noundef %4) #3 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store i32 %4, ptr %10, align 4, !tbaa !9
  %15 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._dc_corners, ptr %16, i32 0, i32 1
  %18 = load i64, ptr %17, align 8, !tbaa !11
  store i64 %18, ptr %12, align 8, !tbaa !14
  br label %19

19:                                               ; preds = %76, %5
  %20 = load i64, ptr %12, align 8, !tbaa !14
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._dc_corners, ptr %21, i32 0, i32 3
  %23 = load i64, ptr %22, align 8, !tbaa !15
  %24 = icmp ult i64 %20, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %19
  store i32 2, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %79

26:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._dc_corners, ptr %27, i32 0, i32 0
  %29 = load i64, ptr %28, align 8, !tbaa !16
  store i64 %29, ptr %14, align 8, !tbaa !14
  br label %30

30:                                               ; preds = %72, %26
  %31 = load i64, ptr %14, align 8, !tbaa !14
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._dc_corners, ptr %32, i32 0, i32 2
  %34 = load i64, ptr %33, align 8, !tbaa !17
  %35 = icmp ult i64 %31, %34
  br i1 %35, label %37, label %36

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

37:                                               ; preds = %30
  %38 = load i64, ptr %14, align 8, !tbaa !14
  %39 = load i64, ptr %12, align 8, !tbaa !14
  %40 = getelementptr inbounds %class.dc_pixel_matrix, ptr %15, i32 0, i32 1
  %41 = load i64, ptr %40, align 8, !tbaa !18
  %42 = call noundef i64 @_Z2ixmmm(i64 noundef %38, i64 noundef %39, i64 noundef %41)
  store i64 %42, ptr %11, align 8, !tbaa !14
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = load i64, ptr %11, align 8, !tbaa !14
  %45 = getelementptr inbounds i8, ptr %43, i64 %44
  store i8 1, ptr %45, align 1, !tbaa !20
  %46 = load i32, ptr %10, align 4, !tbaa !9
  %47 = icmp eq i32 %46, 3
  br i1 %47, label %48, label %62

48:                                               ; preds = %37
  %49 = getelementptr inbounds %class.dc_pixel_matrix, ptr %15, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !21
  %51 = load i64, ptr %11, align 8, !tbaa !14
  %52 = getelementptr inbounds %class.dc_pixel, ptr %50, i64 %51
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct._dc_light_sector, ptr %53, i32 0, i32 0
  %55 = call noundef zeroext i8 @_ZN8dc_pixel5get_rEv(ptr noundef nonnull align 1 dereferenceable(3) %54)
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._dc_light_sector, ptr %56, i32 0, i32 0
  %58 = call noundef zeroext i8 @_ZN8dc_pixel5get_gEv(ptr noundef nonnull align 1 dereferenceable(3) %57)
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._dc_light_sector, ptr %59, i32 0, i32 0
  %61 = call noundef zeroext i8 @_ZN8dc_pixel5get_bEv(ptr noundef nonnull align 1 dereferenceable(3) %60)
  call void @_ZN8dc_pixel12set_channelsEhhh(ptr noundef nonnull align 1 dereferenceable(3) %52, i8 noundef zeroext %55, i8 noundef zeroext %58, i8 noundef zeroext %61)
  br label %71

62:                                               ; preds = %37
  %63 = getelementptr inbounds %class.dc_pixel_matrix, ptr %15, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !21
  %65 = load i64, ptr %11, align 8, !tbaa !14
  %66 = getelementptr inbounds %class.dc_pixel, ptr %64, i64 %65
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct._dc_light_sector, ptr %67, i32 0, i32 1
  %69 = load i8, ptr %68, align 1, !tbaa !22
  %70 = load i32, ptr %10, align 4, !tbaa !9
  call void @_ZN8dc_pixel16increase_channelEh11dc_channels(ptr noundef nonnull align 1 dereferenceable(3) %66, i8 noundef zeroext %69, i32 noundef %70)
  br label %71

71:                                               ; preds = %62, %48
  br label %72

72:                                               ; preds = %71
  %73 = load i64, ptr %14, align 8, !tbaa !14
  %74 = add i64 %73, 1
  store i64 %74, ptr %14, align 8, !tbaa !14
  br label %30, !llvm.loop !25

75:                                               ; preds = %36
  br label %76

76:                                               ; preds = %75
  %77 = load i64, ptr %12, align 8, !tbaa !14
  %78 = add i64 %77, 1
  store i64 %78, ptr %12, align 8, !tbaa !14
  br label %19, !llvm.loop !27

79:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  ret void
}

declare void @_ZN8dc_pixel12set_channelsEhhh(ptr noundef nonnull align 1 dereferenceable(3), i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) #1

declare void @_ZN8dc_pixel16increase_channelEh11dc_channels(ptr noundef nonnull align 1 dereferenceable(3), i8 noundef zeroext, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #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 = !{!"_ZTS11dc_channels", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"_ZTS11_dc_corners", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24}
!13 = !{!"long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !13, i64 24}
!16 = !{!12, !13, i64 0}
!17 = !{!12, !13, i64 16}
!18 = !{!19, !13, i64 8}
!19 = !{!"_ZTS15dc_pixel_matrix", !6, i64 0, !13, i64 8, !13, i64 16}
!20 = !{!7, !7, i64 0}
!21 = !{!19, !6, i64 0}
!22 = !{!23, !7, i64 3}
!23 = !{!"_ZTS16_dc_light_sector", !24, i64 0, !7, i64 3, !7, i64 4}
!24 = !{!"_ZTS8dc_pixel", !7, i64 0, !7, i64 1, !7, i64 2}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = distinct !{!27, !26}


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

%class.dc_pixel = type { i8, i8, i8 }

declare noundef i64 @_Z2ixmmm(i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i8 @_ZN8dc_pixel5get_rEv(ptr noundef nonnull align 1 dereferenceable(3)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i8 @_ZN8dc_pixel5get_gEv(ptr noundef nonnull align 1 dereferenceable(3)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i8 @_ZN8dc_pixel5get_bEv(ptr noundef nonnull align 1 dereferenceable(3)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN15dc_pixel_matrix13draw_n_occupyER11_dc_cornersPhR16_dc_light_sector11dc_channels(ptr nocapture noundef nonnull readonly align 8 dereferenceable(24) %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(32) %1, ptr nocapture noundef writeonly %2, ptr noundef nonnull align 1 dereferenceable(5) %3, i32 noundef %4) local_unnamed_addr #2 align 2 {
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %1, i64 24
  %9 = load i64, ptr %8, align 8, !tbaa !10
  %10 = icmp ult i64 %7, %9
  br i1 %10, label %.lr.ph26, label %._crit_edge27

.lr.ph26:                                         ; preds = %5
  %11 = getelementptr inbounds i8, ptr %1, i64 16
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = icmp eq i32 %4, 3
  %14 = getelementptr inbounds i8, ptr %3, i64 3
  %15 = load i64, ptr %1, align 8, !tbaa !11
  %16 = load i64, ptr %11, align 8, !tbaa !12
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %.lr.ph26.split, label %._crit_edge27

._crit_edge27:                                    ; preds = %._crit_edge, %.lr.ph26, %5
  ret void

.lr.ph26.split:                                   ; preds = %.lr.ph26, %._crit_edge
  %18 = phi i64 [ %32, %._crit_edge ], [ %16, %.lr.ph26 ]
  %.02023 = phi i64 [ %33, %._crit_edge ], [ %7, %.lr.ph26 ]
  %19 = load i64, ptr %1, align 8, !tbaa !11
  %20 = icmp ult i64 %19, %18
  br i1 %20, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph26.split
  br i1 %13, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %.lr.ph.split.us
  %.022.us = phi i64 [ %29, %.lr.ph.split.us ], [ %19, %.lr.ph ]
  %21 = load i64, ptr %12, align 8, !tbaa !13
  %22 = tail call noundef i64 @_Z2ixmmm(i64 noundef %.022.us, i64 noundef %.02023, i64 noundef %21)
  %23 = getelementptr inbounds i8, ptr %2, i64 %22
  store i8 1, ptr %23, align 1, !tbaa !16
  %24 = load ptr, ptr %0, align 8, !tbaa !17
  %25 = getelementptr inbounds %class.dc_pixel, ptr %24, i64 %22
  %26 = tail call noundef zeroext i8 @_ZN8dc_pixel5get_rEv(ptr noundef nonnull align 1 dereferenceable(3) %3)
  %27 = tail call noundef zeroext i8 @_ZN8dc_pixel5get_gEv(ptr noundef nonnull align 1 dereferenceable(3) %3)
  %28 = tail call noundef zeroext i8 @_ZN8dc_pixel5get_bEv(ptr noundef nonnull align 1 dereferenceable(3) %3)
  tail call void @_ZN8dc_pixel12set_channelsEhhh(ptr noundef nonnull align 1 dereferenceable(3) %25, i8 noundef zeroext %26, i8 noundef zeroext %27, i8 noundef zeroext %28)
  %29 = add nuw i64 %.022.us, 1
  %30 = load i64, ptr %11, align 8, !tbaa !12
  %31 = icmp ult i64 %29, %30
  br i1 %31, label %.lr.ph.split.us, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %.lr.ph.split, %.lr.ph.split.us, %.lr.ph26.split
  %32 = phi i64 [ %18, %.lr.ph26.split ], [ %30, %.lr.ph.split.us ], [ %43, %.lr.ph.split ]
  %33 = add nuw i64 %.02023, 1
  %34 = load i64, ptr %8, align 8, !tbaa !10
  %35 = icmp ult i64 %33, %34
  br i1 %35, label %.lr.ph26.split, label %._crit_edge27, !llvm.loop !20

.lr.ph.split:                                     ; preds = %.lr.ph, %.lr.ph.split
  %.022 = phi i64 [ %42, %.lr.ph.split ], [ %19, %.lr.ph ]
  %36 = load i64, ptr %12, align 8, !tbaa !13
  %37 = tail call noundef i64 @_Z2ixmmm(i64 noundef %.022, i64 noundef %.02023, i64 noundef %36)
  %38 = getelementptr inbounds i8, ptr %2, i64 %37
  store i8 1, ptr %38, align 1, !tbaa !16
  %39 = load ptr, ptr %0, align 8, !tbaa !17
  %40 = getelementptr inbounds %class.dc_pixel, ptr %39, i64 %37
  %41 = load i8, ptr %14, align 1, !tbaa !22
  tail call void @_ZN8dc_pixel16increase_channelEh11dc_channels(ptr noundef nonnull align 1 dereferenceable(3) %40, i8 noundef zeroext %41, i32 noundef %4)
  %42 = add nuw i64 %.022, 1
  %43 = load i64, ptr %11, align 8, !tbaa !12
  %44 = icmp ult i64 %42, %43
  br i1 %44, label %.lr.ph.split, label %._crit_edge, !llvm.loop !18
}

declare void @_ZN8dc_pixel12set_channelsEhhh(ptr noundef nonnull align 1 dereferenceable(3), i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #0

declare void @_ZN8dc_pixel16increase_channelEh11dc_channels(ptr noundef nonnull align 1 dereferenceable(3), i8 noundef zeroext, i32 noundef) local_unnamed_addr #0

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

!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 8}
!6 = !{!"_ZTS11_dc_corners", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 24}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 16}
!13 = !{!14, !7, i64 8}
!14 = !{!"_ZTS15dc_pixel_matrix", !15, i64 0, !7, i64 8, !7, i64 16}
!15 = !{!"any pointer", !8, i64 0}
!16 = !{!8, !8, i64 0}
!17 = !{!14, !15, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19, !21}
!21 = !{!"llvm.loop.unswitch.partial.disable"}
!22 = !{!23, !8, i64 3}
!23 = !{!"_ZTS16_dc_light_sector", !24, i64 0, !8, i64 3, !8, i64 4}
!24 = !{!"_ZTS8dc_pixel", !8, i64 0, !8, i64 1, !8, i64 2}


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