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

; 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
declare dso_local void @_ZN12MTRand_int324seedEm(ptr noundef nonnull align 1 dereferenceable(1), i64 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN12MTRand_int324seedEPKmi(ptr noundef nonnull align 1 dereferenceable(1) %0, ptr noundef %1, i32 noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8
  call void @_ZN12MTRand_int324seedEm(ptr noundef nonnull align 1 dereferenceable(1) %11, i64 noundef 19650218)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 1, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = icmp sgt i32 624, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  br label %17

15:                                               ; preds = %3
  %16 = load i32, ptr %6, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %15, %14
  %18 = phi i32 [ 624, %14 ], [ %16, %15 ]
  store i32 %18, ptr %9, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %70, %17
  %20 = load i32, ptr %9, align 4, !tbaa !9
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %23, label %22

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

23:                                               ; preds = %19
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !11
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = sub nsw i32 %28, 1
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !11
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = sub nsw i32 %33, 1
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !11
  %38 = lshr i64 %37, 30
  %39 = xor i64 %32, %38
  %40 = mul i64 %39, 1664525
  %41 = xor i64 %27, %40
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i64, ptr %42, i64 %44
  %46 = load i64, ptr %45, align 8, !tbaa !11
  %47 = add i64 %41, %46
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = add i64 %47, %49
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %52
  store i64 %50, ptr %53, align 8, !tbaa !11
  %54 = load i32, ptr %7, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %55
  %57 = load i64, ptr %56, align 8, !tbaa !11
  %58 = and i64 %57, 4294967295
  store i64 %58, ptr %56, align 8, !tbaa !11
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %8, align 4, !tbaa !9
  %61 = load i32, ptr %6, align 4, !tbaa !9
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = srem i32 %62, %61
  store i32 %63, ptr %8, align 4, !tbaa !9
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %7, align 4, !tbaa !9
  %66 = icmp eq i32 %65, 624
  br i1 %66, label %67, label %69

67:                                               ; preds = %23
  %68 = load i64, ptr getelementptr inbounds ([624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 623), align 8, !tbaa !11
  store i64 %68, ptr @_ZN12MTRand_int325stateE, align 16, !tbaa !11
  store i32 1, ptr %7, align 4, !tbaa !9
  br label %69

69:                                               ; preds = %67, %23
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %9, align 4, !tbaa !9
  %72 = add nsw i32 %71, -1
  store i32 %72, ptr %9, align 4, !tbaa !9
  br label %19, !llvm.loop !13

73:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 623, ptr %10, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %114, %73
  %75 = load i32, ptr %10, align 4, !tbaa !9
  %76 = icmp ne i32 %75, 0
  br i1 %76, label %78, label %77

77:                                               ; preds = %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %117

78:                                               ; preds = %74
  %79 = load i32, ptr %7, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %80
  %82 = load i64, ptr %81, align 8, !tbaa !11
  %83 = load i32, ptr %7, align 4, !tbaa !9
  %84 = sub nsw i32 %83, 1
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %85
  %87 = load i64, ptr %86, align 8, !tbaa !11
  %88 = load i32, ptr %7, align 4, !tbaa !9
  %89 = sub nsw i32 %88, 1
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %90
  %92 = load i64, ptr %91, align 8, !tbaa !11
  %93 = lshr i64 %92, 30
  %94 = xor i64 %87, %93
  %95 = mul i64 %94, 1566083941
  %96 = xor i64 %82, %95
  %97 = load i32, ptr %7, align 4, !tbaa !9
  %98 = sext i32 %97 to i64
  %99 = sub i64 %96, %98
  %100 = load i32, ptr %7, align 4, !tbaa !9
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %101
  store i64 %99, ptr %102, align 8, !tbaa !11
  %103 = load i32, ptr %7, align 4, !tbaa !9
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %104
  %106 = load i64, ptr %105, align 8, !tbaa !11
  %107 = and i64 %106, 4294967295
  store i64 %107, ptr %105, align 8, !tbaa !11
  %108 = load i32, ptr %7, align 4, !tbaa !9
  %109 = add nsw i32 %108, 1
  store i32 %109, ptr %7, align 4, !tbaa !9
  %110 = icmp eq i32 %109, 624
  br i1 %110, label %111, label %113

111:                                              ; preds = %78
  %112 = load i64, ptr getelementptr inbounds ([624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 623), align 8, !tbaa !11
  store i64 %112, ptr @_ZN12MTRand_int325stateE, align 16, !tbaa !11
  store i32 1, ptr %7, align 4, !tbaa !9
  br label %113

113:                                              ; preds = %111, %78
  br label %114

114:                                              ; preds = %113
  %115 = load i32, ptr %10, align 4, !tbaa !9
  %116 = add nsw i32 %115, -1
  store i32 %116, ptr %10, align 4, !tbaa !9
  br label %74, !llvm.loop !15

117:                                              ; preds = %77
  store i64 2147483648, ptr @_ZN12MTRand_int325stateE, align 16, !tbaa !11
  store i32 624, ptr @_ZN12MTRand_int321pE, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 nounwind uwtable
declare dso_local void @_ZN12MTRand_int324seedEm(ptr noundef nonnull align 1 dereferenceable(1), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN12MTRand_int324seedEPKmi(ptr noundef nonnull align 1 dereferenceable(1) %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  tail call void @_ZN12MTRand_int324seedEm(ptr noundef nonnull align 1 dereferenceable(1) %0, i64 noundef 19650218)
  %4 = tail call i32 @llvm.smax.i32(i32 %2, i32 624)
  br label %5

5:                                                ; preds = %3, %29
  %.02533 = phi i32 [ %4, %3 ], [ %30, %29 ]
  %.02632 = phi i32 [ 0, %3 ], [ %24, %29 ]
  %.02731 = phi i32 [ 1, %3 ], [ %.1, %29 ]
  %6 = sext i32 %.02731 to i64
  %7 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %6
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = add nsw i32 %.02731, -1
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %10
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = lshr i64 %12, 30
  %14 = xor i64 %13, %12
  %15 = mul i64 %14, 1664525
  %16 = xor i64 %15, %8
  %17 = sext i32 %.02632 to i64
  %18 = getelementptr inbounds i64, ptr %1, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %20 = add i64 %19, %17
  %21 = add i64 %20, %16
  %22 = and i64 %21, 4294967295
  store i64 %22, ptr %7, align 8, !tbaa !5
  %23 = add nsw i32 %.02632, 1
  %24 = srem i32 %23, %2
  %25 = add nsw i32 %.02731, 1
  %26 = icmp eq i32 %25, 624
  br i1 %26, label %27, label %29

27:                                               ; preds = %5
  %28 = load i64, ptr getelementptr inbounds (i8, ptr @_ZN12MTRand_int325stateE, i64 4984), align 8, !tbaa !5
  store i64 %28, ptr @_ZN12MTRand_int325stateE, align 16, !tbaa !5
  br label %29

29:                                               ; preds = %5, %27
  %.1 = phi i32 [ 1, %27 ], [ %25, %5 ]
  %30 = add nsw i32 %.02533, -1
  %.not = icmp eq i32 %30, 0
  br i1 %.not, label %.preheader, label %5, !llvm.loop !9

31:                                               ; preds = %49
  store i64 2147483648, ptr @_ZN12MTRand_int325stateE, align 16, !tbaa !5
  store i32 624, ptr @_ZN12MTRand_int321pE, align 4, !tbaa !11
  ret void

.preheader:                                       ; preds = %29, %49
  %.035 = phi i32 [ %50, %49 ], [ 623, %29 ]
  %.234 = phi i32 [ %.3, %49 ], [ %.1, %29 ]
  %32 = sext i32 %.234 to i64
  %33 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %32
  %34 = load i64, ptr %33, align 8, !tbaa !5
  %35 = add nsw i32 %.234, -1
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !5
  %39 = lshr i64 %38, 30
  %40 = xor i64 %39, %38
  %41 = mul i64 %40, 1566083941
  %42 = xor i64 %41, %34
  %43 = sub i64 %42, %32
  %44 = and i64 %43, 4294967295
  store i64 %44, ptr %33, align 8, !tbaa !5
  %45 = add nsw i32 %.234, 1
  %46 = icmp eq i32 %45, 624
  br i1 %46, label %47, label %49

47:                                               ; preds = %.preheader
  %48 = load i64, ptr getelementptr inbounds (i8, ptr @_ZN12MTRand_int325stateE, i64 4984), align 8, !tbaa !5
  store i64 %48, ptr @_ZN12MTRand_int325stateE, align 16, !tbaa !5
  br label %49

49:                                               ; preds = %.preheader, %47
  %.3 = phi i32 [ 1, %47 ], [ %45, %.preheader ]
  %50 = add nsw i32 %.035, -1
  %.not30 = icmp eq i32 %50, 0
  br i1 %.not30, label %31, label %.preheader, !llvm.loop !13
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass