; LLVM IR from venumb/ZSPACE :: cpp/depends/alglib/cpp/src (alglibmisc)

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

@_ZN11alglib_implL14hqrnd_hqrndmaxE = external hidden global i64, align 8
@.str.61 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.62 = external hidden unnamed_addr constant [30 x i8], align 1

; 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

declare void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext, ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN11alglib_impl13hqrnduniformiEPNS_10hqrndstateElPNS_8ae_stateE(ptr noundef %0, i64 noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %12 = load i64, ptr %5, align 8, !tbaa !9
  %13 = icmp sgt i64 %12, 0
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext %13, ptr noundef @.str.61, ptr noundef %14)
  %15 = load i64, ptr @_ZN11alglib_implL14hqrnd_hqrndmaxE, align 8, !tbaa !9
  %16 = add nsw i64 %15, 1
  store i64 %16, ptr %7, align 8, !tbaa !9
  %17 = load i64, ptr %5, align 8, !tbaa !9
  %18 = load i64, ptr %7, align 8, !tbaa !9
  %19 = icmp sgt i64 %17, %18
  br i1 %19, label %20, label %90

20:                                               ; preds = %3
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = load i64, ptr %7, align 8, !tbaa !9
  %23 = srem i64 %21, %22
  %24 = icmp eq i64 %23, 0
  br i1 %24, label %25, label %47

25:                                               ; preds = %20
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = load i64, ptr %7, align 8, !tbaa !9
  %28 = sdiv i64 %26, %27
  %29 = load i64, ptr %7, align 8, !tbaa !9
  %30 = icmp sle i64 %28, %29
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext %30, ptr noundef @.str.62, ptr noundef %31)
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load i64, ptr %7, align 8, !tbaa !9
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = call noundef i64 @_ZN11alglib_impl13hqrnduniformiEPNS_10hqrndstateElPNS_8ae_stateE(ptr noundef %32, i64 noundef %33, ptr noundef %34)
  store i64 %35, ptr %9, align 8, !tbaa !9
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load i64, ptr %5, align 8, !tbaa !9
  %38 = load i64, ptr %7, align 8, !tbaa !9
  %39 = sdiv i64 %37, %38
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = call noundef i64 @_ZN11alglib_impl13hqrnduniformiEPNS_10hqrndstateElPNS_8ae_stateE(ptr noundef %36, i64 noundef %39, ptr noundef %40)
  store i64 %41, ptr %10, align 8, !tbaa !9
  %42 = load i64, ptr %9, align 8, !tbaa !9
  %43 = load i64, ptr %7, align 8, !tbaa !9
  %44 = load i64, ptr %10, align 8, !tbaa !9
  %45 = mul nsw i64 %43, %44
  %46 = add nsw i64 %42, %45
  store i64 %46, ptr %11, align 8, !tbaa !9
  br label %89

47:                                               ; preds = %20
  %48 = load i64, ptr %5, align 8, !tbaa !9
  %49 = load i64, ptr %7, align 8, !tbaa !9
  %50 = sdiv i64 %48, %49
  %51 = add nsw i64 %50, 1
  %52 = load i64, ptr %7, align 8, !tbaa !9
  %53 = icmp sle i64 %51, %52
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext %53, ptr noundef @.str.62, ptr noundef %54)
  store i64 -1, ptr %11, align 8, !tbaa !9
  br label %55

55:                                               ; preds = %85, %47
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load i64, ptr %7, align 8, !tbaa !9
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = call noundef i64 @_ZN11alglib_impl13hqrnduniformiEPNS_10hqrndstateElPNS_8ae_stateE(ptr noundef %56, i64 noundef %57, ptr noundef %58)
  store i64 %59, ptr %9, align 8, !tbaa !9
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load i64, ptr %5, align 8, !tbaa !9
  %62 = load i64, ptr %7, align 8, !tbaa !9
  %63 = sdiv i64 %61, %62
  %64 = add nsw i64 %63, 1
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = call noundef i64 @_ZN11alglib_impl13hqrnduniformiEPNS_10hqrndstateElPNS_8ae_stateE(ptr noundef %60, i64 noundef %64, ptr noundef %65)
  store i64 %66, ptr %10, align 8, !tbaa !9
  %67 = load i64, ptr %10, align 8, !tbaa !9
  %68 = load i64, ptr %5, align 8, !tbaa !9
  %69 = load i64, ptr %7, align 8, !tbaa !9
  %70 = sdiv i64 %68, %69
  %71 = icmp eq i64 %67, %70
  br i1 %71, label %72, label %79

72:                                               ; preds = %55
  %73 = load i64, ptr %9, align 8, !tbaa !9
  %74 = load i64, ptr %5, align 8, !tbaa !9
  %75 = load i64, ptr %7, align 8, !tbaa !9
  %76 = srem i64 %74, %75
  %77 = icmp sge i64 %73, %76
  br i1 %77, label %78, label %79

78:                                               ; preds = %72
  br label %85

79:                                               ; preds = %72, %55
  %80 = load i64, ptr %9, align 8, !tbaa !9
  %81 = load i64, ptr %7, align 8, !tbaa !9
  %82 = load i64, ptr %10, align 8, !tbaa !9
  %83 = mul nsw i64 %81, %82
  %84 = add nsw i64 %80, %83
  store i64 %84, ptr %11, align 8, !tbaa !9
  br label %85

85:                                               ; preds = %79, %78
  %86 = load i64, ptr %11, align 8, !tbaa !9
  %87 = icmp slt i64 %86, 0
  br i1 %87, label %55, label %88, !llvm.loop !11

88:                                               ; preds = %85
  br label %89

89:                                               ; preds = %88, %25
  br label %108

90:                                               ; preds = %3
  %91 = load i64, ptr %7, align 8, !tbaa !9
  %92 = load i64, ptr %7, align 8, !tbaa !9
  %93 = load i64, ptr %5, align 8, !tbaa !9
  %94 = srem i64 %92, %93
  %95 = sub nsw i64 %91, %94
  store i64 %95, ptr %8, align 8, !tbaa !9
  br label %96

96:                                               ; preds = %100, %90
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = load ptr, ptr %6, align 8, !tbaa !5
  %99 = call noundef i64 @_ZN11alglib_implL22hqrnd_hqrndintegerbaseEPNS_10hqrndstateEPNS_8ae_stateE(ptr noundef %97, ptr noundef %98)
  store i64 %99, ptr %11, align 8, !tbaa !9
  br label %100

100:                                              ; preds = %96
  %101 = load i64, ptr %11, align 8, !tbaa !9
  %102 = load i64, ptr %8, align 8, !tbaa !9
  %103 = icmp sge i64 %101, %102
  br i1 %103, label %96, label %104, !llvm.loop !13

104:                                              ; preds = %100
  %105 = load i64, ptr %11, align 8, !tbaa !9
  %106 = load i64, ptr %5, align 8, !tbaa !9
  %107 = srem i64 %105, %106
  store i64 %107, ptr %11, align 8, !tbaa !9
  br label %108

108:                                              ; preds = %104, %89
  %109 = load i64, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i64 %109
}

; Function Attrs: mustprogress uwtable
declare hidden noundef i64 @_ZN11alglib_implL22hqrnd_hqrndintegerbaseEPNS_10hqrndstateEPNS_8ae_stateE(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #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 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@_ZN11alglib_implL14hqrnd_hqrndmaxE = external hidden local_unnamed_addr global i64, align 8
@.str.61 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.62 = external hidden unnamed_addr constant [30 x i8], align 1

declare void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN11alglib_impl13hqrnduniformiEPNS_10hqrndstateElPNS_8ae_stateE(ptr noundef %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = icmp sgt i64 %1, 0
  tail call void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext %4, ptr noundef nonnull @.str.61, ptr noundef %2)
  %5 = load i64, ptr @_ZN11alglib_implL14hqrnd_hqrndmaxE, align 8, !tbaa !5
  %6 = add nsw i64 %5, 1
  %7 = icmp slt i64 %6, %1
  br i1 %7, label %8, label %28

8:                                                ; preds = %3
  %9 = srem i64 %1, %6
  %10 = icmp eq i64 %9, 0
  %11 = sdiv i64 %1, %6
  br i1 %10, label %12, label %18

common.ret57:                                     ; preds = %33, %21, %12
  %common.ret57.op = phi i64 [ %17, %12 ], [ %34, %33 ], [ %.1, %21 ]
  ret i64 %common.ret57.op

12:                                               ; preds = %8
  %13 = icmp sle i64 %11, %6
  tail call void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext %13, ptr noundef nonnull @.str.62, ptr noundef %2)
  %14 = tail call noundef i64 @_ZN11alglib_impl13hqrnduniformiEPNS_10hqrndstateElPNS_8ae_stateE(ptr noundef %0, i64 noundef %6, ptr noundef %2)
  %15 = tail call noundef i64 @_ZN11alglib_impl13hqrnduniformiEPNS_10hqrndstateElPNS_8ae_stateE(ptr noundef %0, i64 noundef %11, ptr noundef %2)
  %16 = mul nsw i64 %15, %6
  %17 = add nsw i64 %16, %14
  br label %common.ret57

18:                                               ; preds = %8
  %19 = add nsw i64 %11, 1
  %20 = icmp sle i64 %11, %5
  tail call void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext %20, ptr noundef nonnull @.str.62, ptr noundef %2)
  br label %21

21:                                               ; preds = %21, %18
  %.0 = phi i64 [ -1, %18 ], [ %.1, %21 ]
  %22 = tail call noundef i64 @_ZN11alglib_impl13hqrnduniformiEPNS_10hqrndstateElPNS_8ae_stateE(ptr noundef %0, i64 noundef %6, ptr noundef %2)
  %23 = tail call noundef i64 @_ZN11alglib_impl13hqrnduniformiEPNS_10hqrndstateElPNS_8ae_stateE(ptr noundef %0, i64 noundef %19, ptr noundef %2)
  %24 = icmp ne i64 %23, %11
  %.not56 = icmp slt i64 %22, %9
  %or.cond = or i1 %.not56, %24
  %25 = mul nsw i64 %23, %6
  %26 = add nsw i64 %25, %22
  %.1 = select i1 %or.cond, i64 %26, i64 %.0
  %27 = icmp slt i64 %.1, 0
  br i1 %27, label %21, label %common.ret57, !llvm.loop !9

28:                                               ; preds = %3
  %29 = srem i64 %6, %1
  %30 = sub nsw i64 %6, %29
  br label %31

31:                                               ; preds = %31, %28
  %32 = tail call noundef i64 @_ZN11alglib_implL22hqrnd_hqrndintegerbaseEPNS_10hqrndstateEPNS_8ae_stateE(ptr noundef %0, ptr noundef %2)
  %.not = icmp slt i64 %32, %30
  br i1 %.not, label %33, label %31, !llvm.loop !11

33:                                               ; preds = %31
  %34 = srem i64 %32, %1
  br label %common.ret57
}

; Function Attrs: mustprogress uwtable
declare hidden noundef i64 @_ZN11alglib_implL22hqrnd_hqrndintegerbaseEPNS_10hqrndstateEPNS_8ae_stateE(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #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 = { 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" }

!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 = distinct !{!11, !10}


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