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

; 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.Code = type { %"class.std::vector.0", %"class.std::vector.5", %"class.std::vector", i32, i32, i32, i32, [16 x i8], i32, i32, i32, %"class.std::__cxx11::basic_string", %"class.std::map" }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<Insn, std::allocator<Insn>>::_Vector_impl" }
%"struct.std::_Vector_base<Insn, std::allocator<Insn>>::_Vector_impl" = type { %"struct.std::_Vector_base<Insn, std::allocator<Insn>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Insn, std::allocator<Insn>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.5" = type { %"struct.std::_Vector_base.6" }
%"struct.std::_Vector_base.6" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon.13 }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon.13 = type { i64, [8 x i8] }
%"class.std::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<unsigned char, std::pair<const unsigned char, Sbox>, std::_Select1st<std::pair<const unsigned char, Sbox>>, std::less<unsigned char>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<unsigned char, std::pair<const unsigned char, Sbox>, std::_Select1st<std::pair<const unsigned char, Sbox>>, std::less<unsigned char>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIhSaIhEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #0 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt6vectorIhSaIhEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i8 @_ZN4Code13allocateSpareEb(ptr noundef nonnull align 8 dereferenceable(200) %0, i1 noundef zeroext %1) #0 align 2 {
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  %9 = zext i1 %1 to i8
  store i8 %9, ptr %5, align 1, !tbaa !9
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %11

11:                                               ; preds = %57, %2
  %12 = load i32, ptr %6, align 4, !tbaa !11
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds %class.Code, ptr %10, i32 0, i32 2
  %15 = call noundef i64 @_ZNKSt6vectorIhSaIhEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %14) #2
  %16 = icmp ult i64 %13, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %11
  store i32 2, ptr %7, align 4
  br label %60

18:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #2
  %19 = getelementptr inbounds %class.Code, ptr %10, i32 0, i32 2
  %20 = load i32, ptr %6, align 4, !tbaa !11
  %21 = zext i32 %20 to i64
  %22 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt6vectorIhSaIhEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %19, i64 noundef %21) #2
  %23 = load i8, ptr %22, align 1, !tbaa !13
  store i8 %23, ptr %8, align 1, !tbaa !13
  %24 = getelementptr inbounds %class.Code, ptr %10, i32 0, i32 3
  %25 = load i32, ptr %24, align 8, !tbaa !14
  %26 = load i8, ptr %8, align 1, !tbaa !13
  %27 = zext i8 %26 to i32
  %28 = shl i32 1, %27
  %29 = and i32 %25, %28
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %18
  store i32 4, ptr %7, align 4
  br label %55

32:                                               ; preds = %18
  %33 = load i8, ptr %5, align 1, !tbaa !9, !range !40, !noundef !41
  %34 = trunc i8 %33 to i1
  br i1 %34, label %35, label %40

35:                                               ; preds = %32
  %36 = load i8, ptr %8, align 1, !tbaa !13
  %37 = zext i8 %36 to i32
  %38 = icmp slt i32 %37, 16
  br i1 %38, label %39, label %40

39:                                               ; preds = %35
  store i32 4, ptr %7, align 4
  br label %55

40:                                               ; preds = %35, %32
  %41 = load i8, ptr %8, align 1, !tbaa !13
  %42 = zext i8 %41 to i32
  %43 = shl i32 1, %42
  %44 = getelementptr inbounds %class.Code, ptr %10, i32 0, i32 3
  %45 = load i32, ptr %44, align 8, !tbaa !14
  %46 = or i32 %45, %43
  store i32 %46, ptr %44, align 8, !tbaa !14
  %47 = load i8, ptr %8, align 1, !tbaa !13
  %48 = zext i8 %47 to i32
  %49 = shl i32 1, %48
  %50 = xor i32 %49, -1
  %51 = getelementptr inbounds %class.Code, ptr %10, i32 0, i32 5
  %52 = load i32, ptr %51, align 8, !tbaa !42
  %53 = and i32 %52, %50
  store i32 %53, ptr %51, align 8, !tbaa !42
  %54 = load i8, ptr %8, align 1, !tbaa !13
  store i8 %54, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %55

55:                                               ; preds = %40, %39, %31
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #2
  %56 = load i32, ptr %7, align 4
  switch i32 %56, label %60 [
    i32 4, label %57
  ]

57:                                               ; preds = %55
  %58 = load i32, ptr %6, align 4, !tbaa !11
  %59 = add i32 %58, 1
  store i32 %59, ptr %6, align 4, !tbaa !11
  br label %11, !llvm.loop !43

60:                                               ; preds = %55, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %61 = load i32, ptr %7, align 4
  switch i32 %61, label %65 [
    i32 2, label %62
    i32 1, label %63
  ]

62:                                               ; preds = %60
  store i8 -1, ptr %3, align 1
  br label %63

63:                                               ; preds = %62, %60
  %64 = load i8, ptr %3, align 1
  ret i8 %64

65:                                               ; preds = %60
  unreachable
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind }

!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 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !12, i64 72}
!15 = !{!"_ZTS4Code", !16, i64 0, !20, i64 24, !24, i64 48, !12, i64 72, !12, i64 76, !12, i64 80, !12, i64 84, !7, i64 88, !12, i64 104, !28, i64 108, !12, i64 112, !29, i64 120, !32, i64 152}
!16 = !{!"_ZTSSt6vectorI4InsnSaIS0_EE", !17, i64 0}
!17 = !{!"_ZTSSt12_Vector_baseI4InsnSaIS0_EE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseI4InsnSaIS0_EE12_Vector_implE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseI4InsnSaIS0_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!20 = !{!"_ZTSSt6vectorIiSaIiEE", !21, i64 0}
!21 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !22, i64 0}
!22 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !23, i64 0}
!23 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!24 = !{!"_ZTSSt6vectorIhSaIhEE", !25, i64 0}
!25 = !{!"_ZTSSt12_Vector_baseIhSaIhEE", !26, i64 0}
!26 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE12_Vector_implE", !27, i64 0}
!27 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!28 = !{!"_ZTSN4Code12PrologueTypeE", !7, i64 0}
!29 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !30, i64 0, !31, i64 8, !7, i64 16}
!30 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!31 = !{!"long", !7, i64 0}
!32 = !{!"_ZTSSt3mapIh4SboxSt4lessIhESaISt4pairIKhS0_EEE", !33, i64 0}
!33 = !{!"_ZTSSt8_Rb_treeIhSt4pairIKh4SboxESt10_Select1stIS3_ESt4lessIhESaIS3_EE", !34, i64 0}
!34 = !{!"_ZTSNSt8_Rb_treeIhSt4pairIKh4SboxESt10_Select1stIS3_ESt4lessIhESaIS3_EE13_Rb_tree_implIS7_Lb1EEE", !35, i64 0, !37, i64 8}
!35 = !{!"_ZTSSt20_Rb_tree_key_compareISt4lessIhEE", !36, i64 0}
!36 = !{!"_ZTSSt4lessIhE"}
!37 = !{!"_ZTSSt15_Rb_tree_header", !38, i64 0, !31, i64 32}
!38 = !{!"_ZTSSt18_Rb_tree_node_base", !39, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!39 = !{!"_ZTSSt14_Rb_tree_color", !7, i64 0}
!40 = !{i8 0, i8 2}
!41 = !{}
!42 = !{!15, !12, i64 80}
!43 = distinct !{!43, !44}
!44 = !{!"llvm.loop.mustprogress"}


; 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 nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIhSaIhEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt6vectorIhSaIhEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i8 @_ZN4Code13allocateSpareEb(ptr noundef nonnull align 8 dereferenceable(200) %0, i1 noundef zeroext %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 48
  %4 = tail call noundef i64 @_ZNKSt6vectorIhSaIhEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %3) #1
  %.not2327.not = icmp eq i64 %4, 0
  br i1 %.not2327.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 72
  br label %10

6:                                                ; preds = %10
  %7 = add i32 %.01628, 1
  %8 = zext i32 %7 to i64
  %9 = tail call noundef i64 @_ZNKSt6vectorIhSaIhEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %3) #1
  %.not23 = icmp ugt i64 %9, %8
  br i1 %.not23, label %10, label %.loopexit, !llvm.loop !5

10:                                               ; preds = %.lr.ph, %6
  %11 = phi i64 [ 0, %.lr.ph ], [ %8, %6 ]
  %.01628 = phi i32 [ 0, %.lr.ph ], [ %7, %6 ]
  %12 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt6vectorIhSaIhEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %11) #1
  %13 = load i8, ptr %12, align 1, !tbaa !7
  %14 = load i32, ptr %5, align 8, !tbaa !10
  %15 = zext nneg i8 %13 to i32
  %16 = shl nuw i32 1, %15
  %17 = and i32 %16, %14
  %.not = icmp ne i32 %17, 0
  %18 = icmp ult i8 %13, 16
  %or.cond = and i1 %18, %1
  %or.cond18 = or i1 %or.cond, %.not
  br i1 %or.cond18, label %6, label %19

19:                                               ; preds = %10
  %20 = or i32 %16, %14
  store i32 %20, ptr %5, align 8, !tbaa !10
  %21 = xor i32 %16, -1
  %22 = getelementptr inbounds i8, ptr %0, i64 80
  %23 = load i32, ptr %22, align 8, !tbaa !38
  %24 = and i32 %23, %21
  store i32 %24, ptr %22, align 8, !tbaa !38
  br label %.loopexit

.loopexit:                                        ; preds = %6, %2, %19
  %spec.select = phi i8 [ %13, %19 ], [ -1, %2 ], [ -1, %6 ]
  ret i8 %spec.select
}

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 = { nounwind }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !25, i64 72}
!11 = !{!"_ZTS4Code", !12, i64 0, !17, i64 24, !21, i64 48, !25, i64 72, !25, i64 76, !25, i64 80, !25, i64 84, !8, i64 88, !25, i64 104, !26, i64 108, !25, i64 112, !27, i64 120, !30, i64 152}
!12 = !{!"_ZTSSt6vectorI4InsnSaIS0_EE", !13, i64 0}
!13 = !{!"_ZTSSt12_Vector_baseI4InsnSaIS0_EE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseI4InsnSaIS0_EE12_Vector_implE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseI4InsnSaIS0_EE17_Vector_impl_dataE", !16, i64 0, !16, i64 8, !16, i64 16}
!16 = !{!"any pointer", !8, i64 0}
!17 = !{!"_ZTSSt6vectorIiSaIiEE", !18, i64 0}
!18 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !16, i64 0, !16, i64 8, !16, i64 16}
!21 = !{!"_ZTSSt6vectorIhSaIhEE", !22, i64 0}
!22 = !{!"_ZTSSt12_Vector_baseIhSaIhEE", !23, i64 0}
!23 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE12_Vector_implE", !24, i64 0}
!24 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE17_Vector_impl_dataE", !16, i64 0, !16, i64 8, !16, i64 16}
!25 = !{!"int", !8, i64 0}
!26 = !{!"_ZTSN4Code12PrologueTypeE", !8, i64 0}
!27 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !28, i64 0, !29, i64 8, !8, i64 16}
!28 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !16, i64 0}
!29 = !{!"long", !8, i64 0}
!30 = !{!"_ZTSSt3mapIh4SboxSt4lessIhESaISt4pairIKhS0_EEE", !31, i64 0}
!31 = !{!"_ZTSSt8_Rb_treeIhSt4pairIKh4SboxESt10_Select1stIS3_ESt4lessIhESaIS3_EE", !32, i64 0}
!32 = !{!"_ZTSNSt8_Rb_treeIhSt4pairIKh4SboxESt10_Select1stIS3_ESt4lessIhESaIS3_EE13_Rb_tree_implIS7_Lb1EEE", !33, i64 0, !35, i64 8}
!33 = !{!"_ZTSSt20_Rb_tree_key_compareISt4lessIhEE", !34, i64 0}
!34 = !{!"_ZTSSt4lessIhE"}
!35 = !{!"_ZTSSt15_Rb_tree_header", !36, i64 0, !29, i64 32}
!36 = !{!"_ZTSSt18_Rb_tree_node_base", !37, i64 0, !16, i64 8, !16, i64 16, !16, i64 24}
!37 = !{!"_ZTSSt14_Rb_tree_color", !8, i64 0}
!38 = !{!11, !25, i64 80}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass