; LLVM IR from simbody/simbody :: SimTKcommon/Random/src/SFMT.ll (ZN10SimTK_SFMT13init_gen_randEjRNS_8SFMTDataE)

; 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.SimTK_SFMT::SFMTData" = type { [156 x %struct.W128_T], ptr, ptr, i32, i32, [4 x i32] }
%struct.W128_T = type { [4 x i32] }

; 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 @_ZN10SimTK_SFMT13init_gen_randEjRNS_8SFMTDataE(i32 noundef %0, ptr noundef nonnull align 8 dereferenceable(2536) %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = load ptr, ptr %4, align 8, !tbaa !9
  %8 = getelementptr inbounds %"class.SimTK_SFMT::SFMTData", ptr %7, i32 0, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = call noundef i32 @_ZN10SimTK_SFMTL5idxofEi(i32 noundef 0)
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds i32, ptr %9, i64 %11
  store i32 %6, ptr %12, align 4, !tbaa !5
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %50, %2
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = icmp slt i32 %14, 624
  br i1 %15, label %16, label %53

16:                                               ; preds = %13
  %17 = load ptr, ptr %4, align 8, !tbaa !9
  %18 = getelementptr inbounds %"class.SimTK_SFMT::SFMTData", ptr %17, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = sub nsw i32 %20, 1
  %22 = call noundef i32 @_ZN10SimTK_SFMTL5idxofEi(i32 noundef %21)
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr %19, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = load ptr, ptr %4, align 8, !tbaa !9
  %27 = getelementptr inbounds %"class.SimTK_SFMT::SFMTData", ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = sub nsw i32 %29, 1
  %31 = call noundef i32 @_ZN10SimTK_SFMTL5idxofEi(i32 noundef %30)
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i32, ptr %28, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = lshr i32 %34, 30
  %36 = xor i32 %25, %35
  %37 = zext i32 %36 to i64
  %38 = mul i64 1812433253, %37
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = add i64 %38, %40
  %42 = trunc i64 %41 to i32
  %43 = load ptr, ptr %4, align 8, !tbaa !9
  %44 = getelementptr inbounds %"class.SimTK_SFMT::SFMTData", ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = call noundef i32 @_ZN10SimTK_SFMTL5idxofEi(i32 noundef %46)
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i32, ptr %45, i64 %48
  store i32 %42, ptr %49, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %16
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %5, align 4, !tbaa !5
  br label %13, !llvm.loop !13

53:                                               ; preds = %13
  %54 = load ptr, ptr %4, align 8, !tbaa !9
  %55 = getelementptr inbounds %"class.SimTK_SFMT::SFMTData", ptr %54, i32 0, i32 3
  store i32 624, ptr %55, align 8, !tbaa !15
  %56 = load ptr, ptr %4, align 8, !tbaa !9
  call void @_ZN10SimTK_SFMTL20period_certificationERNS_8SFMTDataE(ptr noundef nonnull align 8 dereferenceable(2536) %56)
  %57 = load ptr, ptr %4, align 8, !tbaa !9
  %58 = getelementptr inbounds %"class.SimTK_SFMT::SFMTData", ptr %57, i32 0, i32 4
  store i32 1, ptr %58, align 4, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZN10SimTK_SFMTL5idxofEi(i32 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN10SimTK_SFMTL20period_certificationERNS_8SFMTDataE(ptr noundef nonnull align 8 dereferenceable(2536)) #3

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 = { inlinehint 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 #3 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 2496}
!12 = !{!"_ZTSN10SimTK_SFMT8SFMTDataE", !7, i64 0, !10, i64 2496, !10, i64 2504, !6, i64 2512, !6, i64 2516, !7, i64 2520}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!12, !6, i64 2512}
!16 = !{!12, !6, i64 2516}


; 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 nounwind uwtable
define dso_local void @_ZN10SimTK_SFMT13init_gen_randEjRNS_8SFMTDataE(i32 noundef %0, ptr noundef nonnull align 8 dereferenceable(2536) %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 2496
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = tail call noundef i32 @_ZN10SimTK_SFMTL5idxofEi(i32 noundef 0)
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds i32, ptr %4, i64 %6
  store i32 %0, ptr %7, align 4, !tbaa !11
  br label %8

8:                                                ; preds = %2, %8
  %.013 = phi i32 [ 1, %2 ], [ %28, %8 ]
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = add nsw i32 %.013, -1
  %11 = tail call noundef i32 @_ZN10SimTK_SFMTL5idxofEi(i32 noundef %10)
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i32, ptr %9, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = tail call noundef i32 @_ZN10SimTK_SFMTL5idxofEi(i32 noundef %10)
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i32, ptr %15, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = lshr i32 %19, 30
  %21 = xor i32 %20, %14
  %22 = mul i32 %21, 1812433253
  %23 = add i32 %22, %.013
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = tail call noundef i32 @_ZN10SimTK_SFMTL5idxofEi(i32 noundef %.013)
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i32, ptr %24, i64 %26
  store i32 %23, ptr %27, align 4, !tbaa !11
  %28 = add nuw nsw i32 %.013, 1
  %exitcond.not = icmp eq i32 %28, 624
  br i1 %exitcond.not, label %29, label %8, !llvm.loop !12

29:                                               ; preds = %8
  %30 = getelementptr inbounds i8, ptr %1, i64 2512
  store i32 624, ptr %30, align 8, !tbaa !14
  tail call void @_ZN10SimTK_SFMTL20period_certificationERNS_8SFMTDataE(ptr noundef nonnull align 8 dereferenceable(2536) %1)
  %31 = getelementptr inbounds i8, ptr %1, i64 2516
  store i32 1, ptr %31, align 4, !tbaa !15
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZN10SimTK_SFMTL5idxofEi(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN10SimTK_SFMTL20period_certificationERNS_8SFMTDataE(ptr noundef nonnull align 8 dereferenceable(2536)) local_unnamed_addr #0

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 = { inlinehint 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, !9, i64 2496}
!6 = !{!"_ZTSN10SimTK_SFMT8SFMTDataE", !7, i64 0, !9, i64 2496, !9, i64 2504, !10, i64 2512, !10, i64 2516, !7, i64 2520}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!10, !10, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!6, !10, i64 2512}
!15 = !{!6, !10, i64 2516}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass