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

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

6:                                                ; preds = %30, %1
  %7 = load i32, ptr %3, align 4, !tbaa !9
  %8 = icmp slt i32 %7, 227
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %33

10:                                               ; preds = %6
  %11 = load i32, ptr %3, align 4, !tbaa !9
  %12 = add nsw i32 %11, 397
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %13
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = load i32, ptr %3, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = add nsw i32 %20, 1
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !11
  %25 = call noundef i64 @_ZN12MTRand_int327twiddleEmm(ptr noundef nonnull align 1 dereferenceable(1) %5, i64 noundef %19, i64 noundef %24)
  %26 = xor i64 %15, %25
  %27 = load i32, ptr %3, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %28
  store i64 %26, ptr %29, align 8, !tbaa !11
  br label %30

30:                                               ; preds = %10
  %31 = load i32, ptr %3, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %3, align 4, !tbaa !9
  br label %6, !llvm.loop !13

33:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 227, ptr %4, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %59, %33
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = icmp slt i32 %35, 623
  br i1 %36, label %38, label %37

37:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %62

38:                                               ; preds = %34
  %39 = load i32, ptr %4, align 4, !tbaa !9
  %40 = add nsw i32 %39, 397
  %41 = sub nsw i32 %40, 624
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %42
  %44 = load i64, ptr %43, align 8, !tbaa !11
  %45 = load i32, ptr %4, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !11
  %49 = load i32, ptr %4, align 4, !tbaa !9
  %50 = add nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !11
  %54 = call noundef i64 @_ZN12MTRand_int327twiddleEmm(ptr noundef nonnull align 1 dereferenceable(1) %5, i64 noundef %48, i64 noundef %53)
  %55 = xor i64 %44, %54
  %56 = load i32, ptr %4, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %57
  store i64 %55, ptr %58, align 8, !tbaa !11
  br label %59

59:                                               ; preds = %38
  %60 = load i32, ptr %4, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %4, align 4, !tbaa !9
  br label %34, !llvm.loop !15

62:                                               ; preds = %37
  %63 = load i64, ptr getelementptr inbounds ([624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 396), align 16, !tbaa !11
  %64 = load i64, ptr getelementptr inbounds ([624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 623), align 8, !tbaa !11
  %65 = load i64, ptr @_ZN12MTRand_int325stateE, align 16, !tbaa !11
  %66 = call noundef i64 @_ZN12MTRand_int327twiddleEmm(ptr noundef nonnull align 1 dereferenceable(1) %5, i64 noundef %64, i64 noundef %65)
  %67 = xor i64 %63, %66
  store i64 %67, ptr getelementptr inbounds ([624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 623), align 8, !tbaa !11
  store i32 0, ptr @_ZN12MTRand_int321pE, align 4, !tbaa !9
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN12MTRand_int327twiddleEmm(ptr noundef nonnull align 1 dereferenceable(1), i64 noundef, i64 noundef) #2 align 2

; 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 = { 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 = { 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
define dso_local void @_ZN12MTRand_int329gen_stateEv(ptr noundef nonnull align 1 dereferenceable(1) %0) local_unnamed_addr #0 align 2 {
  br label %2

2:                                                ; preds = %1, %2
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next, %2 ]
  %3 = add nuw nsw i64 %indvars.iv, 397
  %4 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %3
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %indvars.iv
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %8 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %indvars.iv.next
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = tail call noundef i64 @_ZN12MTRand_int327twiddleEmm(ptr noundef nonnull align 1 dereferenceable(1) %0, i64 noundef %7, i64 noundef %9)
  %11 = xor i64 %10, %5
  store i64 %11, ptr %6, align 8, !tbaa !5
  %exitcond.not = icmp eq i64 %indvars.iv.next, 227
  br i1 %exitcond.not, label %.preheader, label %2, !llvm.loop !9

12:                                               ; preds = %.preheader
  %13 = load i64, ptr getelementptr inbounds (i8, ptr @_ZN12MTRand_int325stateE, i64 3168), align 16, !tbaa !5
  %14 = load i64, ptr getelementptr inbounds (i8, ptr @_ZN12MTRand_int325stateE, i64 4984), align 8, !tbaa !5
  %15 = load i64, ptr @_ZN12MTRand_int325stateE, align 16, !tbaa !5
  %16 = tail call noundef i64 @_ZN12MTRand_int327twiddleEmm(ptr noundef nonnull align 1 dereferenceable(1) %0, i64 noundef %14, i64 noundef %15)
  %17 = xor i64 %16, %13
  store i64 %17, ptr getelementptr inbounds (i8, ptr @_ZN12MTRand_int325stateE, i64 4984), align 8, !tbaa !5
  store i32 0, ptr @_ZN12MTRand_int321pE, align 4, !tbaa !11
  ret void

.preheader:                                       ; preds = %2, %.preheader
  %indvars.iv16 = phi i64 [ %indvars.iv.next17, %.preheader ], [ 227, %2 ]
  %18 = add nsw i64 %indvars.iv16, -227
  %19 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %indvars.iv16
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %indvars.iv.next17 = add nuw nsw i64 %indvars.iv16, 1
  %23 = getelementptr inbounds [624 x i64], ptr @_ZN12MTRand_int325stateE, i64 0, i64 %indvars.iv.next17
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = tail call noundef i64 @_ZN12MTRand_int327twiddleEmm(ptr noundef nonnull align 1 dereferenceable(1) %0, i64 noundef %22, i64 noundef %24)
  %26 = xor i64 %25, %20
  store i64 %26, ptr %21, align 8, !tbaa !5
  %exitcond19.not = icmp eq i64 %indvars.iv.next17, 623
  br i1 %exitcond19.not, label %12, label %.preheader, !llvm.loop !13
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN12MTRand_int327twiddleEmm(ptr noundef nonnull align 1 dereferenceable(1), i64 noundef, i64 noundef) local_unnamed_addr #1 align 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 = { 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, !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,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass