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

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

; Function Attrs: nounwind uwtable
define dso_local void @_dc_append_light_sector(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct._dc_decompression, ptr %5, i32 0, i32 7
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %31

9:                                                ; preds = %2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct._dc_light_sector, ptr %10, i32 0, i32 3
  store ptr null, ptr %11, align 8, !tbaa !13
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._dc_decompression, ptr %12, i32 0, i32 7
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct._dc_light_sector, ptr %14, i32 0, i32 4
  %16 = load ptr, ptr %15, align 8, !tbaa !16
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._dc_light_sector, ptr %17, i32 0, i32 4
  store ptr %16, ptr %18, align 8, !tbaa !16
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._dc_decompression, ptr %20, i32 0, i32 7
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct._dc_light_sector, ptr %22, i32 0, i32 4
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %25 = getelementptr inbounds %struct._dc_light_sector, ptr %24, i32 0, i32 3
  store ptr %19, ptr %25, align 8, !tbaa !13
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._dc_decompression, ptr %27, i32 0, i32 7
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct._dc_light_sector, ptr %29, i32 0, i32 4
  store ptr %26, ptr %30, align 8, !tbaa !16
  br label %40

31:                                               ; preds = %2
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._dc_light_sector, ptr %32, i32 0, i32 3
  store ptr null, ptr %33, align 8, !tbaa !13
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._dc_light_sector, ptr %35, i32 0, i32 4
  store ptr %34, ptr %36, align 8, !tbaa !16
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._dc_decompression, ptr %38, i32 0, i32 7
  store ptr %37, ptr %39, align 8, !tbaa !9
  br label %40

40:                                               ; preds = %31, %9
  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" }

!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 48}
!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, !6, i64 8}
!14 = !{!"_dc_light_sector", !15, i64 0, !7, i64 3, !7, i64 4, !6, i64 8, !6, i64 16}
!15 = !{!"_dc_pixel", !7, i64 0, !7, i64 1, !7, i64 2}
!16 = !{!14, !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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_dc_append_light_sector(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 48
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr null, ptr %5, align 8, !tbaa !12
  br i1 %.not, label %11, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %4, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !15
  %9 = getelementptr inbounds i8, ptr %1, i64 16
  store ptr %8, ptr %9, align 8, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %8, i64 8
  br label %13

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %1, i64 16
  br label %13

13:                                               ; preds = %11, %6
  %.sink13 = phi ptr [ %12, %11 ], [ %10, %6 ]
  %.sink = phi ptr [ %3, %11 ], [ %7, %6 ]
  store ptr %1, ptr %.sink13, align 8, !tbaa !16
  store ptr %1, ptr %.sink, align 8, !tbaa !16
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) 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, !10, i64 48}
!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, !10, i64 8}
!13 = !{!"_dc_light_sector", !14, i64 0, !8, i64 3, !8, i64 4, !10, i64 8, !10, i64 16}
!14 = !{!"_dc_pixel", !8, i64 0, !8, i64 1, !8, i64 2}
!15 = !{!13, !10, i64 16}
!16 = !{!10, !10, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass