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

; 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.dc_pixel = type { i8, i8, i8 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN8dc_pixel16increase_channelEh11dc_channels(ptr noundef nonnull align 1 dereferenceable(3) %0, i8 noundef zeroext %1, i32 noundef %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !10
  %7 = load ptr, ptr %4, align 8
  %8 = load i32, ptr %6, align 4, !tbaa !10
  switch i32 %8, label %33 [
    i32 0, label %9
    i32 1, label %17
    i32 2, label %25
  ]

9:                                                ; preds = %3
  %10 = load i8, ptr %5, align 1, !tbaa !9
  %11 = zext i8 %10 to i32
  %12 = getelementptr inbounds %class.dc_pixel, ptr %7, i32 0, i32 0
  %13 = load i8, ptr %12, align 1, !tbaa !12
  %14 = zext i8 %13 to i32
  %15 = add nsw i32 %14, %11
  %16 = trunc i32 %15 to i8
  store i8 %16, ptr %12, align 1, !tbaa !12
  br label %34

17:                                               ; preds = %3
  %18 = load i8, ptr %5, align 1, !tbaa !9
  %19 = zext i8 %18 to i32
  %20 = getelementptr inbounds %class.dc_pixel, ptr %7, i32 0, i32 1
  %21 = load i8, ptr %20, align 1, !tbaa !14
  %22 = zext i8 %21 to i32
  %23 = add nsw i32 %22, %19
  %24 = trunc i32 %23 to i8
  store i8 %24, ptr %20, align 1, !tbaa !14
  br label %34

25:                                               ; preds = %3
  %26 = load i8, ptr %5, align 1, !tbaa !9
  %27 = zext i8 %26 to i32
  %28 = getelementptr inbounds %class.dc_pixel, ptr %7, i32 0, i32 2
  %29 = load i8, ptr %28, align 1, !tbaa !15
  %30 = zext i8 %29 to i32
  %31 = add nsw i32 %30, %27
  %32 = trunc i32 %31 to i8
  store i8 %32, ptr %28, align 1, !tbaa !15
  br label %34

33:                                               ; preds = %3
  br label %34

34:                                               ; preds = %33, %25, %17, %9
  ret void
}

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

!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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"_ZTS11dc_channels", !7, i64 0}
!12 = !{!13, !7, i64 0}
!13 = !{!"_ZTS8dc_pixel", !7, i64 0, !7, i64 1, !7, i64 2}
!14 = !{!13, !7, i64 1}
!15 = !{!13, !7, i64 2}


; 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 @_ZN8dc_pixel16increase_channelEh11dc_channels(ptr nocapture noundef nonnull align 1 dereferenceable(3) %0, i8 noundef zeroext %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  switch i32 %2, label %10 [
    i32 0, label %.sink.split
    i32 1, label %4
    i32 2, label %6
  ]

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 1
  br label %.sink.split

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 2
  br label %.sink.split

.sink.split:                                      ; preds = %3, %4, %6
  %.sink = phi ptr [ %7, %6 ], [ %5, %4 ], [ %0, %3 ]
  %8 = load i8, ptr %.sink, align 1, !tbaa !5
  %9 = add i8 %8, %1
  store i8 %9, ptr %.sink, align 1, !tbaa !5
  br label %10

10:                                               ; preds = %.sink.split, %3
  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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


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