; LLVM IR from facebook/redex :: liblocator/locator.ll (ZN8facebook7Locator22encodeGlobalClassIndexEjmPc)

; 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.4 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [54 x i8], align 1
@__PRETTY_FUNCTION__._ZN8facebook7Locator22encodeGlobalClassIndexEjmPc = external hidden unnamed_addr constant [80 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [67 x i8], align 1

declare i32 @__gxx_personality_v0(...)

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

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

; 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
define dso_local void @_ZN8facebook7Locator22encodeGlobalClassIndexEjmPc(i32 noundef %0, i64 noundef %1, ptr noundef %2) #2 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !11
  %10 = load i64, ptr %5, align 8, !tbaa !9
  %11 = icmp ugt i64 %10, 0
  br i1 %11, label %12, label %15

12:                                               ; preds = %3
  %13 = load i64, ptr %5, align 8, !tbaa !9
  %14 = icmp ule i64 %13, 6
  br label %15

15:                                               ; preds = %12, %3
  %16 = phi i1 [ false, %3 ], [ %14, %12 ]
  br i1 %16, label %17, label %18

17:                                               ; preds = %15
  br label %20

18:                                               ; preds = %15
  call void @__assert_fail(ptr noundef @.str.7, ptr noundef @.str.4, i32 noundef 67, ptr noundef @__PRETTY_FUNCTION__._ZN8facebook7Locator22encodeGlobalClassIndexEjmPc) #4
  unreachable

19:                                               ; No predecessors!
  br label %20

20:                                               ; preds = %19, %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %21 = load ptr, ptr %6, align 8, !tbaa !11
  store ptr %21, ptr %7, align 8, !tbaa !11
  %22 = load ptr, ptr %7, align 8, !tbaa !11
  %23 = getelementptr inbounds i8, ptr %22, i32 1
  store ptr %23, ptr %7, align 8, !tbaa !11
  store i8 76, ptr %22, align 1, !tbaa !13
  %24 = load ptr, ptr %7, align 8, !tbaa !11
  %25 = getelementptr inbounds i8, ptr %24, i32 1
  store ptr %25, ptr %7, align 8, !tbaa !11
  store i8 88, ptr %24, align 1, !tbaa !13
  %26 = load ptr, ptr %7, align 8, !tbaa !11
  %27 = getelementptr inbounds i8, ptr %26, i32 1
  store ptr %27, ptr %7, align 8, !tbaa !11
  store i8 47, ptr %26, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %28 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %28, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %29 = load ptr, ptr %7, align 8, !tbaa !11
  %30 = load i64, ptr %5, align 8, !tbaa !9
  %31 = getelementptr inbounds i8, ptr %29, i64 %30
  store ptr %31, ptr %9, align 8, !tbaa !11
  br label %32

32:                                               ; preds = %41, %20
  %33 = load i32, ptr %8, align 4, !tbaa !5
  %34 = urem i32 %33, 62
  %35 = invoke noundef signext i8 @_ZN8facebookL8getDigitEj(i32 noundef %34)
          to label %36 unwind label %70

36:                                               ; preds = %32
  %37 = load ptr, ptr %9, align 8, !tbaa !11
  %38 = getelementptr inbounds i8, ptr %37, i32 -1
  store ptr %38, ptr %9, align 8, !tbaa !11
  store i8 %35, ptr %38, align 1, !tbaa !13
  %39 = load i32, ptr %8, align 4, !tbaa !5
  %40 = udiv i32 %39, 62
  store i32 %40, ptr %8, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %36
  %42 = load ptr, ptr %9, align 8, !tbaa !11
  %43 = load ptr, ptr %7, align 8, !tbaa !11
  %44 = icmp ne ptr %42, %43
  br i1 %44, label %32, label %45, !llvm.loop !14

45:                                               ; preds = %41
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %49

48:                                               ; preds = %45
  br label %51

49:                                               ; preds = %45
  call void @__assert_fail(ptr noundef @.str.8, ptr noundef @.str.4, i32 noundef 80, ptr noundef @__PRETTY_FUNCTION__._ZN8facebook7Locator22encodeGlobalClassIndexEjmPc) #4
  unreachable

50:                                               ; No predecessors!
  br label %51

51:                                               ; preds = %50, %48
  %52 = load i64, ptr %5, align 8, !tbaa !9
  %53 = load ptr, ptr %7, align 8, !tbaa !11
  %54 = getelementptr inbounds i8, ptr %53, i64 %52
  store ptr %54, ptr %7, align 8, !tbaa !11
  %55 = load ptr, ptr %7, align 8, !tbaa !11
  %56 = getelementptr inbounds i8, ptr %55, i32 1
  store ptr %56, ptr %7, align 8, !tbaa !11
  store i8 59, ptr %55, align 1, !tbaa !13
  %57 = load ptr, ptr %7, align 8, !tbaa !11
  %58 = getelementptr inbounds i8, ptr %57, i32 1
  store ptr %58, ptr %7, align 8, !tbaa !11
  store i8 0, ptr %57, align 1, !tbaa !13
  %59 = load ptr, ptr %7, align 8, !tbaa !11
  %60 = load ptr, ptr %6, align 8, !tbaa !11
  %61 = ptrtoint ptr %59 to i64
  %62 = ptrtoint ptr %60 to i64
  %63 = sub i64 %61, %62
  %64 = trunc i64 %63 to i32
  %65 = icmp ule i32 %64, 11
  br i1 %65, label %66, label %67

66:                                               ; preds = %51
  br label %69

67:                                               ; preds = %51
  call void @__assert_fail(ptr noundef @.str.9, ptr noundef @.str.4, i32 noundef 86, ptr noundef @__PRETTY_FUNCTION__._ZN8facebook7Locator22encodeGlobalClassIndexEjmPc) #4
  unreachable

68:                                               ; No predecessors!
  br label %69

69:                                               ; preds = %68, %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret void

70:                                               ; preds = %32
  %71 = landingpad { ptr, i32 }
          catch ptr null
  %72 = extractvalue { ptr, i32 } %71, 0
  call void @__clang_call_terminate(ptr %72) #4
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef signext i8 @_ZN8facebookL8getDigitEj(i32 noundef) #2

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { noinline noreturn nounwind uwtable "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 = { noreturn nounwind }
attributes #5 = { 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 = !{!"int", !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 = !{!"any pointer", !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.4 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [54 x i8], align 1
@__PRETTY_FUNCTION__._ZN8facebook7Locator22encodeGlobalClassIndexEjmPc = external hidden unnamed_addr constant [80 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [67 x i8], align 1

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN8facebook7Locator22encodeGlobalClassIndexEjmPc(i32 noundef %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %4 = add i64 %1, -1
  %5 = icmp ult i64 %4, 6
  br i1 %5, label %7, label %6

6:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.4, i32 noundef 67, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN8facebook7Locator22encodeGlobalClassIndexEjmPc) #2
  unreachable

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %2, i64 1
  store i8 76, ptr %2, align 1, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %2, i64 2
  store i8 88, ptr %8, align 1, !tbaa !5
  store i8 47, ptr %9, align 1, !tbaa !5
  %.add = add nuw nsw i64 %1, 3
  br label %10

10:                                               ; preds = %10, %7
  %.020 = phi i32 [ %0, %7 ], [ %13, %10 ]
  %.0.idx = phi i64 [ %.add, %7 ], [ %.0.add, %10 ]
  %11 = urem i32 %.020, 62
  %12 = tail call noundef signext i8 @_ZN8facebookL8getDigitEj(i32 noundef %11)
  %.0.add = add nsw i64 %.0.idx, -1
  %.ptr = getelementptr inbounds i8, ptr %2, i64 %.0.add
  store i8 %12, ptr %.ptr, align 1, !tbaa !5
  %13 = udiv i32 %.020, 62
  %.not = icmp eq i64 %.0.add, 3
  br i1 %.not, label %14, label %10, !llvm.loop !8

14:                                               ; preds = %10
  %15 = icmp ult i32 %.020, 62
  br i1 %15, label %17, label %16

16:                                               ; preds = %14
  tail call void @__assert_fail(ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.4, i32 noundef 80, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN8facebook7Locator22encodeGlobalClassIndexEjmPc) #2
  unreachable

17:                                               ; preds = %14
  %.ptr23 = getelementptr inbounds i8, ptr %2, i64 %.add
  %18 = getelementptr inbounds i8, ptr %.ptr23, i64 1
  store i8 59, ptr %.ptr23, align 1, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %.ptr23, i64 2
  store i8 0, ptr %18, align 1, !tbaa !5
  %20 = ptrtoint ptr %19 to i64
  %21 = ptrtoint ptr %2 to i64
  %22 = sub i64 %20, %21
  %23 = trunc i64 %22 to i32
  %24 = icmp ult i32 %23, 12
  br i1 %24, label %26, label %25

25:                                               ; preds = %17
  tail call void @__assert_fail(ptr noundef nonnull @.str.9, ptr noundef nonnull @.str.4, i32 noundef 86, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN8facebook7Locator22encodeGlobalClassIndexEjmPc) #2
  unreachable

26:                                               ; preds = %17
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef signext i8 @_ZN8facebookL8getDigitEj(i32 noundef) local_unnamed_addr #1

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 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 }

!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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass