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

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

; Function Attrs: nounwind uwtable
declare dso_local void @stbi_image_free(ptr 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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local void @_dc_pack(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._dc_decompression, ptr %11, i32 0, i32 6
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct._dc_pixel_matrix, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 8, !tbaa !13
  %16 = sext i32 %15 to i64
  store i64 %16, ptr %3, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._dc_decompression, ptr %17, i32 0, i32 6
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct._dc_pixel_matrix, ptr %19, i32 0, i32 2
  %21 = load i32, ptr %20, align 4, !tbaa !16
  %22 = sext i32 %21 to i64
  store i64 %22, ptr %4, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %23 = load i64, ptr %3, align 8, !tbaa !15
  %24 = mul i64 1, %23
  %25 = load i64, ptr %4, align 8, !tbaa !15
  %26 = mul i64 %24, %25
  %27 = mul i64 %26, 3
  %28 = call noalias ptr @malloc(i64 noundef %27) #4
  store ptr %28, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !15
  br label %29

29:                                               ; preds = %80, %1
  %30 = load i64, ptr %7, align 8, !tbaa !15
  %31 = load i64, ptr %4, align 8, !tbaa !15
  %32 = icmp ult i64 %30, %31
  br i1 %32, label %34, label %33

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

34:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 0, ptr %9, align 8, !tbaa !15
  br label %35

35:                                               ; preds = %76, %34
  %36 = load i64, ptr %9, align 8, !tbaa !15
  %37 = load i64, ptr %3, align 8, !tbaa !15
  %38 = icmp ult i64 %36, %37
  br i1 %38, label %40, label %39

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

40:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._dc_decompression, ptr %41, i32 0, i32 6
  %43 = load ptr, ptr %42, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct._dc_pixel_matrix, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !17
  %46 = load i64, ptr %9, align 8, !tbaa !15
  %47 = trunc i64 %46 to i32
  %48 = load i64, ptr %7, align 8, !tbaa !15
  %49 = trunc i64 %48 to i32
  %50 = load i64, ptr %3, align 8, !tbaa !15
  %51 = trunc i64 %50 to i32
  %52 = call i32 @ix(i32 noundef %47, i32 noundef %49, i32 noundef %51)
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds %struct._dc_pixel, ptr %45, i64 %53
  store ptr %54, ptr %10, align 8, !tbaa !5
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._dc_pixel, ptr %55, i32 0, i32 0
  %57 = load i8, ptr %56, align 1, !tbaa !18
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = load i64, ptr %6, align 8, !tbaa !15
  %60 = add i64 %59, 1
  store i64 %60, ptr %6, align 8, !tbaa !15
  %61 = getelementptr inbounds i8, ptr %58, i64 %59
  store i8 %57, ptr %61, align 1, !tbaa !20
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._dc_pixel, ptr %62, i32 0, i32 1
  %64 = load i8, ptr %63, align 1, !tbaa !21
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = load i64, ptr %6, align 8, !tbaa !15
  %67 = add i64 %66, 1
  store i64 %67, ptr %6, align 8, !tbaa !15
  %68 = getelementptr inbounds i8, ptr %65, i64 %66
  store i8 %64, ptr %68, align 1, !tbaa !20
  %69 = load ptr, ptr %10, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct._dc_pixel, ptr %69, i32 0, i32 2
  %71 = load i8, ptr %70, align 1, !tbaa !22
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = load i64, ptr %6, align 8, !tbaa !15
  %74 = add i64 %73, 1
  store i64 %74, ptr %6, align 8, !tbaa !15
  %75 = getelementptr inbounds i8, ptr %72, i64 %73
  store i8 %71, ptr %75, align 1, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %76

76:                                               ; preds = %40
  %77 = load i64, ptr %9, align 8, !tbaa !15
  %78 = add i64 %77, 1
  store i64 %78, ptr %9, align 8, !tbaa !15
  br label %35, !llvm.loop !23

79:                                               ; preds = %39
  br label %80

80:                                               ; preds = %79
  %81 = load i64, ptr %7, align 8, !tbaa !15
  %82 = add i64 %81, 1
  store i64 %82, ptr %7, align 8, !tbaa !15
  br label %29, !llvm.loop !25

83:                                               ; preds = %33
  %84 = load ptr, ptr %2, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct._dc_decompression, ptr %84, i32 0, i32 3
  %86 = load ptr, ptr %85, align 8, !tbaa !26
  %87 = load i64, ptr %3, align 8, !tbaa !15
  %88 = trunc i64 %87 to i32
  %89 = load i64, ptr %4, align 8, !tbaa !15
  %90 = trunc i64 %89 to i32
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = call i32 @stbi_write_png(ptr noundef %86, i32 noundef %88, i32 noundef %90, i32 noundef 3, ptr noundef %91, i32 noundef 0)
  %93 = load ptr, ptr %5, align 8, !tbaa !5
  call void @stbi_image_free(ptr noundef %93)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind allocsize(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 = { nounwind allocsize(0) }

!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, !6, i64 40}
!10 = !{!"_dc_decompression", !11, i64 0, !7, i64 4, !6, i64 8, !6, i64 16, !7, i64 24, !12, i64 32, !6, i64 40, !6, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !11, i64 8}
!14 = !{!"_dc_pixel_matrix", !6, i64 0, !11, i64 8, !11, i64 12}
!15 = !{!12, !12, i64 0}
!16 = !{!14, !11, i64 12}
!17 = !{!14, !6, i64 0}
!18 = !{!19, !7, i64 0}
!19 = !{!"_dc_pixel", !7, i64 0, !7, i64 1, !7, i64 2}
!20 = !{!7, !7, i64 0}
!21 = !{!19, !7, i64 1}
!22 = !{!19, !7, i64 2}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !24}
!26 = !{!10, !6, i64 16}


; 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 void @stbi_image_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @_dc_pack(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !12
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds i8, ptr %3, i64 12
  %8 = load i32, ptr %7, align 4, !tbaa !14
  %9 = sext i32 %8 to i64
  %10 = mul nsw i64 %6, 3
  %11 = mul i64 %10, %9
  %12 = tail call noalias ptr @malloc(i64 noundef %11) #2
  %.not = icmp eq i32 %8, 0
  %.not34 = icmp eq i32 %5, 0
  %or.cond = or i1 %.not, %.not34
  br i1 %or.cond, label %._crit_edge33, label %.preheader.us

.preheader.us:                                    ; preds = %1, %._crit_edge.us
  %.032.us = phi i64 [ %28, %._crit_edge.us ], [ 0, %1 ]
  %.02831.us = phi i64 [ %31, %._crit_edge.us ], [ 0, %1 ]
  %13 = trunc i64 %.02831.us to i32
  br label %14

14:                                               ; preds = %.preheader.us, %14
  %.130.us = phi i64 [ %.032.us, %.preheader.us ], [ %28, %14 ]
  %.02729.us = phi i64 [ 0, %.preheader.us ], [ %30, %14 ]
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  %17 = trunc i64 %.02729.us to i32
  %18 = tail call i32 @ix(i32 noundef %17, i32 noundef %13, i32 noundef %5)
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds %struct._dc_pixel, ptr %16, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !16
  %22 = getelementptr inbounds i8, ptr %12, i64 %.130.us
  store i8 %21, ptr %22, align 1, !tbaa !18
  %23 = getelementptr inbounds i8, ptr %20, i64 1
  %24 = load i8, ptr %23, align 1, !tbaa !19
  %25 = getelementptr i8, ptr %22, i64 1
  store i8 %24, ptr %25, align 1, !tbaa !18
  %26 = getelementptr inbounds i8, ptr %20, i64 2
  %27 = load i8, ptr %26, align 1, !tbaa !20
  %28 = add i64 %.130.us, 3
  %29 = getelementptr i8, ptr %22, i64 2
  store i8 %27, ptr %29, align 1, !tbaa !18
  %30 = add nuw i64 %.02729.us, 1
  %exitcond.not = icmp eq i64 %30, %6
  br i1 %exitcond.not, label %._crit_edge.us, label %14, !llvm.loop !21

._crit_edge.us:                                   ; preds = %14
  %31 = add nuw i64 %.02831.us, 1
  %exitcond36.not = icmp eq i64 %31, %9
  br i1 %exitcond36.not, label %._crit_edge33, label %.preheader.us, !llvm.loop !23

._crit_edge33:                                    ; preds = %._crit_edge.us, %1
  %32 = getelementptr inbounds i8, ptr %0, i64 16
  %33 = load ptr, ptr %32, align 8, !tbaa !24
  %34 = tail call i32 @stbi_write_png(ptr noundef %33, i32 noundef %5, i32 noundef %8, i32 noundef 3, ptr noundef %12, i32 noundef 0)
  tail call void @stbi_image_free(ptr noundef %12)
  ret void
}

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" }
attributes #1 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0) }

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


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