; LLVM IR from qc-tum/chemtensor :: src/util (rng)

; 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 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [66 x i8], align 1
@__PRETTY_FUNCTION__.rand_choice = external hidden unnamed_addr constant [81 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @rand_interval(i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @rand_choice(i64 noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i8, align 1
  %14 = alloca i16, align 2
  store i64 %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  %15 = load i64, ptr %6, align 8, !tbaa !5
  %16 = load i64, ptr %5, align 8, !tbaa !5
  %17 = icmp ule i64 %15, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %4
  br label %20

19:                                               ; preds = %4
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 66, ptr noundef @__PRETTY_FUNCTION__.rand_choice) #3
  unreachable

20:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 0, ptr %9, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %69, %20
  %22 = load i64, ptr %9, align 8, !tbaa !5
  %23 = load i64, ptr %6, align 8, !tbaa !5
  %24 = icmp ult i64 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %72

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %27 = load i64, ptr %5, align 8, !tbaa !5
  %28 = load i64, ptr %6, align 8, !tbaa !5
  %29 = sub i64 %27, %28
  %30 = add i64 %29, 1
  %31 = load i64, ptr %9, align 8, !tbaa !5
  %32 = add i64 %30, %31
  store i64 %32, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %33 = load i64, ptr %11, align 8, !tbaa !5
  %34 = load ptr, ptr %7, align 8, !tbaa !9
  %35 = call i64 @rand_interval(i64 noundef %33, ptr noundef %34)
  store i64 %35, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #4
  store i8 0, ptr %13, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 2, ptr %14) #4
  store i16 0, ptr %14, align 2, !tbaa !13
  br label %36

36:                                               ; preds = %52, %26
  %37 = load i16, ptr %14, align 2, !tbaa !13
  %38 = zext i16 %37 to i64
  %39 = load i64, ptr %9, align 8, !tbaa !5
  %40 = icmp ult i64 %38, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %36
  store i32 5, ptr %10, align 4
  br label %55

42:                                               ; preds = %36
  %43 = load ptr, ptr %8, align 8, !tbaa !9
  %44 = load i16, ptr %14, align 2, !tbaa !13
  %45 = zext i16 %44 to i64
  %46 = getelementptr inbounds i64, ptr %43, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !5
  %48 = load i64, ptr %12, align 8, !tbaa !5
  %49 = icmp eq i64 %47, %48
  br i1 %49, label %50, label %51

50:                                               ; preds = %42
  store i8 1, ptr %13, align 1, !tbaa !11
  store i32 5, ptr %10, align 4
  br label %55

51:                                               ; preds = %42
  br label %52

52:                                               ; preds = %51
  %53 = load i16, ptr %14, align 2, !tbaa !13
  %54 = add i16 %53, 1
  store i16 %54, ptr %14, align 2, !tbaa !13
  br label %36, !llvm.loop !15

55:                                               ; preds = %50, %41
  call void @llvm.lifetime.end.p0(i64 2, ptr %14) #4
  br label %56

56:                                               ; preds = %55
  %57 = load i8, ptr %13, align 1, !tbaa !11, !range !17, !noundef !18
  %58 = trunc i8 %57 to i1
  br i1 %58, label %59, label %62

59:                                               ; preds = %56
  %60 = load i64, ptr %11, align 8, !tbaa !5
  %61 = sub i64 %60, 1
  br label %64

62:                                               ; preds = %56
  %63 = load i64, ptr %12, align 8, !tbaa !5
  br label %64

64:                                               ; preds = %62, %59
  %65 = phi i64 [ %61, %59 ], [ %63, %62 ]
  %66 = load ptr, ptr %8, align 8, !tbaa !9
  %67 = load i64, ptr %9, align 8, !tbaa !5
  %68 = getelementptr inbounds i64, ptr %66, i64 %67
  store i64 %65, ptr %68, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %69

69:                                               ; preds = %64
  %70 = load i64, ptr %9, align 8, !tbaa !5
  %71 = add i64 %70, 1
  store i64 %71, ptr %9, align 8, !tbaa !5
  br label %21, !llvm.loop !19

72:                                               ; preds = %25
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { noreturn nounwind }
attributes #4 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = distinct !{!19, !16}


; 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 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [66 x i8], align 1
@__PRETTY_FUNCTION__.rand_choice = external hidden unnamed_addr constant [81 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @rand_interval(i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @rand_choice(i64 noundef %0, i64 noundef %1, ptr noundef %2, ptr nocapture noundef %3) local_unnamed_addr #0 {
  %.not = icmp ugt i64 %1, %0
  br i1 %.not, label %7, label %.preheader

.preheader:                                       ; preds = %4
  %.not31 = icmp eq i64 %1, 0
  br i1 %.not31, label %._crit_edge30, label %.lr.ph29

.lr.ph29:                                         ; preds = %.preheader
  %5 = sub i64 %0, %1
  %6 = add i64 %5, 1
  br label %8

7:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 66, ptr noundef nonnull @__PRETTY_FUNCTION__.rand_choice) #2
  unreachable

._crit_edge30:                                    ; preds = %._crit_edge.thread, %.preheader
  ret void

8:                                                ; preds = %.lr.ph29, %._crit_edge.thread
  %.02128 = phi i64 [ 0, %.lr.ph29 ], [ %23, %._crit_edge.thread ]
  %9 = add i64 %6, %.02128
  %10 = tail call i64 @rand_interval(i64 noundef %9, ptr noundef %2)
  %.not32 = icmp eq i64 %.02128, 0
  br i1 %.not32, label %._crit_edge.thread, label %.lr.ph

11:                                               ; preds = %.lr.ph
  %12 = add i16 %.025, 1
  %13 = zext i16 %12 to i64
  %14 = icmp ugt i64 %.02128, %13
  br i1 %14, label %.lr.ph, label %._crit_edge.thread, !llvm.loop !5

.lr.ph:                                           ; preds = %8, %11
  %15 = phi i64 [ %13, %11 ], [ 0, %8 ]
  %.025 = phi i16 [ %12, %11 ], [ 0, %8 ]
  %16 = getelementptr inbounds i64, ptr %3, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !7
  %18 = icmp eq i64 %17, %10
  br i1 %18, label %19, label %11

19:                                               ; preds = %.lr.ph
  %20 = add i64 %.02128, %5
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %11, %8, %19
  %21 = phi i64 [ %20, %19 ], [ %10, %8 ], [ %10, %11 ]
  %22 = getelementptr inbounds i64, ptr %3, i64 %.02128
  store i64 %21, ptr %22, align 8, !tbaa !7
  %23 = add nuw i64 %.02128, 1
  %exitcond.not = icmp eq i64 %23, %1
  br i1 %exitcond.not, label %._crit_edge30, label %8, !llvm.loop !11
}

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

attributes #0 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = distinct !{!11, !6}


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