; LLVM IR from rweather/lightweight-crypto :: src/genavr/code.ll (ZN4Insn6memoryENS_4TypeEhh)

; 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.Insn = type <{ i32, i8, i8, [2 x i8] }>

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4InsnC2ENS_4TypeEhh(ptr noundef nonnull align 4 dereferenceable(6), i32 noundef, i8 noundef zeroext, i8 noundef zeroext) unnamed_addr #0 align 2

declare ptr @__cxa_allocate_exception(i64)

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

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 #2

declare void @__cxa_throw(ptr, ptr, ptr)

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Insn6memoryENS_4TypeEhh(ptr dead_on_unwind noalias writable sret(%class.Insn) align 4 %0, i32 noundef %1, i8 noundef zeroext %2, i8 noundef zeroext %3) #3 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i8 %2, ptr %7, align 1, !tbaa !9
  store i8 %3, ptr %8, align 1, !tbaa !9
  %11 = load i8, ptr %8, align 1, !tbaa !9
  %12 = zext i8 %11 to i32
  %13 = icmp ne i32 %12, 254
  br i1 %13, label %14, label %49

14:                                               ; preds = %4
  %15 = load i8, ptr %8, align 1, !tbaa !9
  %16 = zext i8 %15 to i32
  %17 = icmp ne i32 %16, 255
  br i1 %17, label %18, label %49

18:                                               ; preds = %14
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = icmp eq i32 %19, 23
  br i1 %20, label %24, label %21

21:                                               ; preds = %18
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = icmp eq i32 %22, 53
  br i1 %23, label %24, label %36

24:                                               ; preds = %21, %18
  %25 = load i8, ptr %8, align 1, !tbaa !9
  %26 = zext i8 %25 to i32
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %35

28:                                               ; preds = %24
  %29 = call ptr @__cxa_allocate_exception(i64 16) #4
  invoke void @_ZNSt16invalid_argumentC1EPKc(ptr noundef nonnull align 8 dereferenceable(16) %29, ptr noundef @.str.4)
          to label %30 unwind label %31

30:                                               ; preds = %28
  call void @__cxa_throw(ptr %29, ptr @_ZTISt16invalid_argument, ptr @_ZNSt16invalid_argumentD1Ev) #5
  unreachable

31:                                               ; preds = %28
  %32 = landingpad { ptr, i32 }
          cleanup
  %33 = extractvalue { ptr, i32 } %32, 0
  store ptr %33, ptr %9, align 8
  %34 = extractvalue { ptr, i32 } %32, 1
  store i32 %34, ptr %10, align 4
  call void @__cxa_free_exception(ptr %29) #4
  br label %53

35:                                               ; preds = %24
  br label %48

36:                                               ; preds = %21
  %37 = load i8, ptr %8, align 1, !tbaa !9
  %38 = zext i8 %37 to i32
  %39 = icmp sge i32 %38, 64
  br i1 %39, label %40, label %47

40:                                               ; preds = %36
  %41 = call ptr @__cxa_allocate_exception(i64 16) #4
  invoke void @_ZNSt16invalid_argumentC1EPKc(ptr noundef nonnull align 8 dereferenceable(16) %41, ptr noundef @.str.5)
          to label %42 unwind label %43

42:                                               ; preds = %40
  call void @__cxa_throw(ptr %41, ptr @_ZTISt16invalid_argument, ptr @_ZNSt16invalid_argumentD1Ev) #5
  unreachable

43:                                               ; preds = %40
  %44 = landingpad { ptr, i32 }
          cleanup
  %45 = extractvalue { ptr, i32 } %44, 0
  store ptr %45, ptr %9, align 8
  %46 = extractvalue { ptr, i32 } %44, 1
  store i32 %46, ptr %10, align 4
  call void @__cxa_free_exception(ptr %41) #4
  br label %53

47:                                               ; preds = %36
  br label %48

48:                                               ; preds = %47, %35
  br label %49

49:                                               ; preds = %48, %14, %4
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = load i8, ptr %7, align 1, !tbaa !9
  %52 = load i8, ptr %8, align 1, !tbaa !9
  call void @_ZN4InsnC2ENS_4TypeEhh(ptr noundef nonnull align 4 dereferenceable(6) %0, i32 noundef %50, i8 noundef zeroext %51, i8 noundef zeroext %52)
  ret void

53:                                               ; preds = %43, %31
  %54 = load ptr, ptr %9, align 8
  %55 = load i32, ptr %10, align 4
  %56 = insertvalue { ptr, i32 } poison, ptr %54, 0
  %57 = insertvalue { ptr, i32 } %56, i32 %55, 1
  resume { ptr, i32 } %57
}

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" }
attributes #1 = { "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 "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 = { 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 #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, !6, i64 0}
!6 = !{!"_ZTSN4Insn4TypeE", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}


; 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"

%class.Insn = type <{ i32, i8, i8, [2 x i8] }>

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4InsnC2ENS_4TypeEhh(ptr noundef nonnull align 4 dereferenceable(6), i32 noundef, i8 noundef zeroext, i8 noundef zeroext) unnamed_addr #0 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 #1

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 #2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Insn6memoryENS_4TypeEhh(ptr dead_on_unwind noalias writable sret(%class.Insn) align 4 %0, i32 noundef %1, i8 noundef zeroext %2, i8 noundef zeroext %3) local_unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %or.cond = icmp ult i8 %3, -2
  br i1 %or.cond, label %5, label %19

5:                                                ; preds = %4
  switch i32 %1, label %12 [
    i32 53, label %6
    i32 23, label %6
  ]

6:                                                ; preds = %5, %5
  %.not = icmp eq i8 %3, 0
  br i1 %.not, label %19, label %7

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

9:                                                ; preds = %7
  tail call void @__cxa_throw(ptr nonnull %8, ptr nonnull @_ZTISt16invalid_argument, ptr nonnull @_ZNSt16invalid_argumentD1Ev) #5
  unreachable

10:                                               ; preds = %7
  %11 = landingpad { ptr, i32 }
          cleanup
  br label %20

12:                                               ; preds = %5
  %13 = icmp ugt i8 %3, 63
  br i1 %13, label %14, label %19

14:                                               ; preds = %12
  %15 = tail call ptr @__cxa_allocate_exception(i64 16) #4
  invoke void @_ZNSt16invalid_argumentC1EPKc(ptr noundef nonnull align 8 dereferenceable(16) %15, ptr noundef nonnull @.str.5)
          to label %16 unwind label %17

16:                                               ; preds = %14
  tail call void @__cxa_throw(ptr nonnull %15, ptr nonnull @_ZTISt16invalid_argument, ptr nonnull @_ZNSt16invalid_argumentD1Ev) #5
  unreachable

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

19:                                               ; preds = %6, %12, %4
  tail call void @_ZN4InsnC2ENS_4TypeEhh(ptr noundef nonnull align 4 dereferenceable(6) %0, i32 noundef %1, i8 noundef zeroext %2, i8 noundef zeroext %3)
  ret void

20:                                               ; preds = %17, %10
  %.sink = phi ptr [ %15, %17 ], [ %8, %10 ]
  %.pn = phi { ptr, i32 } [ %18, %17 ], [ %11, %10 ]
  tail call void @__cxa_free_exception(ptr %.sink) #4
  resume { ptr, i32 } %.pn
}

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


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