; LLVM IR from Dimandragon/non-parametric-dsp :: 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"

%"struct.alglib_impl::hqrndstate" = type { i64, i64, i64 }

@_ZN11alglib_implL16hqrnd_hqrndmagicE = external hidden global i64, align 8
@.str.22 = external hidden unnamed_addr constant [54 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_impl16hqrndintegerbaseEPNS_10hqrndstateEPNS_8ae_stateE(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %"struct.alglib_impl::hqrndstate", ptr %7, i32 0, i32 2
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = load i64, ptr @_ZN11alglib_implL16hqrnd_hqrndmagicE, align 8, !tbaa !12
  %11 = icmp ne i64 %9, %10
  br i1 %11, label %12, label %14

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext false, ptr noundef @.str.22, ptr noundef %13)
  br label %14

14:                                               ; preds = %12, %2
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %"struct.alglib_impl::hqrndstate", ptr %15, i32 0, i32 0
  %17 = load i64, ptr %16, align 8, !tbaa !13
  %18 = sdiv i64 %17, 53668
  store i64 %18, ptr %5, align 8, !tbaa !12
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.alglib_impl::hqrndstate", ptr %19, i32 0, i32 0
  %21 = load i64, ptr %20, align 8, !tbaa !13
  %22 = load i64, ptr %5, align 8, !tbaa !12
  %23 = mul nsw i64 %22, 53668
  %24 = sub nsw i64 %21, %23
  %25 = mul nsw i64 40014, %24
  %26 = load i64, ptr %5, align 8, !tbaa !12
  %27 = mul nsw i64 %26, 12211
  %28 = sub nsw i64 %25, %27
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %"struct.alglib_impl::hqrndstate", ptr %29, i32 0, i32 0
  store i64 %28, ptr %30, align 8, !tbaa !13
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %"struct.alglib_impl::hqrndstate", ptr %31, i32 0, i32 0
  %33 = load i64, ptr %32, align 8, !tbaa !13
  %34 = icmp slt i64 %33, 0
  br i1 %34, label %35, label %42

35:                                               ; preds = %14
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %"struct.alglib_impl::hqrndstate", ptr %36, i32 0, i32 0
  %38 = load i64, ptr %37, align 8, !tbaa !13
  %39 = add nsw i64 %38, 2147483563
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %"struct.alglib_impl::hqrndstate", ptr %40, i32 0, i32 0
  store i64 %39, ptr %41, align 8, !tbaa !13
  br label %42

42:                                               ; preds = %35, %14
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %"struct.alglib_impl::hqrndstate", ptr %43, i32 0, i32 1
  %45 = load i64, ptr %44, align 8, !tbaa !14
  %46 = sdiv i64 %45, 52774
  store i64 %46, ptr %5, align 8, !tbaa !12
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.alglib_impl::hqrndstate", ptr %47, i32 0, i32 1
  %49 = load i64, ptr %48, align 8, !tbaa !14
  %50 = load i64, ptr %5, align 8, !tbaa !12
  %51 = mul nsw i64 %50, 52774
  %52 = sub nsw i64 %49, %51
  %53 = mul nsw i64 40692, %52
  %54 = load i64, ptr %5, align 8, !tbaa !12
  %55 = mul nsw i64 %54, 3791
  %56 = sub nsw i64 %53, %55
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %"struct.alglib_impl::hqrndstate", ptr %57, i32 0, i32 1
  store i64 %56, ptr %58, align 8, !tbaa !14
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %"struct.alglib_impl::hqrndstate", ptr %59, i32 0, i32 1
  %61 = load i64, ptr %60, align 8, !tbaa !14
  %62 = icmp slt i64 %61, 0
  br i1 %62, label %63, label %70

63:                                               ; preds = %42
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %"struct.alglib_impl::hqrndstate", ptr %64, i32 0, i32 1
  %66 = load i64, ptr %65, align 8, !tbaa !14
  %67 = add nsw i64 %66, 2147483399
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %"struct.alglib_impl::hqrndstate", ptr %68, i32 0, i32 1
  store i64 %67, ptr %69, align 8, !tbaa !14
  br label %70

70:                                               ; preds = %63, %42
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %"struct.alglib_impl::hqrndstate", ptr %71, i32 0, i32 0
  %73 = load i64, ptr %72, align 8, !tbaa !13
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %"struct.alglib_impl::hqrndstate", ptr %74, i32 0, i32 1
  %76 = load i64, ptr %75, align 8, !tbaa !14
  %77 = sub nsw i64 %73, %76
  store i64 %77, ptr %6, align 8, !tbaa !12
  %78 = load i64, ptr %6, align 8, !tbaa !12
  %79 = icmp slt i64 %78, 1
  br i1 %79, label %80, label %83

80:                                               ; preds = %70
  %81 = load i64, ptr %6, align 8, !tbaa !12
  %82 = add nsw i64 %81, 2147483562
  store i64 %82, ptr %6, align 8, !tbaa !12
  br label %83

83:                                               ; preds = %80, %70
  %84 = load i64, ptr %6, align 8, !tbaa !12
  %85 = sub nsw i64 %84, 1
  store i64 %85, ptr %6, align 8, !tbaa !12
  %86 = load i64, ptr %6, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i64 %86
}

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, !11, i64 16}
!10 = !{!"_ZTSN11alglib_impl10hqrndstateE", !11, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 0}
!14 = !{!10, !11, i64 8}


; 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_implL16hqrnd_hqrndmagicE = external hidden local_unnamed_addr global i64, align 8
@.str.22 = external hidden unnamed_addr constant [54 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 range(i64 -9223372034707292247, 9223372036854775807) i64 @_ZN11alglib_impl16hqrndintegerbaseEPNS_10hqrndstateEPNS_8ae_stateE(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = load i64, ptr @_ZN11alglib_implL16hqrnd_hqrndmagicE, align 8, !tbaa !10
  %.not = icmp eq i64 %4, %5
  br i1 %.not, label %7, label %6

6:                                                ; preds = %2
  tail call void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext false, ptr noundef nonnull @.str.22, ptr noundef %1)
  br label %7

7:                                                ; preds = %6, %2
  %8 = load i64, ptr %0, align 8, !tbaa !11
  %9 = sdiv i64 %8, 53668
  %.neg = mul nsw i64 %9, -53668
  %10 = add i64 %.neg, %8
  %11 = mul nsw i64 %10, 40014
  %.neg26 = mul nsw i64 %9, -12211
  %12 = add i64 %11, %.neg26
  %13 = icmp slt i64 %12, 0
  %14 = add nsw i64 %12, 2147483563
  %spec.select = select i1 %13, i64 %14, i64 %12
  store i64 %spec.select, ptr %0, align 8, !tbaa !11
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load i64, ptr %15, align 8, !tbaa !12
  %17 = sdiv i64 %16, 52774
  %.neg27 = mul nsw i64 %17, -52774
  %18 = add i64 %.neg27, %16
  %19 = mul nsw i64 %18, 40692
  %.neg28 = mul nsw i64 %17, -3791
  %20 = add i64 %19, %.neg28
  %21 = icmp slt i64 %20, 0
  %22 = add nsw i64 %20, 2147483399
  %storemerge29 = select i1 %21, i64 %22, i64 %20
  store i64 %storemerge29, ptr %15, align 8, !tbaa !12
  %23 = sub nsw i64 %spec.select, %storemerge29
  %24 = icmp slt i64 %23, 1
  %25 = add nsw i64 %23, 2147483562
  %.0 = select i1 %24, i64 %25, i64 %23
  %26 = add nsw i64 %.0, -1
  ret i64 %26
}

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, !7, i64 16}
!6 = !{!"_ZTSN11alglib_impl10hqrndstateE", !7, i64 0, !7, i64 8, !7, i64 16}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 8}


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