; LLVM IR from Razakhel/RaZ :: src/RaZ/Data/Image.ll (ZN3Raz5ImageC2ENS_15ImageColorspaceENS_13ImageDataTypeE)

; 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.Raz::Image" = type { i32, i32, i32, i32, i8, %"class.std::unique_ptr" }
%"class.std::unique_ptr" = type { %"struct.std::__uniq_ptr_data" }
%"struct.std::__uniq_ptr_data" = type { %"class.std::__uniq_ptr_impl" }
%"class.std::__uniq_ptr_impl" = type { %"class.std::tuple" }
%"class.std::tuple" = type { %"struct.std::_Tuple_impl" }
%"struct.std::_Tuple_impl" = type { %"struct.std::_Head_base.7" }
%"struct.std::_Head_base.7" = type { ptr }

@.str.1 = external hidden unnamed_addr constant [69 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [176 x i8], align 1
@__PRETTY_FUNCTION__._ZN3Raz5ImageC2ENS_15ImageColorspaceENS_13ImageDataTypeE = external hidden unnamed_addr constant [50 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [50 x i8], align 1
@_ZTISt16invalid_argument = external constant ptr

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3Raz5ImageC2ENS_15ImageColorspaceENS_13ImageDataTypeE(ptr noundef nonnull align 8 dereferenceable(32) %0, i32 noundef %1, i32 noundef %2) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !11
  %9 = load ptr, ptr %4, align 8
  %10 = getelementptr inbounds %"class.Raz::Image", ptr %9, i32 0, i32 0
  store i32 0, ptr %10, align 8, !tbaa !13
  %11 = getelementptr inbounds %"class.Raz::Image", ptr %9, i32 0, i32 1
  store i32 0, ptr %11, align 4, !tbaa !22
  %12 = getelementptr inbounds %"class.Raz::Image", ptr %9, i32 0, i32 2
  %13 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %13, ptr %12, align 8, !tbaa !23
  %14 = getelementptr inbounds %"class.Raz::Image", ptr %9, i32 0, i32 3
  %15 = load i32, ptr %6, align 4, !tbaa !11
  store i32 %15, ptr %14, align 4, !tbaa !24
  %16 = getelementptr inbounds %"class.Raz::Image", ptr %9, i32 0, i32 4
  store i8 0, ptr %16, align 8, !tbaa !25
  %17 = getelementptr inbounds %"class.Raz::Image", ptr %9, i32 0, i32 5
  call void @_ZNSt10unique_ptrIN3Raz9ImageDataESt14default_deleteIS1_EEC2IS3_vEEv(ptr noundef nonnull align 8 dereferenceable(8) %17) #5
  %18 = getelementptr inbounds %"class.Raz::Image", ptr %9, i32 0, i32 2
  %19 = load i32, ptr %18, align 8, !tbaa !23
  %20 = icmp ne i32 %19, 4
  br i1 %20, label %29, label %21

21:                                               ; preds = %3
  %22 = getelementptr inbounds %"class.Raz::Image", ptr %9, i32 0, i32 2
  %23 = load i32, ptr %22, align 8, !tbaa !23
  %24 = icmp ne i32 %23, 5
  br i1 %24, label %29, label %25

25:                                               ; preds = %21
  %26 = getelementptr inbounds %"class.Raz::Image", ptr %9, i32 0, i32 3
  %27 = load i32, ptr %26, align 4, !tbaa !24
  %28 = icmp eq i32 %27, 0
  br label %29

29:                                               ; preds = %25, %21, %3
  %30 = phi i1 [ true, %21 ], [ true, %3 ], [ %28, %25 ]
  br i1 %30, label %31, label %32

31:                                               ; preds = %29
  br label %34

32:                                               ; preds = %29
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 31, ptr noundef @__PRETTY_FUNCTION__._ZN3Raz5ImageC2ENS_15ImageColorspaceENS_13ImageDataTypeE) #6
  unreachable

33:                                               ; No predecessors!
  br label %34

34:                                               ; preds = %33, %31
  %35 = load i32, ptr %5, align 4, !tbaa !9
  switch i32 %35, label %44 [
    i32 0, label %36
    i32 1, label %38
    i32 2, label %40
    i32 4, label %40
    i32 3, label %42
    i32 5, label %42
  ]

36:                                               ; preds = %34
  %37 = getelementptr inbounds %"class.Raz::Image", ptr %9, i32 0, i32 4
  store i8 1, ptr %37, align 8, !tbaa !25
  br label %55

38:                                               ; preds = %34
  %39 = getelementptr inbounds %"class.Raz::Image", ptr %9, i32 0, i32 4
  store i8 2, ptr %39, align 8, !tbaa !25
  br label %55

40:                                               ; preds = %34, %34
  %41 = getelementptr inbounds %"class.Raz::Image", ptr %9, i32 0, i32 4
  store i8 3, ptr %41, align 8, !tbaa !25
  br label %55

42:                                               ; preds = %34, %34
  %43 = getelementptr inbounds %"class.Raz::Image", ptr %9, i32 0, i32 4
  store i8 4, ptr %43, align 8, !tbaa !25
  br label %55

44:                                               ; preds = %34
  %45 = call ptr @__cxa_allocate_exception(i64 16) #5
  invoke void @_ZNSt16invalid_argumentC1EPKc(ptr noundef nonnull align 8 dereferenceable(16) %45, ptr noundef @.str.4)
          to label %46 unwind label %47

46:                                               ; preds = %44
  invoke void @__cxa_throw(ptr %45, ptr @_ZTISt16invalid_argument, ptr @_ZNSt16invalid_argumentD1Ev) #7
          to label %62 unwind label %51

47:                                               ; preds = %44
  %48 = landingpad { ptr, i32 }
          cleanup
  %49 = extractvalue { ptr, i32 } %48, 0
  store ptr %49, ptr %7, align 8
  %50 = extractvalue { ptr, i32 } %48, 1
  store i32 %50, ptr %8, align 4
  call void @__cxa_free_exception(ptr %45) #5
  br label %56

51:                                               ; preds = %46
  %52 = landingpad { ptr, i32 }
          cleanup
  %53 = extractvalue { ptr, i32 } %52, 0
  store ptr %53, ptr %7, align 8
  %54 = extractvalue { ptr, i32 } %52, 1
  store i32 %54, ptr %8, align 4
  br label %56

55:                                               ; preds = %42, %40, %38, %36
  ret void

56:                                               ; preds = %51, %47
  call void @_ZNSt10unique_ptrIN3Raz9ImageDataESt14default_deleteIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(8) %17) #5
  br label %57

57:                                               ; preds = %56
  %58 = load ptr, ptr %7, align 8
  %59 = load i32, ptr %8, align 4
  %60 = insertvalue { ptr, i32 } poison, ptr %58, 0
  %61 = insertvalue { ptr, i32 } %60, i32 %59, 1
  resume { ptr, i32 } %61

62:                                               ; preds = %46
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt10unique_ptrIN3Raz9ImageDataESt14default_deleteIS1_EEC2IS3_vEEv(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 align 2

declare ptr @__cxa_allocate_exception(i64)

declare void @_ZNSt16invalid_argumentC1EPKc(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) unnamed_addr #3

declare i32 @__gxx_personality_v0(...)

declare void @__cxa_free_exception(ptr)

; Function Attrs: nounwind
declare void @_ZNSt16invalid_argumentD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #4

declare void @__cxa_throw(ptr, ptr, ptr)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt10unique_ptrIN3Raz9ImageDataESt14default_deleteIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 align 2

attributes #0 = { noreturn nounwind "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 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 = { 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" }
attributes #3 = { "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 #4 = { nounwind "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 #5 = { nounwind }
attributes #6 = { noreturn nounwind }
attributes #7 = { noreturn }

!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, !10, i64 0}
!10 = !{!"_ZTSN3Raz15ImageColorspaceE", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_ZTSN3Raz13ImageDataTypeE", !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"_ZTSN3Raz5ImageE", !15, i64 0, !15, i64 4, !10, i64 8, !12, i64 12, !7, i64 16, !16, i64 24}
!15 = !{!"int", !7, i64 0}
!16 = !{!"_ZTSSt10unique_ptrIN3Raz9ImageDataESt14default_deleteIS1_EE", !17, i64 0}
!17 = !{!"_ZTSSt15__uniq_ptr_dataIN3Raz9ImageDataESt14default_deleteIS1_ELb1ELb1EE", !18, i64 0}
!18 = !{!"_ZTSSt15__uniq_ptr_implIN3Raz9ImageDataESt14default_deleteIS1_EE", !19, i64 0}
!19 = !{!"_ZTSSt5tupleIJPN3Raz9ImageDataESt14default_deleteIS1_EEE", !20, i64 0}
!20 = !{!"_ZTSSt11_Tuple_implILm0EJPN3Raz9ImageDataESt14default_deleteIS1_EEE", !21, i64 0}
!21 = !{!"_ZTSSt10_Head_baseILm0EPN3Raz9ImageDataELb0EE", !6, i64 0}
!22 = !{!14, !15, i64 4}
!23 = !{!14, !10, i64 8}
!24 = !{!14, !12, i64 12}
!25 = !{!14, !7, 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"

@.str.4 = external hidden unnamed_addr constant [50 x i8], align 1
@_ZTISt16invalid_argument = external constant ptr

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3Raz5ImageC2ENS_15ImageColorspaceENS_13ImageDataTypeE(ptr noundef nonnull align 8 dereferenceable(32) %0, i32 noundef %1, i32 noundef %2) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
.critedge:
  store i32 0, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 0, ptr %3, align 4, !tbaa !19
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %1, ptr %4, align 8, !tbaa !20
  %5 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %2, ptr %5, align 4, !tbaa !21
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  store i8 0, ptr %6, align 8, !tbaa !22
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  tail call void @_ZNSt10unique_ptrIN3Raz9ImageDataESt14default_deleteIS1_EEC2IS3_vEEv(ptr noundef nonnull align 8 dereferenceable(8) %7) #4
  %8 = icmp ult i32 %1, 6
  br i1 %8, label %switch.lookup, label %9

9:                                                ; preds = %.critedge
  %10 = tail call ptr @__cxa_allocate_exception(i64 16) #4
  invoke void @_ZNSt16invalid_argumentC1EPKc(ptr noundef nonnull align 8 dereferenceable(16) %10, ptr noundef nonnull @.str.4)
          to label %11 unwind label %12

11:                                               ; preds = %9
  invoke void @__cxa_throw(ptr nonnull %10, ptr nonnull @_ZTISt16invalid_argument, ptr nonnull @_ZNSt16invalid_argumentD1Ev) #5
          to label %18 unwind label %14

12:                                               ; preds = %9
  %13 = landingpad { ptr, i32 }
          cleanup
  tail call void @__cxa_free_exception(ptr %10) #4
  br label %17

14:                                               ; preds = %11
  %15 = landingpad { ptr, i32 }
          cleanup
  br label %17

switch.lookup:                                    ; preds = %.critedge
  %16 = shl nuw nsw i32 %1, 3
  %switch.shiftamt = zext nneg i32 %16 to i48
  %switch.downshift = lshr i48 4410998718977, %switch.shiftamt
  %switch.masked = trunc i48 %switch.downshift to i8
  store i8 %switch.masked, ptr %6, align 8, !tbaa !22
  ret void

17:                                               ; preds = %14, %12
  %.pn = phi { ptr, i32 } [ %15, %14 ], [ %13, %12 ]
  tail call void @_ZNSt10unique_ptrIN3Raz9ImageDataESt14default_deleteIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(8) %7) #4
  resume { ptr, i32 } %.pn

18:                                               ; preds = %11
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt10unique_ptrIN3Raz9ImageDataESt14default_deleteIS1_EEC2IS3_vEEv(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #1 align 2

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

declare void @_ZNSt16invalid_argumentC1EPKc(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) unnamed_addr #2

declare i32 @__gxx_personality_v0(...)

declare void @__cxa_free_exception(ptr) local_unnamed_addr

; Function Attrs: nounwind
declare void @_ZNSt16invalid_argumentD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #3

declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt10unique_ptrIN3Raz9ImageDataESt14default_deleteIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #1 align 2

attributes #0 = { mustprogress 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 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 = { "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 "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 #4 = { nounwind }
attributes #5 = { noreturn }

!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 = !{!"_ZTSN3Raz5ImageE", !7, i64 0, !7, i64 4, !10, i64 8, !11, i64 12, !8, i64 16, !12, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN3Raz15ImageColorspaceE", !8, i64 0}
!11 = !{!"_ZTSN3Raz13ImageDataTypeE", !8, i64 0}
!12 = !{!"_ZTSSt10unique_ptrIN3Raz9ImageDataESt14default_deleteIS1_EE", !13, i64 0}
!13 = !{!"_ZTSSt15__uniq_ptr_dataIN3Raz9ImageDataESt14default_deleteIS1_ELb1ELb1EE", !14, i64 0}
!14 = !{!"_ZTSSt15__uniq_ptr_implIN3Raz9ImageDataESt14default_deleteIS1_EE", !15, i64 0}
!15 = !{!"_ZTSSt5tupleIJPN3Raz9ImageDataESt14default_deleteIS1_EEE", !16, i64 0}
!16 = !{!"_ZTSSt11_Tuple_implILm0EJPN3Raz9ImageDataESt14default_deleteIS1_EEE", !17, i64 0}
!17 = !{!"_ZTSSt10_Head_baseILm0EPN3Raz9ImageDataELb0EE", !18, i64 0}
!18 = !{!"any pointer", !8, i64 0}
!19 = !{!6, !7, i64 4}
!20 = !{!6, !10, i64 8}
!21 = !{!6, !11, i64 12}
!22 = !{!6, !8, i64 16}


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