; LLVM IR from idmillington/cyclone-physics :: src/random.ll (ZN7cyclone6Random4seedEj)

; 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.cyclone::Random" = type { i32, i32, [17 x i32] }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7cyclone6Random4seedEj(ptr noundef nonnull align 4 dereferenceable(76) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %12

9:                                                ; preds = %2
  %10 = call i64 @clock() #3
  %11 = trunc i64 %10 to i32
  store i32 %11, ptr %4, align 4, !tbaa !9
  br label %12

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

13:                                               ; preds = %28, %12
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = icmp ult i32 %14, 17
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %31

17:                                               ; preds = %13
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = zext i32 %18 to i64
  %20 = mul nsw i64 %19, 2891336453
  %21 = add nsw i64 %20, 1
  %22 = trunc i64 %21 to i32
  store i32 %22, ptr %4, align 4, !tbaa !9
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = getelementptr inbounds %"class.cyclone::Random", ptr %6, i32 0, i32 2
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds [17 x i32], ptr %24, i64 0, i64 %26
  store i32 %23, ptr %27, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %17
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = add i32 %29, 1
  store i32 %30, ptr %5, align 4, !tbaa !9
  br label %13, !llvm.loop !11

31:                                               ; preds = %16
  %32 = getelementptr inbounds %"class.cyclone::Random", ptr %6, i32 0, i32 0
  store i32 0, ptr %32, align 4, !tbaa !13
  %33 = getelementptr inbounds %"class.cyclone::Random", ptr %6, i32 0, i32 1
  store i32 10, ptr %33, align 4, !tbaa !15
  ret void
}

; Function Attrs: nounwind
declare i64 @clock() #1

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

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

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTSN7cyclone6RandomE", !10, i64 0, !10, i64 4, !7, i64 8}
!15 = !{!14, !10, i64 4}


; 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 @_ZN7cyclone6Random4seedEj(ptr nocapture noundef nonnull writeonly align 4 dereferenceable(76) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = icmp eq i32 %1, 0
  br i1 %3, label %4, label %7

4:                                                ; preds = %2
  %5 = tail call i64 @clock() #2
  %6 = trunc i64 %5 to i32
  br label %7

7:                                                ; preds = %4, %2
  %.06 = phi i32 [ %6, %4 ], [ %1, %2 ]
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = mul i32 %.06, -1403630843
  %10 = add i32 %9, 1
  store i32 %10, ptr %8, align 4, !tbaa !5
  %11 = mul i32 %10, -1403630843
  %12 = add i32 %11, 1
  %13 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %12, ptr %13, align 4, !tbaa !5
  %14 = mul i32 %12, -1403630843
  %15 = add i32 %14, 1
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %15, ptr %16, align 4, !tbaa !5
  %17 = mul i32 %15, -1403630843
  %18 = add i32 %17, 1
  %19 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 %18, ptr %19, align 4, !tbaa !5
  %20 = mul i32 %18, -1403630843
  %21 = add i32 %20, 1
  %22 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %21, ptr %22, align 4, !tbaa !5
  %23 = mul i32 %21, -1403630843
  %24 = add i32 %23, 1
  %25 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 %24, ptr %25, align 4, !tbaa !5
  %26 = mul i32 %24, -1403630843
  %27 = add i32 %26, 1
  %28 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 %27, ptr %28, align 4, !tbaa !5
  %29 = mul i32 %27, -1403630843
  %30 = add i32 %29, 1
  %31 = getelementptr inbounds i8, ptr %0, i64 36
  store i32 %30, ptr %31, align 4, !tbaa !5
  %32 = mul i32 %30, -1403630843
  %33 = add i32 %32, 1
  %34 = getelementptr inbounds i8, ptr %0, i64 40
  store i32 %33, ptr %34, align 4, !tbaa !5
  %35 = mul i32 %33, -1403630843
  %36 = add i32 %35, 1
  %37 = getelementptr inbounds i8, ptr %0, i64 44
  store i32 %36, ptr %37, align 4, !tbaa !5
  %38 = mul i32 %36, -1403630843
  %39 = add i32 %38, 1
  %40 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 %39, ptr %40, align 4, !tbaa !5
  %41 = mul i32 %39, -1403630843
  %42 = add i32 %41, 1
  %43 = getelementptr inbounds i8, ptr %0, i64 52
  store i32 %42, ptr %43, align 4, !tbaa !5
  %44 = mul i32 %42, -1403630843
  %45 = add i32 %44, 1
  %46 = getelementptr inbounds i8, ptr %0, i64 56
  store i32 %45, ptr %46, align 4, !tbaa !5
  %47 = mul i32 %45, -1403630843
  %48 = add i32 %47, 1
  %49 = getelementptr inbounds i8, ptr %0, i64 60
  store i32 %48, ptr %49, align 4, !tbaa !5
  %50 = mul i32 %48, -1403630843
  %51 = add i32 %50, 1
  %52 = getelementptr inbounds i8, ptr %0, i64 64
  store i32 %51, ptr %52, align 4, !tbaa !5
  %53 = mul i32 %51, -1403630843
  %54 = add i32 %53, 1
  %55 = getelementptr inbounds i8, ptr %0, i64 68
  store i32 %54, ptr %55, align 4, !tbaa !5
  %56 = mul i32 %54, -1403630843
  %57 = add i32 %56, 1
  %58 = getelementptr inbounds i8, ptr %0, i64 72
  store i32 %57, ptr %58, align 4, !tbaa !5
  store i32 0, ptr %0, align 4, !tbaa !9
  %59 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 10, ptr %59, align 4, !tbaa !11
  ret void
}

; Function Attrs: nounwind
declare i64 @clock() local_unnamed_addr #1

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 = { 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 = { 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, !6, i64 0}
!10 = !{!"_ZTSN7cyclone6RandomE", !6, i64 0, !6, i64 4, !7, i64 8}
!11 = !{!10, !6, i64 4}


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