; LLVM IR from interpretml/interpret :: shared/libebm (RandomDeterministic)

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

@.str = external hidden unnamed_addr constant [93 x i8], align 1
@__func__._ZN14NAMESPACE_MAIN19RandomDeterministic23GetOneTimePadConversionEm = external hidden unnamed_addr constant [24 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [67 x i8], align 1
@__PRETTY_FUNCTION__._ZN14NAMESPACE_MAIN19RandomDeterministic23GetOneTimePadConversionEm = external hidden unnamed_addr constant [97 x i8], align 1
@_ZN14NAMESPACE_MAINL16k_oneTimePadSeedE = external hidden constant [64 x i64], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN14NAMESPACE_MAIN19RandomDeterministic23GetOneTimePadConversionEm(i64 noundef %0) #0 align 2 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  %5 = load i64, ptr %2, align 8, !tbaa !5
  %6 = load i64, ptr %2, align 8, !tbaa !5
  %7 = icmp eq i64 %5, %6
  br i1 %7, label %10, label %8

8:                                                ; preds = %1
  call void @LogAssertFailure(i64 noundef 89, ptr noundef @.str, ptr noundef @__func__._ZN14NAMESPACE_MAIN19RandomDeterministic23GetOneTimePadConversionEm, ptr noundef @.str.1)
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str, i32 noundef 89, ptr noundef @__PRETTY_FUNCTION__._ZN14NAMESPACE_MAIN19RandomDeterministic23GetOneTimePadConversionEm) #5
  unreachable

9:                                                ; No predecessors!
  br label %10

10:                                               ; preds = %9, %1
  %11 = phi i1 [ true, %1 ], [ false, %9 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  store i64 7744400872392380017, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  store ptr @_ZN14NAMESPACE_MAINL16k_oneTimePadSeedE, ptr %4, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %28, %10
  %13 = load i64, ptr %2, align 8, !tbaa !5
  %14 = and i64 1, %13
  %15 = icmp ne i64 0, %14
  %16 = xor i1 %15, true
  %17 = xor i1 %16, true
  br i1 %17, label %18, label %23, !unpredictable !11

18:                                               ; preds = %12
  %19 = load ptr, ptr %4, align 8, !tbaa !9
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = load i64, ptr %3, align 8, !tbaa !5
  %22 = xor i64 %21, %20
  store i64 %22, ptr %3, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %18, %12
  %24 = load ptr, ptr %4, align 8, !tbaa !9
  %25 = getelementptr inbounds i64, ptr %24, i32 1
  store ptr %25, ptr %4, align 8, !tbaa !9
  %26 = load i64, ptr %2, align 8, !tbaa !5
  %27 = lshr i64 %26, 1
  store i64 %27, ptr %2, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %23
  %29 = load i64, ptr %2, align 8, !tbaa !5
  %30 = icmp ne i64 0, %29
  %31 = xor i1 %30, true
  %32 = xor i1 %31, true
  %33 = zext i1 %32 to i64
  %34 = call i64 @llvm.expect.i64(i64 %33, i64 1)
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %12, label %36, !llvm.loop !12

36:                                               ; preds = %28
  %37 = load i64, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  ret i64 %37
}

declare void @LogAssertFailure(i64 noundef, ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

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

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

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

attributes #0 = { 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 #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 = { noreturn 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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #5 = { noreturn nounwind }
attributes #6 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@_ZN14NAMESPACE_MAINL16k_oneTimePadSeedE = external hidden local_unnamed_addr constant [64 x i64], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef i64 @_ZN14NAMESPACE_MAIN19RandomDeterministic23GetOneTimePadConversionEm(i64 noundef %0) local_unnamed_addr #0 align 2 {
  br label %2

2:                                                ; preds = %7, %1
  %.09 = phi i64 [ %0, %1 ], [ %9, %7 ]
  %.08 = phi i64 [ 7744400872392380017, %1 ], [ %.1, %7 ]
  %.0 = phi ptr [ @_ZN14NAMESPACE_MAINL16k_oneTimePadSeedE, %1 ], [ %8, %7 ]
  %3 = and i64 %.09, 1
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %7, label %4, !unpredictable !5

4:                                                ; preds = %2
  %5 = load i64, ptr %.0, align 8, !tbaa !6
  %6 = xor i64 %5, %.08
  br label %7

7:                                                ; preds = %4, %2
  %.1 = phi i64 [ %6, %4 ], [ %.08, %2 ]
  %8 = getelementptr inbounds i8, ptr %.0, i64 8
  %9 = lshr i64 %.09, 1
  %.not11 = icmp ult i64 %.09, 2
  br i1 %.not11, label %10, label %2, !prof !10, !llvm.loop !11

10:                                               ; preds = %7
  ret i64 %.1
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(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" }

!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, !7, i64 0}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopUnrollPass,LowerExpectIntrinsicPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass