; LLVM IR from jorgemf/c-evolutionary-library :: src/mtrand.ll (ZN12MTRand_int324seedEm)

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

@_ZN12MTRand_int325stateE = external dso_local global [624 x i64], align 16
@_ZN12MTRand_int321pE = external dso_local global i32, align 4

; 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 nounwind uwtable
define dso_local void @_ZN12MTRand_int324seedEm(ptr noundef nonnull align 1 dereferenceable(1) %0, i64 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  %7 = load i64, ptr %4, align 8, !tbaa !9
  %8 = and i64 %7, 4294967295
  store i64 %8, ptr @_ZN12MTRand_int325stateE, align 16, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 1, ptr %5, align 4, !tbaa !11
  br label %9

9:                                                ; preds = %38, %2
  %10 = load i32, ptr %5, align 4, !tbaa !11
  %11 = icmp slt i32 %10, 624
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %41

13:                                               ; preds = %9
  %14 = load i32, ptr %5, align 4, !tbaa !11
  %15 = sub nsw i32 %14, 1
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %16
  %18 = load i64, ptr %17, align 8, !tbaa !9
  %19 = load i32, ptr %5, align 4, !tbaa !11
  %20 = sub nsw i32 %19, 1
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = lshr i64 %23, 30
  %25 = xor i64 %18, %24
  %26 = mul i64 1812433253, %25
  %27 = load i32, ptr %5, align 4, !tbaa !11
  %28 = sext i32 %27 to i64
  %29 = add i64 %26, %28
  %30 = load i32, ptr %5, align 4, !tbaa !11
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %31
  store i64 %29, ptr %32, align 8, !tbaa !9
  %33 = load i32, ptr %5, align 4, !tbaa !11
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %34
  %36 = load i64, ptr %35, align 8, !tbaa !9
  %37 = and i64 %36, 4294967295
  store i64 %37, ptr %35, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %13
  %39 = load i32, ptr %5, align 4, !tbaa !11
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %5, align 4, !tbaa !11
  br label %9, !llvm.loop !13

41:                                               ; preds = %12
  store i32 624, ptr @_ZN12MTRand_int321pE, align 4, !tbaa !11
  ret void
}

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

@_ZN12MTRand_int325stateE = external dso_local local_unnamed_addr global [624 x i64], align 16
@_ZN12MTRand_int321pE = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_ZN12MTRand_int324seedEm(ptr nocapture noundef nonnull readnone align 1 dereferenceable(1) %0, i64 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = and i64 %1, 4294967295
  store i64 %3, ptr @_ZN12MTRand_int325stateE, align 16, !tbaa !5
  br label %5

4:                                                ; preds = %5
  store i32 624, ptr @_ZN12MTRand_int321pE, align 4, !tbaa !9
  ret void

5:                                                ; preds = %13, %2
  %6 = phi i64 [ %3, %2 ], [ %19, %13 ]
  %indvars.iv = phi i64 [ 1, %2 ], [ %indvars.iv.next.1, %13 ]
  %7 = lshr i64 %6, 30
  %8 = xor i64 %7, %6
  %9 = mul nuw nsw i64 %8, 1812433253
  %10 = add nuw i64 %9, %indvars.iv
  %11 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %indvars.iv
  %12 = and i64 %10, 4294967295
  store i64 %12, ptr %11, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 624
  br i1 %exitcond.not, label %4, label %13, !llvm.loop !11

13:                                               ; preds = %5
  %14 = lshr i64 %12, 30
  %15 = xor i64 %14, %10
  %16 = mul i64 %15, 1812433253
  %17 = add i64 %16, %indvars.iv.next
  %18 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %indvars.iv.next
  %19 = and i64 %17, 4294967295
  store i64 %19, ptr %18, align 8, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  br label %5
}

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


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