; LLVM IR from simbody/simbody :: SimTKcommon/Random/src/SFMT.ll (ZN10SimTK_SFMT10gen_rand32ERNS_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] }

@.str.1 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [81 x i8], align 1
@__PRETTY_FUNCTION__._ZN10SimTK_SFMT10gen_rand32ERNS_8SFMTDataE = external hidden unnamed_addr constant [44 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN10SimTK_SFMT10gen_rand32ERNS_8SFMTDataE(ptr noundef nonnull align 8 dereferenceable(2536) %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %"class.SimTK_SFMT::SFMTData", ptr %4, i32 0, i32 4
  %6 = load i32, ptr %5, align 4, !tbaa !9
  %7 = icmp ne i32 %6, 0
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  br label %11

9:                                                ; preds = %1
  call void @__assert_fail(ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 444, ptr noundef @__PRETTY_FUNCTION__._ZN10SimTK_SFMT10gen_rand32ERNS_8SFMTDataE) #5
  unreachable

10:                                               ; No predecessors!
  br label %11

11:                                               ; preds = %10, %8
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %"class.SimTK_SFMT::SFMTData", ptr %12, i32 0, i32 3
  %14 = load i32, ptr %13, align 8, !tbaa !12
  %15 = icmp sge i32 %14, 624
  br i1 %15, label %16, label %20

16:                                               ; preds = %11
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_ZN10SimTK_SFMTL12gen_rand_allERNS_8SFMTDataE(ptr noundef nonnull align 8 dereferenceable(2536) %17)
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %"class.SimTK_SFMT::SFMTData", ptr %18, i32 0, i32 3
  store i32 0, ptr %19, align 8, !tbaa !12
  br label %20

20:                                               ; preds = %16, %11
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %"class.SimTK_SFMT::SFMTData", ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %"class.SimTK_SFMT::SFMTData", ptr %24, i32 0, i32 3
  %26 = load i32, ptr %25, align 8, !tbaa !12
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %25, align 8, !tbaa !12
  %28 = sext i32 %26 to i64
  %29 = getelementptr inbounds i32, ptr %23, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !14
  store i32 %30, ptr %3, align 4, !tbaa !14
  %31 = load i32, ptr %3, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret i32 %31
}

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

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

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 #4 = { nounwind }
attributes #5 = { 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 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 2516}
!10 = !{!"_ZTSN10SimTK_SFMT8SFMTDataE", !7, i64 0, !6, i64 2496, !6, i64 2504, !11, i64 2512, !11, i64 2516, !7, i64 2520}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 2512}
!13 = !{!10, !6, i64 2496}
!14 = !{!11, !11, i64 0}


; 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.1 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [81 x i8], align 1
@__PRETTY_FUNCTION__._ZN10SimTK_SFMT10gen_rand32ERNS_8SFMTDataE = external hidden unnamed_addr constant [44 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN10SimTK_SFMT10gen_rand32ERNS_8SFMTDataE(ptr noundef nonnull align 8 dereferenceable(2536) %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 2516
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %4, label %5

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

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 2512
  %7 = load i32, ptr %6, align 8, !tbaa !11
  %8 = icmp sgt i32 %7, 623
  br i1 %8, label %9, label %10

9:                                                ; preds = %5
  tail call void @_ZN10SimTK_SFMTL12gen_rand_allERNS_8SFMTDataE(ptr noundef nonnull align 8 dereferenceable(2536) %0)
  br label %10

10:                                               ; preds = %9, %5
  %11 = phi i32 [ 0, %9 ], [ %7, %5 ]
  %12 = getelementptr inbounds i8, ptr %0, i64 2496
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %14 = add nsw i32 %11, 1
  store i32 %14, ptr %6, align 8, !tbaa !11
  %15 = sext i32 %11 to i64
  %16 = getelementptr inbounds i32, ptr %13, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !13
  ret i32 %17
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @_ZN10SimTK_SFMTL12gen_rand_allERNS_8SFMTDataE(ptr noundef nonnull align 8 dereferenceable(2536)) local_unnamed_addr #2

attributes #0 = { 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 #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 = { inlinehint 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 #3 = { 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 = !{!6, !10, i64 2516}
!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 = !{!6, !10, i64 2512}
!12 = !{!6, !9, i64 2496}
!13 = !{!10, !10, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass