; LLVM IR from trustwallet/wallet-core :: src/FIO/Actor.ll (ZN2TW3FIO5Actor10shortenKeyERKSt5arrayIhLm37EE)

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

@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [75 x i8], align 1
@__PRETTY_FUNCTION__._ZN2TW3FIO5Actor10shortenKeyERKSt5arrayIhLm37EE = external hidden unnamed_addr constant [84 x i8], align 1

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

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

9:                                                ; preds = %59, %57, %1
  %10 = load i32, ptr %5, align 4, !tbaa !11
  %11 = icmp sle i32 %10, 12
  br i1 %11, label %12, label %60

12:                                               ; preds = %9
  %13 = load i32, ptr %4, align 4, !tbaa !11
  %14 = icmp slt i32 %13, 33
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  br label %18

16:                                               ; preds = %12
  call void @__assert_fail(ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 29, ptr noundef @__PRETTY_FUNCTION__._ZN2TW3FIO5Actor10shortenKeyERKSt5arrayIhLm37EE) #4
  unreachable

17:                                               ; No predecessors!
  br label %18

18:                                               ; preds = %17, %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = load i32, ptr %4, align 4, !tbaa !11
  %21 = sext i32 %20 to i64
  %22 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt5arrayIhLm37EEixEm(ptr noundef nonnull align 1 dereferenceable(37) %19, i64 noundef %21) #3
  %23 = load i8, ptr %22, align 1, !tbaa !13
  %24 = zext i8 %23 to i32
  %25 = load i32, ptr %5, align 4, !tbaa !11
  %26 = icmp eq i32 %25, 12
  %27 = zext i1 %26 to i64
  %28 = select i1 %26, i32 15, i32 31
  %29 = and i32 %24, %28
  %30 = sext i32 %29 to i64
  store i64 %30, ptr %6, align 8, !tbaa !9
  %31 = load i64, ptr %6, align 8, !tbaa !9
  %32 = icmp eq i64 %31, 0
  br i1 %32, label %33, label %36

33:                                               ; preds = %18
  %34 = load i32, ptr %4, align 4, !tbaa !11
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %4, align 4, !tbaa !11
  store i32 2, ptr %7, align 4
  br label %57, !llvm.loop !14

36:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %37 = load i32, ptr %5, align 4, !tbaa !11
  %38 = icmp eq i32 %37, 12
  br i1 %38, label %39, label %40

39:                                               ; preds = %36
  br label %45

40:                                               ; preds = %36
  %41 = load i32, ptr %5, align 4, !tbaa !11
  %42 = sub nsw i32 12, %41
  %43 = mul nsw i32 5, %42
  %44 = sub nsw i32 %43, 1
  br label %45

45:                                               ; preds = %40, %39
  %46 = phi i32 [ 0, %39 ], [ %44, %40 ]
  store i32 %46, ptr %8, align 4, !tbaa !11
  %47 = load i64, ptr %6, align 8, !tbaa !9
  %48 = load i32, ptr %8, align 4, !tbaa !11
  %49 = zext i32 %48 to i64
  %50 = shl i64 %47, %49
  %51 = load i64, ptr %3, align 8, !tbaa !9
  %52 = or i64 %51, %50
  store i64 %52, ptr %3, align 8, !tbaa !9
  %53 = load i32, ptr %5, align 4, !tbaa !11
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %5, align 4, !tbaa !11
  %55 = load i32, ptr %4, align 4, !tbaa !11
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %4, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  store i32 0, ptr %7, align 4
  br label %57

57:                                               ; preds = %45, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %58 = load i32, ptr %7, align 4
  switch i32 %58, label %62 [
    i32 0, label %59
    i32 2, label %9
  ]

59:                                               ; preds = %57
  br label %9, !llvm.loop !14

60:                                               ; preds = %9
  %61 = load i64, ptr %3, align 8, !tbaa !9
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i64 %61

62:                                               ; preds = %57
  unreachable
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt5arrayIhLm37EEixEm(ptr noundef nonnull align 1 dereferenceable(37), i64 noundef) #1 align 2

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 = { 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 #3 = { nounwind }
attributes #4 = { noreturn 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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [75 x i8], align 1
@__PRETTY_FUNCTION__._ZN2TW3FIO5Actor10shortenKeyERKSt5arrayIhLm37EE = external hidden unnamed_addr constant [84 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_ZN2TW3FIO5Actor10shortenKeyERKSt5arrayIhLm37EE(ptr noundef nonnull align 1 dereferenceable(37) %0) local_unnamed_addr #0 align 2 {
  br label %2

2:                                                ; preds = %1, %21
  %indvars.iv = phi i64 [ 1, %1 ], [ %indvars.iv.next, %21 ]
  %.022 = phi i64 [ 0, %1 ], [ %.1, %21 ]
  %.01620 = phi i32 [ 0, %1 ], [ %.117, %21 ]
  %exitcond.not = icmp eq i64 %indvars.iv, 33
  br i1 %exitcond.not, label %3, label %4

3:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef 29, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN2TW3FIO5Actor10shortenKeyERKSt5arrayIhLm37EE) #2
  unreachable

4:                                                ; preds = %2
  %5 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt5arrayIhLm37EEixEm(ptr noundef nonnull align 1 dereferenceable(37) %0, i64 noundef %indvars.iv) #3
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %7 = zext i8 %6 to i64
  %8 = icmp eq i32 %.01620, 12
  %9 = select i1 %8, i64 15, i64 31
  %10 = and i64 %9, %7
  %11 = icmp eq i64 %10, 0
  br i1 %11, label %21, label %12, !llvm.loop !8

12:                                               ; preds = %4
  %13 = sub nsw i32 12, %.01620
  %14 = mul nsw i32 %13, 5
  %15 = add nsw i32 %14, -1
  %16 = select i1 %8, i32 0, i32 %15
  %17 = zext nneg i32 %16 to i64
  %18 = shl i64 %10, %17
  %19 = or i64 %18, %.022
  %20 = add nsw i32 %.01620, 1
  br label %21

21:                                               ; preds = %4, %12
  %.117 = phi i32 [ %20, %12 ], [ %.01620, %4 ]
  %.1 = phi i64 [ %19, %12 ], [ %.022, %4 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %22 = icmp slt i32 %.117, 13
  br i1 %22, label %2, label %23

23:                                               ; preds = %21
  ret i64 %.1
}

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

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

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 = { 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 #2 = { noreturn nounwind }
attributes #3 = { 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"}


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