; LLVM IR from giacomo-ascari/dichotomic-compression :: legacy/dc/dc.ll (dc_draw_n_occupy)

; 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 { i32, i32, i32, i32 }
%struct._dc_decompression = type { i32, i8, ptr, ptr, i8, i64, ptr, ptr }
%struct._dc_pixel_matrix = type { ptr, i32, i32 }
%struct._dc_light_sector = type { %struct._dc_pixel, i8, i8, ptr, ptr }
%struct._dc_pixel = type { i8, i8, i8 }

; 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: nounwind uwtable
declare dso_local i32 @ix(i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @_dc_set_channel(ptr noundef, i32 noundef, i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local void @_dc_draw_n_occupy(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) #1 {
  %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
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._dc_corners, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = sext i32 %17 to i64
  store i64 %18, ptr %12, align 8, !tbaa !13
  br label %19

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

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

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

32:                                               ; preds = %110, %27
  %33 = load i64, ptr %14, align 8, !tbaa !13
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._dc_corners, ptr %34, i32 0, i32 2
  %36 = load i32, ptr %35, align 4, !tbaa !17
  %37 = sext i32 %36 to i64
  %38 = icmp ult i64 %33, %37
  br i1 %38, label %40, label %39

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

40:                                               ; preds = %32
  %41 = load i64, ptr %14, align 8, !tbaa !13
  %42 = trunc i64 %41 to i32
  %43 = load i64, ptr %12, align 8, !tbaa !13
  %44 = trunc i64 %43 to i32
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._dc_decompression, ptr %45, i32 0, i32 6
  %47 = load ptr, ptr %46, align 8, !tbaa !18
  %48 = getelementptr inbounds %struct._dc_pixel_matrix, ptr %47, i32 0, i32 1
  %49 = load i32, ptr %48, align 8, !tbaa !20
  %50 = call i32 @ix(i32 noundef %42, i32 noundef %44, i32 noundef %49)
  %51 = sext i32 %50 to i64
  store i64 %51, ptr %11, align 8, !tbaa !13
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = load i64, ptr %11, align 8, !tbaa !13
  %54 = getelementptr inbounds i8, ptr %52, i64 %53
  store i8 1, ptr %54, align 1, !tbaa !22
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._dc_decompression, ptr %55, i32 0, i32 1
  %57 = load i8, ptr %56, align 4, !tbaa !23
  %58 = zext i8 %57 to i32
  switch i32 %58, label %108 [
    i32 1, label %59
    i32 2, label %96
  ]

59:                                               ; preds = %40
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._dc_light_sector, ptr %60, i32 0, i32 0
  %62 = getelementptr inbounds %struct._dc_pixel, ptr %61, i32 0, i32 0
  %63 = load i8, ptr %62, align 8, !tbaa !24
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct._dc_decompression, ptr %64, i32 0, i32 6
  %66 = load ptr, ptr %65, align 8, !tbaa !18
  %67 = getelementptr inbounds %struct._dc_pixel_matrix, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !27
  %69 = load i64, ptr %11, align 8, !tbaa !13
  %70 = getelementptr inbounds %struct._dc_pixel, ptr %68, i64 %69
  %71 = getelementptr inbounds %struct._dc_pixel, ptr %70, i32 0, i32 0
  store i8 %63, ptr %71, align 1, !tbaa !28
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct._dc_light_sector, ptr %72, i32 0, i32 0
  %74 = getelementptr inbounds %struct._dc_pixel, ptr %73, i32 0, i32 1
  %75 = load i8, ptr %74, align 1, !tbaa !29
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct._dc_decompression, ptr %76, i32 0, i32 6
  %78 = load ptr, ptr %77, align 8, !tbaa !18
  %79 = getelementptr inbounds %struct._dc_pixel_matrix, ptr %78, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8, !tbaa !27
  %81 = load i64, ptr %11, align 8, !tbaa !13
  %82 = getelementptr inbounds %struct._dc_pixel, ptr %80, i64 %81
  %83 = getelementptr inbounds %struct._dc_pixel, ptr %82, i32 0, i32 1
  store i8 %75, ptr %83, align 1, !tbaa !30
  %84 = load ptr, ptr %9, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct._dc_light_sector, ptr %84, i32 0, i32 0
  %86 = getelementptr inbounds %struct._dc_pixel, ptr %85, i32 0, i32 2
  %87 = load i8, ptr %86, align 2, !tbaa !31
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct._dc_decompression, ptr %88, i32 0, i32 6
  %90 = load ptr, ptr %89, align 8, !tbaa !18
  %91 = getelementptr inbounds %struct._dc_pixel_matrix, ptr %90, i32 0, i32 0
  %92 = load ptr, ptr %91, align 8, !tbaa !27
  %93 = load i64, ptr %11, align 8, !tbaa !13
  %94 = getelementptr inbounds %struct._dc_pixel, ptr %92, i64 %93
  %95 = getelementptr inbounds %struct._dc_pixel, ptr %94, i32 0, i32 2
  store i8 %87, ptr %95, align 1, !tbaa !32
  br label %109

96:                                               ; preds = %40
  %97 = load ptr, ptr %6, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct._dc_decompression, ptr %97, i32 0, i32 6
  %99 = load ptr, ptr %98, align 8, !tbaa !18
  %100 = getelementptr inbounds %struct._dc_pixel_matrix, ptr %99, i32 0, i32 0
  %101 = load ptr, ptr %100, align 8, !tbaa !27
  %102 = load i64, ptr %11, align 8, !tbaa !13
  %103 = getelementptr inbounds %struct._dc_pixel, ptr %101, i64 %102
  %104 = load i32, ptr %10, align 4, !tbaa !9
  %105 = load ptr, ptr %9, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct._dc_light_sector, ptr %105, i32 0, i32 1
  %107 = load i8, ptr %106, align 1, !tbaa !33
  call void @_dc_set_channel(ptr noundef %103, i32 noundef %104, i8 noundef zeroext %107)
  br label %109

108:                                              ; preds = %40
  br label %109

109:                                              ; preds = %108, %96, %59
  br label %110

110:                                              ; preds = %109
  %111 = load i64, ptr %14, align 8, !tbaa !13
  %112 = add i64 %111, 1
  store i64 %112, ptr %14, align 8, !tbaa !13
  br label %32, !llvm.loop !34

113:                                              ; preds = %39
  br label %114

114:                                              ; preds = %113
  %115 = load i64, ptr %12, align 8, !tbaa !13
  %116 = add i64 %115, 1
  store i64 %116, ptr %12, align 8, !tbaa !13
  br label %19, !llvm.loop !36

117:                                              ; preds = %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"_dc_corners", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!12, !10, i64 12}
!16 = !{!12, !10, i64 0}
!17 = !{!12, !10, i64 8}
!18 = !{!19, !6, i64 40}
!19 = !{!"_dc_decompression", !10, i64 0, !7, i64 4, !6, i64 8, !6, i64 16, !7, i64 24, !14, i64 32, !6, i64 40, !6, i64 48}
!20 = !{!21, !10, i64 8}
!21 = !{!"_dc_pixel_matrix", !6, i64 0, !10, i64 8, !10, i64 12}
!22 = !{!7, !7, i64 0}
!23 = !{!19, !7, i64 4}
!24 = !{!25, !7, i64 0}
!25 = !{!"_dc_light_sector", !26, i64 0, !7, i64 3, !7, i64 4, !6, i64 8, !6, i64 16}
!26 = !{!"_dc_pixel", !7, i64 0, !7, i64 1, !7, i64 2}
!27 = !{!21, !6, i64 0}
!28 = !{!26, !7, i64 0}
!29 = !{!25, !7, i64 1}
!30 = !{!26, !7, i64 1}
!31 = !{!25, !7, i64 2}
!32 = !{!26, !7, i64 2}
!33 = !{!25, !7, i64 3}
!34 = distinct !{!34, !35}
!35 = !{!"llvm.loop.mustprogress"}
!36 = distinct !{!36, !35}


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

%struct._dc_pixel = type { i8, i8, i8 }

; Function Attrs: nounwind uwtable
declare dso_local i32 @ix(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @_dc_set_channel(ptr noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @_dc_draw_n_occupy(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef readonly %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = getelementptr inbounds i8, ptr %1, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %1, i64 12
  %9 = load i32, ptr %8, align 4, !tbaa !10
  %10 = icmp ult i32 %7, %9
  br i1 %10, label %.lr.ph30, label %._crit_edge31

.lr.ph30:                                         ; preds = %5
  %11 = sext i32 %7 to i64
  %12 = getelementptr inbounds i8, ptr %1, i64 8
  %13 = getelementptr inbounds i8, ptr %0, i64 40
  %14 = getelementptr inbounds i8, ptr %0, i64 4
  %15 = getelementptr inbounds i8, ptr %3, i64 3
  %16 = getelementptr inbounds i8, ptr %3, i64 1
  %17 = getelementptr inbounds i8, ptr %3, i64 2
  %.pre = load i32, ptr %12, align 4, !tbaa !11
  br label %18

._crit_edge31:                                    ; preds = %._crit_edge, %5
  ret void

18:                                               ; preds = %.lr.ph30, %._crit_edge
  %19 = phi i32 [ %9, %.lr.ph30 ], [ %25, %._crit_edge ]
  %20 = phi i32 [ %.pre, %.lr.ph30 ], [ %26, %._crit_edge ]
  %.02628 = phi i64 [ %11, %.lr.ph30 ], [ %27, %._crit_edge ]
  %21 = load i32, ptr %1, align 4, !tbaa !12
  %22 = icmp ult i32 %21, %20
  br i1 %22, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %18
  %23 = sext i32 %21 to i64
  %24 = trunc i64 %.02628 to i32
  br label %30

._crit_edge.loopexit:                             ; preds = %53
  %.pre32 = load i32, ptr %8, align 4, !tbaa !10
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %18
  %25 = phi i32 [ %.pre32, %._crit_edge.loopexit ], [ %19, %18 ]
  %26 = phi i32 [ %55, %._crit_edge.loopexit ], [ %20, %18 ]
  %27 = add i64 %.02628, 1
  %28 = sext i32 %25 to i64
  %29 = icmp ult i64 %27, %28
  br i1 %29, label %18, label %._crit_edge31, !llvm.loop !13

30:                                               ; preds = %.lr.ph, %53
  %.027 = phi i64 [ %23, %.lr.ph ], [ %54, %53 ]
  %31 = trunc i64 %.027 to i32
  %32 = load ptr, ptr %13, align 8, !tbaa !15
  %33 = getelementptr inbounds i8, ptr %32, i64 8
  %34 = load i32, ptr %33, align 8, !tbaa !19
  %35 = tail call i32 @ix(i32 noundef %31, i32 noundef %24, i32 noundef %34)
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %2, i64 %36
  store i8 1, ptr %37, align 1, !tbaa !21
  %38 = load i8, ptr %14, align 4, !tbaa !22
  switch i8 %38, label %53 [
    i8 1, label %39
    i8 2, label %48
  ]

39:                                               ; preds = %30
  %40 = load i8, ptr %3, align 8, !tbaa !23
  %41 = load ptr, ptr %13, align 8, !tbaa !15
  %42 = load ptr, ptr %41, align 8, !tbaa !26
  %43 = getelementptr inbounds %struct._dc_pixel, ptr %42, i64 %36
  store i8 %40, ptr %43, align 1, !tbaa !27
  %44 = load i8, ptr %16, align 1, !tbaa !28
  %45 = getelementptr inbounds %struct._dc_pixel, ptr %42, i64 %36, i32 1
  store i8 %44, ptr %45, align 1, !tbaa !29
  %46 = load i8, ptr %17, align 2, !tbaa !30
  %47 = getelementptr inbounds %struct._dc_pixel, ptr %42, i64 %36, i32 2
  store i8 %46, ptr %47, align 1, !tbaa !31
  br label %53

48:                                               ; preds = %30
  %49 = load ptr, ptr %13, align 8, !tbaa !15
  %50 = load ptr, ptr %49, align 8, !tbaa !26
  %51 = getelementptr inbounds %struct._dc_pixel, ptr %50, i64 %36
  %52 = load i8, ptr %15, align 1, !tbaa !32
  tail call void @_dc_set_channel(ptr noundef %51, i32 noundef %4, i8 noundef zeroext %52)
  br label %53

53:                                               ; preds = %39, %48, %30
  %54 = add nuw i64 %.027, 1
  %55 = load i32, ptr %12, align 4, !tbaa !11
  %56 = sext i32 %55 to i64
  %57 = icmp ult i64 %54, %56
  br i1 %57, label %30, label %._crit_edge.loopexit, !llvm.loop !33
}

attributes #0 = { 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 4}
!6 = !{!"_dc_corners", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 12}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !17, i64 40}
!16 = !{!"_dc_decompression", !7, i64 0, !8, i64 4, !17, i64 8, !17, i64 16, !8, i64 24, !18, i64 32, !17, i64 40, !17, i64 48}
!17 = !{!"any pointer", !8, i64 0}
!18 = !{!"long", !8, i64 0}
!19 = !{!20, !7, i64 8}
!20 = !{!"_dc_pixel_matrix", !17, i64 0, !7, i64 8, !7, i64 12}
!21 = !{!8, !8, i64 0}
!22 = !{!16, !8, i64 4}
!23 = !{!24, !8, i64 0}
!24 = !{!"_dc_light_sector", !25, i64 0, !8, i64 3, !8, i64 4, !17, i64 8, !17, i64 16}
!25 = !{!"_dc_pixel", !8, i64 0, !8, i64 1, !8, i64 2}
!26 = !{!20, !17, i64 0}
!27 = !{!25, !8, i64 0}
!28 = !{!24, !8, i64 1}
!29 = !{!25, !8, i64 1}
!30 = !{!24, !8, i64 2}
!31 = !{!25, !8, i64 2}
!32 = !{!24, !8, i64 3}
!33 = distinct !{!33, !14}


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