; LLVM IR from aap/librw :: src/image.ll (ZN2rw10ColorQuant4Node8addColorENS_4RGBAE)

; 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.rw::RGBA" = type { i8, i8, i8, i8 }
%"struct.rw::ColorQuant::Node" = type { i32, i32, i32, i32, i32, ptr, [16 x ptr], %"struct.rw::LLLink" }
%"struct.rw::LLLink" = type { ptr, ptr }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN2rw10ColorQuant4Node8addColorENS_4RGBAE(ptr noundef nonnull align 8 dereferenceable(176) %0, i32 %1) #0 align 2 {
  %3 = alloca %"struct.rw::RGBA", align 1
  %4 = alloca ptr, align 8
  store i32 %1, ptr %3, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %4, align 8
  %6 = getelementptr inbounds %"struct.rw::RGBA", ptr %3, i32 0, i32 0
  %7 = load i8, ptr %6, align 1, !tbaa !9
  %8 = zext i8 %7 to i32
  %9 = getelementptr inbounds %"struct.rw::ColorQuant::Node", ptr %5, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = add i32 %10, %8
  store i32 %11, ptr %9, align 8, !tbaa !11
  %12 = getelementptr inbounds %"struct.rw::RGBA", ptr %3, i32 0, i32 1
  %13 = load i8, ptr %12, align 1, !tbaa !15
  %14 = zext i8 %13 to i32
  %15 = getelementptr inbounds %"struct.rw::ColorQuant::Node", ptr %5, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !16
  %17 = add i32 %16, %14
  store i32 %17, ptr %15, align 4, !tbaa !16
  %18 = getelementptr inbounds %"struct.rw::RGBA", ptr %3, i32 0, i32 2
  %19 = load i8, ptr %18, align 1, !tbaa !17
  %20 = zext i8 %19 to i32
  %21 = getelementptr inbounds %"struct.rw::ColorQuant::Node", ptr %5, i32 0, i32 2
  %22 = load i32, ptr %21, align 8, !tbaa !18
  %23 = add i32 %22, %20
  store i32 %23, ptr %21, align 8, !tbaa !18
  %24 = getelementptr inbounds %"struct.rw::RGBA", ptr %3, i32 0, i32 3
  %25 = load i8, ptr %24, align 1, !tbaa !19
  %26 = zext i8 %25 to i32
  %27 = getelementptr inbounds %"struct.rw::ColorQuant::Node", ptr %5, i32 0, i32 3
  %28 = load i32, ptr %27, align 4, !tbaa !20
  %29 = add i32 %28, %26
  store i32 %29, ptr %27, align 4, !tbaa !20
  %30 = getelementptr inbounds %"struct.rw::ColorQuant::Node", ptr %5, i32 0, i32 4
  %31 = load i32, ptr %30, align 8, !tbaa !21
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %30, align 8, !tbaa !21
  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 = !{!10, !7, i64 0}
!10 = !{!"_ZTSN2rw4RGBAE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTSN2rw10ColorQuant4NodeE", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !6, i64 24, !7, i64 32, !14, i64 160}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTSN2rw6LLLinkE", !6, i64 0, !6, i64 8}
!15 = !{!10, !7, i64 1}
!16 = !{!12, !13, i64 4}
!17 = !{!10, !7, i64 2}
!18 = !{!12, !13, i64 8}
!19 = !{!10, !7, i64 3}
!20 = !{!12, !13, i64 12}
!21 = !{!12, !13, 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(argmem: readwrite) uwtable
define dso_local void @_ZN2rw10ColorQuant4Node8addColorENS_4RGBAE(ptr nocapture noundef nonnull align 8 dereferenceable(176) %0, i32 %1) local_unnamed_addr #0 align 2 {
  %.sroa.2.0.extract.shift = lshr i32 %1, 8
  %.sroa.3.0.extract.shift = lshr i32 %1, 16
  %.sroa.4.0.extract.shift = lshr i32 %1, 24
  %3 = and i32 %1, 255
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %5 = add i32 %4, %3
  store i32 %5, ptr %0, align 8, !tbaa !5
  %6 = and i32 %.sroa.2.0.extract.shift, 255
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  %8 = and i32 %.sroa.3.0.extract.shift, 255
  %9 = load <4 x i32>, ptr %7, align 4, !tbaa !12
  %10 = insertelement <4 x i32> <i32 poison, i32 poison, i32 poison, i32 1>, i32 %6, i64 0
  %11 = insertelement <4 x i32> %10, i32 %8, i64 1
  %12 = insertelement <4 x i32> %11, i32 %.sroa.4.0.extract.shift, i64 2
  %13 = add <4 x i32> %9, %12
  store <4 x i32> %13, ptr %7, align 4, !tbaa !12
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 0}
!6 = !{!"_ZTSN2rw10ColorQuant4NodeE", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 24, !8, i64 32, !11, i64 160}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_ZTSN2rw6LLLinkE", !10, i64 0, !10, i64 8}
!12 = !{!7, !7, i64 0}


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