; LLVM IR from godzilla-foundation/godzilla-community :: core/deps/nanomsg-1.1.5/src/utils (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"

@nn_random_state = external hidden global i64, align 8

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @nn_random_generate(ptr noundef %0, i64 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %6, ptr %5, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %27, %2
  br label %8

8:                                                ; preds = %7
  %9 = load i64, ptr @nn_random_state, align 8, !tbaa !9
  %10 = mul i64 %9, 1103515245
  %11 = add i64 %10, 12345
  store i64 %11, ptr @nn_random_state, align 8, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load i64, ptr %4, align 8, !tbaa !9
  %14 = icmp ugt i64 %13, 8
  br i1 %14, label %15, label %16

15:                                               ; preds = %8
  br label %18

16:                                               ; preds = %8
  %17 = load i64, ptr %4, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %16, %15
  %19 = phi i64 [ 8, %15 ], [ %17, %16 ]
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %12, ptr align 8 @nn_random_state, i64 %19, i1 false)
  %20 = load i64, ptr %4, align 8, !tbaa !9
  %21 = icmp ule i64 %20, 8
  %22 = zext i1 %21 to i32
  %23 = sext i32 %22 to i64
  %24 = call i64 @llvm.expect.i64(i64 %23, i64 1)
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void

27:                                               ; preds = %18
  %28 = load i64, ptr %4, align 8, !tbaa !9
  %29 = sub i64 %28, 8
  store i64 %29, ptr %4, align 8, !tbaa !9
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 8
  store ptr %31, ptr %5, align 8, !tbaa !5
  br label %7
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #4 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}


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

@nn_random_state = external hidden local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @nn_random_generate(ptr nocapture noundef writeonly %0, i64 noundef %1) local_unnamed_addr #1 {
  %3 = load i64, ptr @nn_random_state, align 8, !tbaa !5
  %4 = mul i64 %3, 1103515245
  %5 = add i64 %4, 12345
  store i64 %5, ptr @nn_random_state, align 8, !tbaa !5
  %6 = tail call i64 @llvm.umin.i64(i64 %1, i64 8)
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %0, ptr nonnull align 8 @nn_random_state, i64 %6, i1 false)
  %7 = icmp ult i64 %1, 9
  br i1 %7, label %._crit_edge, label %.lr.ph, !prof !9

.lr.ph:                                           ; preds = %2
  %nn_random_state.promoted = load i64, ptr @nn_random_state, align 8, !tbaa !5
  %8 = add i64 %1, -9
  %9 = and i64 %8, 8
  %lcmp.mod.not.not = icmp eq i64 %9, 0
  br i1 %lcmp.mod.not.not, label %.prol.loopexit.unr-lcssa, label %.prol.loopexit, !prof !10

.prol.loopexit.unr-lcssa:                         ; preds = %.lr.ph
  %10 = add i64 %1, -8
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = mul i64 %nn_random_state.promoted, 1103515245
  %13 = add i64 %12, 12345
  store i64 %13, ptr @nn_random_state, align 8, !tbaa !5
  %14 = tail call i64 @llvm.umin.i64(i64 %10, i64 8)
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %11, ptr nonnull align 8 @nn_random_state, i64 %14, i1 false)
  br label %.prol.loopexit

.prol.loopexit:                                   ; preds = %.prol.loopexit.unr-lcssa, %.lr.ph
  %.unr = phi i64 [ %nn_random_state.promoted, %.lr.ph ], [ %13, %.prol.loopexit.unr-lcssa ]
  %.08.unr = phi ptr [ %0, %.lr.ph ], [ %11, %.prol.loopexit.unr-lcssa ]
  %.067.unr = phi i64 [ %1, %.lr.ph ], [ %10, %.prol.loopexit.unr-lcssa ]
  %15 = icmp ult i64 %8, 8
  br i1 %15, label %._crit_edge, label %.lr.ph.new, !prof !10

._crit_edge:                                      ; preds = %.prol.loopexit, %.lr.ph.new, %2
  ret void

.lr.ph.new:                                       ; preds = %.prol.loopexit, %.lr.ph.new
  %16 = phi i64 [ %25, %.lr.ph.new ], [ %.unr, %.prol.loopexit ]
  %.08 = phi ptr [ %23, %.lr.ph.new ], [ %.08.unr, %.prol.loopexit ]
  %.067 = phi i64 [ %22, %.lr.ph.new ], [ %.067.unr, %.prol.loopexit ]
  %17 = add i64 %.067, -8
  %18 = getelementptr inbounds i8, ptr %.08, i64 8
  %19 = mul i64 %16, 1103515245
  %20 = add i64 %19, 12345
  store i64 %20, ptr @nn_random_state, align 8, !tbaa !5
  %21 = tail call i64 @llvm.umin.i64(i64 %17, i64 8)
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %18, ptr nonnull align 8 @nn_random_state, i64 %21, i1 false)
  %22 = add i64 %.067, -16
  %23 = getelementptr inbounds i8, ptr %.08, i64 16
  %24 = mul i64 %20, 1103515245
  %25 = add i64 %24, 12345
  store i64 %25, ptr @nn_random_state, align 8, !tbaa !5
  %26 = tail call i64 @llvm.umin.i64(i64 %22, i64 8)
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %23, ptr nonnull align 8 @nn_random_state, i64 %26, i1 false)
  %27 = icmp ult i64 %22, 9
  br i1 %27, label %._crit_edge, label %.lr.ph.new, !prof !11
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #2

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree norecurse nosync nounwind memory(readwrite, 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" }
attributes #2 = { 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/C++ TBAA"}
!9 = !{!"branch_weights", i32 1999, i32 1}
!10 = !{!"branch_weights", i32 1, i32 127}
!11 = !{!"branch_weights", i32 0, i32 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LowerExpectIntrinsicPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass