; LLVM IR from facebookresearch/habitat-sim :: src/deps/basis-universal/encoder (basisu_enc)

; 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.basisu::rand" = type { %"class.std::mersenne_twister_engine" }
%"class.std::mersenne_twister_engine" = type { [624 x i64], i64 }

; 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 uwtable
define dso_local void @_ZN6basisu29fill_buffer_with_random_bytesEPvmj(ptr noundef %0, i64 noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca %"class.basisu::rand", align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 5000, ptr %7) #2
  %9 = load i32, ptr %6, align 4, !tbaa !11
  call void @_ZN6basisu4randC2Ej(ptr noundef nonnull align 8 dereferenceable(5000) %7, i32 noundef %9)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %10, ptr %8, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %14, %3
  %12 = load i64, ptr %5, align 8, !tbaa !9
  %13 = icmp uge i64 %12, 4
  br i1 %13, label %14, label %21

14:                                               ; preds = %11
  %15 = call noundef i32 @_ZN6basisu4rand7urand32Ev(ptr noundef nonnull align 8 dereferenceable(5000) %7)
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %15, ptr %16, align 4, !tbaa !11
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 4
  store ptr %18, ptr %8, align 8, !tbaa !5
  %19 = load i64, ptr %5, align 8, !tbaa !9
  %20 = sub i64 %19, 4
  store i64 %20, ptr %5, align 8, !tbaa !9
  br label %11, !llvm.loop !13

21:                                               ; preds = %11
  br label %22

22:                                               ; preds = %25, %21
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %31

25:                                               ; preds = %22
  %26 = call noundef zeroext i8 @_ZN6basisu4rand4byteEv(ptr noundef nonnull align 8 dereferenceable(5000) %7)
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i32 1
  store ptr %28, ptr %8, align 8, !tbaa !5
  store i8 %26, ptr %27, align 1, !tbaa !15
  %29 = load i64, ptr %5, align 8, !tbaa !9
  %30 = add i64 %29, -1
  store i64 %30, ptr %5, align 8, !tbaa !9
  br label %22, !llvm.loop !16

31:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 5000, ptr %7) #2
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6basisu4randC2Ej(ptr noundef nonnull align 8 dereferenceable(5000), i32 noundef) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN6basisu4rand7urand32Ev(ptr noundef nonnull align 8 dereferenceable(5000)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i8 @_ZN6basisu4rand4byteEv(ptr noundef nonnull align 8 dereferenceable(5000)) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !14}


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

%"class.basisu::rand" = type { %"class.std::mersenne_twister_engine" }
%"class.std::mersenne_twister_engine" = type { [624 x i64], i64 }

; 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 uwtable
define dso_local void @_ZN6basisu29fill_buffer_with_random_bytesEPvmj(ptr nocapture noundef writeonly %0, i64 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca %"class.basisu::rand", align 8
  call void @llvm.lifetime.start.p0(i64 5000, ptr nonnull %4) #2
  call void @_ZN6basisu4randC2Ej(ptr noundef nonnull align 8 dereferenceable(5000) %4, i32 noundef %2)
  %5 = icmp ugt i64 %1, 3
  br i1 %5, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %3
  %.08.lcssa = phi i64 [ %1, %3 ], [ %8, %.lr.ph ]
  %.0.lcssa = phi ptr [ %0, %3 ], [ %7, %.lr.ph ]
  %.not13 = icmp eq i64 %.08.lcssa, 0
  br i1 %.not13, label %._crit_edge, label %.lr.ph16

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.011 = phi ptr [ %7, %.lr.ph ], [ %0, %3 ]
  %.0810 = phi i64 [ %8, %.lr.ph ], [ %1, %3 ]
  %6 = call noundef i32 @_ZN6basisu4rand7urand32Ev(ptr noundef nonnull align 8 dereferenceable(5000) %4)
  store i32 %6, ptr %.011, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %.011, i64 4
  %8 = add i64 %.0810, -4
  %9 = icmp ugt i64 %8, 3
  br i1 %9, label %.lr.ph, label %.preheader, !llvm.loop !9

.lr.ph16:                                         ; preds = %.preheader, %.lr.ph16
  %.115 = phi ptr [ %11, %.lr.ph16 ], [ %.0.lcssa, %.preheader ]
  %.1914 = phi i64 [ %12, %.lr.ph16 ], [ %.08.lcssa, %.preheader ]
  %10 = call noundef zeroext i8 @_ZN6basisu4rand4byteEv(ptr noundef nonnull align 8 dereferenceable(5000) %4)
  %11 = getelementptr inbounds i8, ptr %.115, i64 1
  store i8 %10, ptr %.115, align 1, !tbaa !11
  %12 = add nsw i64 %.1914, -1
  %.not = icmp eq i64 %12, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph16, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph16, %.preheader
  call void @llvm.lifetime.end.p0(i64 5000, ptr nonnull %4) #2
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6basisu4randC2Ej(ptr noundef nonnull align 8 dereferenceable(5000), i32 noundef) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN6basisu4rand7urand32Ev(ptr noundef nonnull align 8 dereferenceable(5000)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i8 @_ZN6basisu4rand4byteEv(ptr noundef nonnull align 8 dereferenceable(5000)) local_unnamed_addr #1 align 2

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


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