; LLVM IR from jingweizhanghuai/Morn :: src/util (morn_universal)

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

@morn_rand_seed = external hidden global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local i32 @m_Rand(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %8 = load i32, ptr @morn_rand_seed, align 4, !tbaa !5
  %9 = icmp eq i32 %8, -1
  br i1 %9, label %10, label %14

10:                                               ; preds = %2
  %11 = call i64 @time(ptr noundef null) #3
  %12 = trunc i64 %11 to i32
  store i32 %12, ptr @morn_rand_seed, align 4, !tbaa !5
  %13 = load i32, ptr @morn_rand_seed, align 4, !tbaa !5
  call void @srand(i32 noundef %13) #3
  br label %14

14:                                               ; preds = %10, %2
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = icmp eq i32 %15, -1
  br i1 %16, label %17, label %22

17:                                               ; preds = %14
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = icmp eq i32 %18, -1
  br i1 %19, label %20, label %22

20:                                               ; preds = %17
  %21 = call i32 @rand() #3
  store i32 %21, ptr %3, align 4
  br label %50

22:                                               ; preds = %17, %14
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = icmp eq i32 %23, %24
  br i1 %25, label %26, label %28

26:                                               ; preds = %22
  %27 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %27, ptr %3, align 4
  br label %50

28:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = sub nsw i32 %29, %30
  store i32 %31, ptr %6, align 4, !tbaa !5
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = icmp sgt i32 %32, 2147483647
  br i1 %33, label %34, label %43

34:                                               ; preds = %28
  %35 = call i32 @rand() #3
  %36 = shl i32 %35, 15
  %37 = call i32 @rand() #3
  %38 = add nsw i32 %36, %37
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = srem i32 %38, %39
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = add nsw i32 %40, %41
  store i32 %42, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %49

43:                                               ; preds = %28
  %44 = call i32 @rand() #3
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = srem i32 %44, %45
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = add nsw i32 %46, %47
  store i32 %48, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %49

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

50:                                               ; preds = %49, %26, %20
  %51 = load i32, ptr %3, align 4
  ret i32 %51
}

; Function Attrs: nounwind
declare i64 @time(ptr noundef) #1

; Function Attrs: nounwind
declare void @srand(i32 noundef) #1

; Function Attrs: nounwind
declare i32 @rand() #1

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

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

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" }
attributes #1 = { nounwind "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 willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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

@morn_rand_seed = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local i32 @m_Rand(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @morn_rand_seed, align 4, !tbaa !5
  %4 = icmp eq i32 %3, -1
  br i1 %4, label %5, label %8

5:                                                ; preds = %2
  %6 = tail call i64 @time(ptr noundef null) #2
  %7 = trunc i64 %6 to i32
  store i32 %7, ptr @morn_rand_seed, align 4, !tbaa !5
  tail call void @srand(i32 noundef %7) #2
  br label %8

8:                                                ; preds = %5, %2
  %9 = and i32 %1, %0
  %or.cond = icmp eq i32 %9, -1
  br i1 %or.cond, label %10, label %12

10:                                               ; preds = %8
  %11 = tail call i32 @rand() #2
  br label %19

12:                                               ; preds = %8
  %13 = icmp eq i32 %0, %1
  br i1 %13, label %19, label %14

14:                                               ; preds = %12
  %15 = tail call i32 @rand() #2
  %16 = sub nsw i32 %1, %0
  %17 = srem i32 %15, %16
  %18 = add nsw i32 %17, %0
  br label %19

19:                                               ; preds = %12, %14, %10
  %.1 = phi i32 [ %11, %10 ], [ %18, %14 ], [ %1, %12 ]
  ret i32 %.1
}

; Function Attrs: nounwind
declare i64 @time(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare void @srand(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #1

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" }
attributes #1 = { nounwind "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass