; LLVM IR from robinrodricks/InspiritImage :: Inspirit.Assurf/clib/kdtree (random)

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

%struct._VlRand = type { [624 x i32], i32 }

; Function Attrs: nounwind uwtable
define dso_local void @vl_rand_seed(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %5 = load i32, ptr %4, align 4, !tbaa !9
  %6 = zext i32 %5 to i64
  %7 = and i64 %6, 4294967295
  %8 = trunc i64 %7 to i32
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct._VlRand, ptr %9, i32 0, i32 0
  %11 = getelementptr inbounds [624 x i32], ptr %10, i64 0, i64 0
  store i32 %8, ptr %11, align 4, !tbaa !9
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._VlRand, ptr %12, i32 0, i32 1
  store i32 1, ptr %13, align 4, !tbaa !11
  br label %14

14:                                               ; preds = %66, %2
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._VlRand, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = icmp ult i32 %17, 624
  br i1 %18, label %19, label %71

19:                                               ; preds = %14
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._VlRand, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._VlRand, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %25 = sub i32 %24, 1
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds [624 x i32], ptr %21, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._VlRand, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._VlRand, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !11
  %34 = sub i32 %33, 1
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds [624 x i32], ptr %30, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = lshr i32 %37, 30
  %39 = xor i32 %28, %38
  %40 = zext i32 %39 to i64
  %41 = mul i64 1812433253, %40
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._VlRand, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 4, !tbaa !11
  %45 = zext i32 %44 to i64
  %46 = add i64 %41, %45
  %47 = trunc i64 %46 to i32
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct._VlRand, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._VlRand, ptr %50, i32 0, i32 1
  %52 = load i32, ptr %51, align 4, !tbaa !11
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds [624 x i32], ptr %49, i64 0, i64 %53
  store i32 %47, ptr %54, align 4, !tbaa !9
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._VlRand, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct._VlRand, ptr %57, i32 0, i32 1
  %59 = load i32, ptr %58, align 4, !tbaa !11
  %60 = zext i32 %59 to i64
  %61 = getelementptr inbounds [624 x i32], ptr %56, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = zext i32 %62 to i64
  %64 = and i64 %63, 4294967295
  %65 = trunc i64 %64 to i32
  store i32 %65, ptr %61, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %19
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct._VlRand, ptr %67, i32 0, i32 1
  %69 = load i32, ptr %68, align 4, !tbaa !11
  %70 = add i32 %69, 1
  store i32 %70, ptr %68, align 4, !tbaa !11
  br label %14, !llvm.loop !13

71:                                               ; preds = %14
  ret void
}

attributes #0 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 2496}
!12 = !{!"_VlRand", !7, i64 0, !10, i64 2496}
!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"

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @vl_rand_seed(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  store i32 %1, ptr %0, align 4, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 2496
  store i32 1, ptr %3, align 4, !tbaa !9
  br label %4

4:                                                ; preds = %2, %4
  %storemerge13 = phi i32 [ 1, %2 ], [ %16, %4 ]
  %5 = add nsw i32 %storemerge13, -1
  %6 = zext i32 %5 to i64
  %7 = getelementptr inbounds [624 x i32], ptr %0, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = lshr i32 %8, 30
  %10 = xor i32 %9, %8
  %11 = mul i32 %10, 1812433253
  %12 = zext nneg i32 %storemerge13 to i64
  %13 = add i32 %11, %storemerge13
  %14 = getelementptr inbounds [624 x i32], ptr %0, i64 0, i64 %12
  store i32 %13, ptr %14, align 4, !tbaa !5
  %15 = load i32, ptr %3, align 4, !tbaa !9
  %16 = add i32 %15, 1
  store i32 %16, ptr %3, align 4, !tbaa !9
  %17 = icmp ult i32 %16, 624
  br i1 %17, label %4, label %18, !llvm.loop !11

18:                                               ; preds = %4
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 2496}
!10 = !{!"_VlRand", !7, i64 0, !6, i64 2496}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass