; LLVM IR from DataManagementLab/ScaleStore :: backend/scalestore/utils/RandomGenerator.ll (ZN10scalestore5utils15MersenneTwister4initEm)

; 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.scalestore::utils::MersenneTwister" = type <{ [312 x i64], i32, [4 x i8] }>

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN10scalestore5utils15MersenneTwister4initEm(ptr noundef nonnull align 8 dereferenceable(2500) %0, i64 noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %5 = load ptr, ptr %3, align 8
  %6 = load i64, ptr %4, align 8, !tbaa !9
  %7 = getelementptr inbounds %"class.scalestore::utils::MersenneTwister", ptr %5, i32 0, i32 0
  %8 = getelementptr inbounds [312 x i64], ptr %7, i64 0, i64 0
  store i64 %6, ptr %8, align 8, !tbaa !9
  %9 = getelementptr inbounds %"class.scalestore::utils::MersenneTwister", ptr %5, i32 0, i32 1
  store i32 1, ptr %9, align 8, !tbaa !11
  br label %10

10:                                               ; preds = %41, %2
  %11 = getelementptr inbounds %"class.scalestore::utils::MersenneTwister", ptr %5, i32 0, i32 1
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = icmp slt i32 %12, 312
  br i1 %13, label %14, label %45

14:                                               ; preds = %10
  %15 = getelementptr inbounds %"class.scalestore::utils::MersenneTwister", ptr %5, i32 0, i32 0
  %16 = getelementptr inbounds %"class.scalestore::utils::MersenneTwister", ptr %5, i32 0, i32 1
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = sub nsw i32 %17, 1
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [312 x i64], ptr %15, i64 0, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds %"class.scalestore::utils::MersenneTwister", ptr %5, i32 0, i32 0
  %23 = getelementptr inbounds %"class.scalestore::utils::MersenneTwister", ptr %5, i32 0, i32 1
  %24 = load i32, ptr %23, align 8, !tbaa !11
  %25 = sub nsw i32 %24, 1
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [312 x i64], ptr %22, i64 0, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !9
  %29 = lshr i64 %28, 62
  %30 = xor i64 %21, %29
  %31 = mul i64 6364136223846793005, %30
  %32 = getelementptr inbounds %"class.scalestore::utils::MersenneTwister", ptr %5, i32 0, i32 1
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = sext i32 %33 to i64
  %35 = add i64 %31, %34
  %36 = getelementptr inbounds %"class.scalestore::utils::MersenneTwister", ptr %5, i32 0, i32 0
  %37 = getelementptr inbounds %"class.scalestore::utils::MersenneTwister", ptr %5, i32 0, i32 1
  %38 = load i32, ptr %37, align 8, !tbaa !11
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [312 x i64], ptr %36, i64 0, i64 %39
  store i64 %35, ptr %40, align 8, !tbaa !9
  br label %41

41:                                               ; preds = %14
  %42 = getelementptr inbounds %"class.scalestore::utils::MersenneTwister", ptr %5, i32 0, i32 1
  %43 = load i32, ptr %42, align 8, !tbaa !11
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %42, align 8, !tbaa !11
  br label %10, !llvm.loop !14

45:                                               ; preds = %10
  ret void
}

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

!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, !13, i64 2496}
!12 = !{!"_ZTSN10scalestore5utils15MersenneTwisterE", !7, i64 0, !13, i64 2496}
!13 = !{!"int", !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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(argmem: write) uwtable
define dso_local void @_ZN10scalestore5utils15MersenneTwister4initEm(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(2500) %0, i64 noundef %1) local_unnamed_addr #0 align 2 {
  store i64 %1, ptr %0, align 8, !tbaa !5
  br label %3

3:                                                ; preds = %10, %2
  %4 = phi i64 [ %1, %2 ], [ %14, %10 ]
  %indvars.iv = phi i64 [ 1, %2 ], [ %indvars.iv.next.1, %10 ]
  %5 = lshr i64 %4, 62
  %6 = xor i64 %5, %4
  %7 = mul i64 %6, 6364136223846793005
  %8 = add i64 %7, %indvars.iv
  %9 = getelementptr inbounds [312 x i64], ptr %0, i64 0, i64 %indvars.iv
  store i64 %8, ptr %9, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 312
  br i1 %exitcond.not, label %16, label %10, !llvm.loop !9

10:                                               ; preds = %3
  %11 = lshr i64 %8, 62
  %12 = xor i64 %11, %8
  %13 = mul i64 %12, 6364136223846793005
  %14 = add i64 %13, %indvars.iv.next
  %15 = getelementptr inbounds [312 x i64], ptr %0, i64 0, i64 %indvars.iv.next
  store i64 %14, ptr %15, align 8, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  br label %3

16:                                               ; preds = %3
  %17 = getelementptr inbounds i8, ptr %0, i64 2496
  store i32 312, ptr %17, align 8, !tbaa !11
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: write) 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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !13, i64 2496}
!12 = !{!"_ZTSN10scalestore5utils15MersenneTwisterE", !7, i64 0, !13, i64 2496}
!13 = !{!"int", !7, i64 0}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass