; LLVM IR from Morpho-lang/morpho :: src/support (random)

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

@xoshiro256p_jump.JUMP = external hidden constant [4 x i64], align 16
@xoshiro256p_state = external hidden global [4 x i64], align 16

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @next() #1

; 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
define dso_local void @xoshiro256p_jump() #2 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  store i64 0, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  store i64 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 !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store i64 0, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %47, %0
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = sext i32 %9 to i64
  %11 = icmp ult i64 %10, 4
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %50

13:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %43, %13
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = icmp slt i32 %15, 64
  br i1 %16, label %18, label %17

17:                                               ; preds = %14
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %46

18:                                               ; preds = %14
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [4 x i64], ptr @xoshiro256p_jump.JUMP, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = shl i64 1, %24
  %26 = and i64 %22, %25
  %27 = icmp ne i64 %26, 0
  br i1 %27, label %28, label %41

28:                                               ; preds = %18
  %29 = load i64, ptr @xoshiro256p_state, align 16, !tbaa !5
  %30 = load i64, ptr %1, align 8, !tbaa !5
  %31 = xor i64 %30, %29
  store i64 %31, ptr %1, align 8, !tbaa !5
  %32 = load i64, ptr getelementptr inbounds ([4 x i64], ptr @xoshiro256p_state, i64 0, i64 1), align 8, !tbaa !5
  %33 = load i64, ptr %2, align 8, !tbaa !5
  %34 = xor i64 %33, %32
  store i64 %34, ptr %2, align 8, !tbaa !5
  %35 = load i64, ptr getelementptr inbounds ([4 x i64], ptr @xoshiro256p_state, i64 0, i64 2), align 16, !tbaa !5
  %36 = load i64, ptr %3, align 8, !tbaa !5
  %37 = xor i64 %36, %35
  store i64 %37, ptr %3, align 8, !tbaa !5
  %38 = load i64, ptr getelementptr inbounds ([4 x i64], ptr @xoshiro256p_state, i64 0, i64 3), align 8, !tbaa !5
  %39 = load i64, ptr %4, align 8, !tbaa !5
  %40 = xor i64 %39, %38
  store i64 %40, ptr %4, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %28, %18
  %42 = call i64 @next()
  br label %43

43:                                               ; preds = %41
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %7, align 4, !tbaa !9
  br label %14, !llvm.loop !11

46:                                               ; preds = %17
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %5, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %5, align 4, !tbaa !9
  br label %8, !llvm.loop !13

50:                                               ; preds = %12
  %51 = load i64, ptr %1, align 8, !tbaa !5
  store i64 %51, ptr @xoshiro256p_state, align 16, !tbaa !5
  %52 = load i64, ptr %2, align 8, !tbaa !5
  store i64 %52, ptr getelementptr inbounds ([4 x i64], ptr @xoshiro256p_state, i64 0, i64 1), align 8, !tbaa !5
  %53 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %53, ptr getelementptr inbounds ([4 x i64], ptr @xoshiro256p_state, i64 0, i64 2), align 16, !tbaa !5
  %54 = load i64, ptr %4, align 8, !tbaa !5
  store i64 %54, ptr getelementptr inbounds ([4 x i64], ptr @xoshiro256p_state, i64 0, i64 3), align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret void
}

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


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

@xoshiro256p_jump.JUMP = external hidden local_unnamed_addr constant [4 x i64], align 16
@xoshiro256p_state = external hidden local_unnamed_addr global [4 x i64], align 16

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @next() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @xoshiro256p_jump() local_unnamed_addr #1 {
.preheader:
  %0 = load i64, ptr @xoshiro256p_jump.JUMP, align 16, !tbaa !5
  br label %41

.preheader.1:                                     ; preds = %41
  %1 = load i64, ptr getelementptr inbounds (i8, ptr @xoshiro256p_jump.JUMP, i64 8), align 8, !tbaa !5
  br label %2

2:                                                ; preds = %2, %.preheader.1
  %indvars.iv.1 = phi i64 [ 0, %.preheader.1 ], [ %indvars.iv.next.1, %2 ]
  %3 = phi <2 x i64> [ %50, %.preheader.1 ], [ %11, %2 ]
  %4 = phi <2 x i64> [ %51, %.preheader.1 ], [ %12, %2 ]
  %5 = shl nuw i64 1, %indvars.iv.1
  %6 = and i64 %1, %5
  %.not.1 = icmp eq i64 %6, 0
  %7 = load <2 x i64>, ptr @xoshiro256p_state, align 16
  %8 = xor <2 x i64> %7, %3
  %9 = load <2 x i64>, ptr getelementptr inbounds (i8, ptr @xoshiro256p_state, i64 16), align 16
  %10 = xor <2 x i64> %9, %4
  %11 = select i1 %.not.1, <2 x i64> %3, <2 x i64> %8
  %12 = select i1 %.not.1, <2 x i64> %4, <2 x i64> %10
  %13 = tail call i64 @next()
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv.1, 1
  %exitcond.1.not = icmp eq i64 %indvars.iv.next.1, 64
  br i1 %exitcond.1.not, label %.preheader.2, label %2, !llvm.loop !9

.preheader.2:                                     ; preds = %2
  %14 = load i64, ptr getelementptr inbounds (i8, ptr @xoshiro256p_jump.JUMP, i64 16), align 16, !tbaa !5
  br label %15

15:                                               ; preds = %15, %.preheader.2
  %indvars.iv.2 = phi i64 [ 0, %.preheader.2 ], [ %indvars.iv.next.2, %15 ]
  %16 = phi <2 x i64> [ %11, %.preheader.2 ], [ %24, %15 ]
  %17 = phi <2 x i64> [ %12, %.preheader.2 ], [ %25, %15 ]
  %18 = shl nuw i64 1, %indvars.iv.2
  %19 = and i64 %14, %18
  %.not.2 = icmp eq i64 %19, 0
  %20 = load <2 x i64>, ptr @xoshiro256p_state, align 16
  %21 = xor <2 x i64> %20, %16
  %22 = load <2 x i64>, ptr getelementptr inbounds (i8, ptr @xoshiro256p_state, i64 16), align 16
  %23 = xor <2 x i64> %22, %17
  %24 = select i1 %.not.2, <2 x i64> %16, <2 x i64> %21
  %25 = select i1 %.not.2, <2 x i64> %17, <2 x i64> %23
  %26 = tail call i64 @next()
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv.2, 1
  %exitcond.2.not = icmp eq i64 %indvars.iv.next.2, 64
  br i1 %exitcond.2.not, label %.preheader.3, label %15, !llvm.loop !9

.preheader.3:                                     ; preds = %15
  %27 = load i64, ptr getelementptr inbounds (i8, ptr @xoshiro256p_jump.JUMP, i64 24), align 8, !tbaa !5
  br label %28

28:                                               ; preds = %28, %.preheader.3
  %indvars.iv.3 = phi i64 [ 0, %.preheader.3 ], [ %indvars.iv.next.3, %28 ]
  %29 = phi <2 x i64> [ %24, %.preheader.3 ], [ %37, %28 ]
  %30 = phi <2 x i64> [ %25, %.preheader.3 ], [ %38, %28 ]
  %31 = shl nuw i64 1, %indvars.iv.3
  %32 = and i64 %27, %31
  %.not.3 = icmp eq i64 %32, 0
  %33 = load <2 x i64>, ptr @xoshiro256p_state, align 16
  %34 = xor <2 x i64> %33, %29
  %35 = load <2 x i64>, ptr getelementptr inbounds (i8, ptr @xoshiro256p_state, i64 16), align 16
  %36 = xor <2 x i64> %35, %30
  %37 = select i1 %.not.3, <2 x i64> %29, <2 x i64> %34
  %38 = select i1 %.not.3, <2 x i64> %30, <2 x i64> %36
  %39 = tail call i64 @next()
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv.3, 1
  %exitcond.3.not = icmp eq i64 %indvars.iv.next.3, 64
  br i1 %exitcond.3.not, label %40, label %28, !llvm.loop !9

40:                                               ; preds = %28
  store <2 x i64> %37, ptr @xoshiro256p_state, align 16, !tbaa !5
  store <2 x i64> %38, ptr getelementptr inbounds (i8, ptr @xoshiro256p_state, i64 16), align 16, !tbaa !5
  ret void

41:                                               ; preds = %.preheader, %41
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next, %41 ]
  %42 = phi <2 x i64> [ zeroinitializer, %.preheader ], [ %50, %41 ]
  %43 = phi <2 x i64> [ zeroinitializer, %.preheader ], [ %51, %41 ]
  %44 = shl nuw i64 1, %indvars.iv
  %45 = and i64 %0, %44
  %.not = icmp eq i64 %45, 0
  %46 = load <2 x i64>, ptr @xoshiro256p_state, align 16
  %47 = xor <2 x i64> %46, %42
  %48 = load <2 x i64>, ptr getelementptr inbounds (i8, ptr @xoshiro256p_state, i64 16), align 16
  %49 = xor <2 x i64> %48, %43
  %50 = select i1 %.not, <2 x i64> %42, <2 x i64> %47
  %51 = select i1 %.not, <2 x i64> %43, <2 x i64> %49
  %52 = tail call i64 @next()
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 64
  br i1 %exitcond.not, label %.preheader.1, label %41, !llvm.loop !9
}

attributes #0 = { inlinehint 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 = { 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" }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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