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

; 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.facebook::Locator" = type { i32, i32, i32 }

@.str.3 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [71 x i8], align 1
@__PRETTY_FUNCTION__._ZN8facebook7Locator6encodeEPc = external hidden unnamed_addr constant [43 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN8facebook7Locator6encodeEPc(ptr noundef nonnull align 4 dereferenceable(12) %0, ptr noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %10 = getelementptr inbounds %"class.facebook::Locator", ptr %9, i32 0, i32 0
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = zext i32 %11 to i64
  %13 = shl i64 %12, 20
  store i64 %13, ptr %5, align 8, !tbaa !12
  %14 = load i64, ptr %5, align 8, !tbaa !12
  %15 = getelementptr inbounds %"class.facebook::Locator", ptr %9, i32 0, i32 2
  %16 = load i32, ptr %15, align 4, !tbaa !14
  %17 = zext i32 %16 to i64
  %18 = or i64 %14, %17
  %19 = shl i64 %18, 6
  store i64 %19, ptr %5, align 8, !tbaa !12
  %20 = load i64, ptr %5, align 8, !tbaa !12
  %21 = getelementptr inbounds %"class.facebook::Locator", ptr %9, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !15
  %23 = zext i32 %22 to i64
  %24 = or i64 %20, %23
  store i64 %24, ptr %5, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 0
  store ptr %26, ptr %6, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %49, %2
  %28 = load i64, ptr %5, align 8, !tbaa !12
  %29 = icmp ne i64 %28, 0
  br i1 %29, label %30, label %55

30:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  %31 = load i64, ptr %5, align 8, !tbaa !12
  %32 = urem i64 %31, 94
  %33 = add i64 %32, 33
  %34 = trunc i64 %33 to i8
  store i8 %34, ptr %7, align 1, !tbaa !16
  %35 = load i8, ptr %7, align 1, !tbaa !16
  %36 = zext i8 %35 to i32
  %37 = and i32 %36, 128
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %30
  br label %42

40:                                               ; preds = %30
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.4, i32 noundef 41, ptr noundef @__PRETTY_FUNCTION__._ZN8facebook7Locator6encodeEPc) #4
  unreachable

41:                                               ; No predecessors!
  br label %42

42:                                               ; preds = %41, %39
  %43 = load i8, ptr %7, align 1, !tbaa !16
  %44 = zext i8 %43 to i32
  %45 = icmp uge i32 %44, 33
  br i1 %45, label %46, label %47

46:                                               ; preds = %42
  br label %49

47:                                               ; preds = %42
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.4, i32 noundef 42, ptr noundef @__PRETTY_FUNCTION__._ZN8facebook7Locator6encodeEPc) #4
  unreachable

48:                                               ; No predecessors!
  br label %49

49:                                               ; preds = %48, %46
  %50 = load i8, ptr %7, align 1, !tbaa !16
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i32 1
  store ptr %52, ptr %6, align 8, !tbaa !5
  store i8 %50, ptr %51, align 1, !tbaa !16
  %53 = load i64, ptr %5, align 8, !tbaa !12
  %54 = udiv i64 %53, 94
  store i64 %54, ptr %5, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  br label %27, !llvm.loop !17

55:                                               ; preds = %27
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  store i8 0, ptr %56, align 1, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = ptrtoint ptr %57 to i64
  %60 = ptrtoint ptr %58 to i64
  %61 = sub i64 %59, %60
  %62 = trunc i64 %61 to i32
  store i32 %62, ptr %8, align 4, !tbaa !19
  %63 = load i32, ptr %8, align 4, !tbaa !19
  %64 = icmp ule i32 %63, 8
  br i1 %64, label %65, label %66

65:                                               ; preds = %55
  br label %68

66:                                               ; preds = %55
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.4, i32 noundef 48, ptr noundef @__PRETTY_FUNCTION__._ZN8facebook7Locator6encodeEPc) #4
  unreachable

67:                                               ; No predecessors!
  br label %68

68:                                               ; preds = %67, %65
  %69 = load i32, ptr %8, align 4, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i32 %69
}

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

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

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

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 = { 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, !11, i64 0}
!10 = !{!"_ZTSN8facebook7LocatorE", !11, i64 0, !11, i64 4, !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!10, !11, i64 8}
!15 = !{!10, !11, i64 4}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!11, !11, 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"

@.str.4 = external hidden unnamed_addr constant [71 x i8], align 1
@__PRETTY_FUNCTION__._ZN8facebook7Locator6encodeEPc = external hidden unnamed_addr constant [43 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 0, 9) i32 @_ZN8facebook7Locator6encodeEPc(ptr nocapture noundef nonnull readonly align 4 dereferenceable(12) %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  %3 = load i32, ptr %0, align 4, !tbaa !5
  %4 = zext i32 %3 to i64
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 4, !tbaa !10
  %7 = zext i32 %6 to i64
  %8 = shl nuw nsw i64 %4, 26
  %9 = shl nuw nsw i64 %7, 6
  %10 = or i64 %9, %8
  %11 = getelementptr inbounds i8, ptr %0, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = zext i32 %12 to i64
  %14 = or i64 %10, %13
  %.not17 = icmp eq i64 %14, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.019 = phi i64 [ %19, %.lr.ph ], [ %14, %2 ]
  %.01518 = phi ptr [ %18, %.lr.ph ], [ %1, %2 ]
  %15 = urem i64 %.019, 94
  %16 = trunc nuw nsw i64 %15 to i8
  %17 = add nuw nsw i8 %16, 33
  %18 = getelementptr inbounds i8, ptr %.01518, i64 1
  store i8 %17, ptr %.01518, align 1, !tbaa !12
  %19 = udiv i64 %.019, 94
  %.not = icmp ult i64 %.019, 94
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.015.lcssa = phi ptr [ %1, %2 ], [ %18, %.lr.ph ]
  store i8 0, ptr %.015.lcssa, align 1, !tbaa !12
  %20 = ptrtoint ptr %.015.lcssa to i64
  %21 = ptrtoint ptr %1 to i64
  %22 = sub i64 %20, %21
  %23 = trunc i64 %22 to i32
  %24 = icmp ult i32 %23, 9
  br i1 %24, label %26, label %25

25:                                               ; preds = %._crit_edge
  tail call void @__assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.4, i32 noundef 48, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN8facebook7Locator6encodeEPc) #2
  unreachable

26:                                               ; preds = %._crit_edge
  ret i32 %23
}

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

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 }

!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, !7, i64 0}
!6 = !{!"_ZTSN8facebook7LocatorE", !7, i64 0, !7, i64 4, !7, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!6, !7, i64 4}
!12 = !{!8, !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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