; LLVM IR from dynexcoin/Dynex :: src/Common (StringTools)

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN6Common7fromHexEcRh(i8 noundef signext, ptr noundef nonnull align 1 dereferenceable(1)) #1

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN6Common7fromHexERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPvmRm(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef %1, i64 noundef %2, ptr noundef nonnull align 8 dereferenceable(8) %3) #1 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i8, align 1
  %13 = alloca i8, align 1
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %14) #2
  %16 = and i64 %15, 1
  %17 = icmp ne i64 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %4
  store i1 false, ptr %5, align 1
  br label %76

19:                                               ; preds = %4
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %20) #2
  %22 = lshr i64 %21, 1
  %23 = load i64, ptr %8, align 8, !tbaa !9
  %24 = icmp ugt i64 %22, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %19
  store i1 false, ptr %5, align 1
  br label %76

26:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %66, %26
  %28 = load i64, ptr %10, align 8, !tbaa !9
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %29) #2
  %31 = lshr i64 %30, 1
  %32 = icmp ult i64 %28, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %27
  store i32 2, ptr %11, align 4
  br label %69

34:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #2
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load i64, ptr %10, align 8, !tbaa !9
  %37 = shl i64 %36, 1
  %38 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %35, i64 noundef %37) #2
  %39 = load i8, ptr %38, align 1, !tbaa !11
  %40 = call noundef zeroext i1 @_ZN6Common7fromHexEcRh(i8 noundef signext %39, ptr noundef nonnull align 1 dereferenceable(1) %12)
  br i1 %40, label %42, label %41

41:                                               ; preds = %34
  store i1 false, ptr %5, align 1
  store i32 1, ptr %11, align 4
  br label %63

42:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #2
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = load i64, ptr %10, align 8, !tbaa !9
  %45 = shl i64 %44, 1
  %46 = add i64 %45, 1
  %47 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %43, i64 noundef %46) #2
  %48 = load i8, ptr %47, align 1, !tbaa !11
  %49 = call noundef zeroext i1 @_ZN6Common7fromHexEcRh(i8 noundef signext %48, ptr noundef nonnull align 1 dereferenceable(1) %13)
  br i1 %49, label %51, label %50

50:                                               ; preds = %42
  store i1 false, ptr %5, align 1
  store i32 1, ptr %11, align 4
  br label %62

51:                                               ; preds = %42
  %52 = load i8, ptr %12, align 1, !tbaa !11
  %53 = zext i8 %52 to i32
  %54 = shl i32 %53, 4
  %55 = load i8, ptr %13, align 1, !tbaa !11
  %56 = zext i8 %55 to i32
  %57 = or i32 %54, %56
  %58 = trunc i32 %57 to i8
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load i64, ptr %10, align 8, !tbaa !9
  %61 = getelementptr inbounds i8, ptr %59, i64 %60
  store i8 %58, ptr %61, align 1, !tbaa !11
  store i32 0, ptr %11, align 4
  br label %62

62:                                               ; preds = %51, %50
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #2
  br label %63

63:                                               ; preds = %62, %41
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #2
  %64 = load i32, ptr %11, align 4
  switch i32 %64, label %69 [
    i32 0, label %65
  ]

65:                                               ; preds = %63
  br label %66

66:                                               ; preds = %65
  %67 = load i64, ptr %10, align 8, !tbaa !9
  %68 = add i64 %67, 1
  store i64 %68, ptr %10, align 8, !tbaa !9
  br label %27, !llvm.loop !12

69:                                               ; preds = %63, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %70 = load i32, ptr %11, align 4
  switch i32 %70, label %78 [
    i32 2, label %71
    i32 1, label %76
  ]

71:                                               ; preds = %69
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %72) #2
  %74 = lshr i64 %73, 1
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %74, ptr %75, align 8, !tbaa !9
  store i1 true, ptr %5, align 1
  br label %76

76:                                               ; preds = %71, %69, %25, %18
  %77 = load i1, ptr %5, align 1
  ret i1 %77

78:                                               ; preds = %69
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress nounwind uwtable
declare noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN6Common7fromHexEcRh(i8 noundef signext, ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN6Common7fromHexERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPvmRm(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr nocapture noundef writeonly %1, i64 noundef %2, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %3) local_unnamed_addr #1 {
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  %7 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #2
  %8 = and i64 %7, 1
  %.not = icmp eq i64 %8, 0
  br i1 %.not, label %9, label %.thread25

9:                                                ; preds = %4
  %10 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #2
  %11 = lshr i64 %10, 1
  %12 = icmp ugt i64 %11, %2
  br i1 %12, label %.thread25, label %.preheader

.preheader:                                       ; preds = %9
  %13 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #2
  %.not30 = icmp ult i64 %13, 2
  br i1 %.not30, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %24
  %.01629 = phi i64 [ %30, %24 ], [ 0, %.preheader ]
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %5) #2
  %14 = shl nuw i64 %.01629, 1
  %15 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %14) #2
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = call noundef zeroext i1 @_ZN6Common7fromHexEcRh(i8 noundef signext %16, ptr noundef nonnull align 1 dereferenceable(1) %5)
  br i1 %17, label %18, label %.thread

.thread:                                          ; preds = %.lr.ph
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %5) #2
  br label %.thread25

18:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %6) #2
  %19 = or disjoint i64 %14, 1
  %20 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %19) #2
  %21 = load i8, ptr %20, align 1, !tbaa !5
  %22 = call noundef zeroext i1 @_ZN6Common7fromHexEcRh(i8 noundef signext %21, ptr noundef nonnull align 1 dereferenceable(1) %6)
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %6) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %5) #2
  br label %.thread25

24:                                               ; preds = %18
  %25 = load i8, ptr %5, align 1, !tbaa !5
  %26 = shl i8 %25, 4
  %27 = load i8, ptr %6, align 1, !tbaa !5
  %28 = or i8 %26, %27
  %29 = getelementptr inbounds i8, ptr %1, i64 %.01629
  store i8 %28, ptr %29, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %6) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %5) #2
  %30 = add nuw nsw i64 %.01629, 1
  %31 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #2
  %32 = lshr i64 %31, 1
  %33 = icmp ult i64 %30, %32
  br i1 %33, label %.lr.ph, label %._crit_edge, !llvm.loop !8

._crit_edge:                                      ; preds = %24, %.preheader
  %34 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #2
  %35 = lshr i64 %34, 1
  store i64 %35, ptr %3, align 8, !tbaa !10
  br label %.thread25

.thread25:                                        ; preds = %.thread, %23, %9, %4, %._crit_edge
  %.4 = phi i1 [ true, %._crit_edge ], [ false, %4 ], [ false, %9 ], [ false, %23 ], [ false, %.thread ]
  ret i1 %.4
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !6, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass