; LLVM IR from dynexcoin/Dynex :: src/crypto (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"

%union.hash_state = type { [25 x i64] }

@curstate = external hidden global i32, align 4
@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [69 x i8], align 1
@state = external hidden global %union.hash_state, align 1
@__PRETTY_FUNCTION__.generate_random_bytes = external hidden unnamed_addr constant [43 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @generate_random_bytes(i64 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  %5 = load volatile i32, ptr @curstate, align 4, !tbaa !11
  %6 = icmp eq i32 %5, 1
  br i1 %6, label %7, label %8

7:                                                ; preds = %2
  br label %9

8:                                                ; preds = %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 125, ptr noundef @__PRETTY_FUNCTION__.generate_random_bytes) #5
  unreachable

9:                                                ; preds = %7
  store volatile i32 2, ptr @curstate, align 4, !tbaa !11
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = icmp eq i64 %10, 0
  br i1 %11, label %12, label %18

12:                                               ; preds = %9
  %13 = load volatile i32, ptr @curstate, align 4, !tbaa !11
  %14 = icmp eq i32 %13, 2
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  br label %17

16:                                               ; preds = %12
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 130, ptr noundef @__PRETTY_FUNCTION__.generate_random_bytes) #5
  unreachable

17:                                               ; preds = %15
  store volatile i32 1, ptr @curstate, align 4, !tbaa !11
  br label %37

18:                                               ; preds = %9
  br label %19

19:                                               ; preds = %36, %18
  call void @hash_permutation(ptr noundef @state)
  %20 = load i64, ptr %3, align 8, !tbaa !5
  %21 = icmp ule i64 %20, 136
  br i1 %21, label %22, label %30

22:                                               ; preds = %19
  %23 = load ptr, ptr %4, align 8, !tbaa !9
  %24 = load i64, ptr %3, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %23, ptr align 1 @state, i64 %24, i1 false)
  %25 = load volatile i32, ptr @curstate, align 4, !tbaa !11
  %26 = icmp eq i32 %25, 2
  br i1 %26, label %27, label %28

27:                                               ; preds = %22
  br label %29

28:                                               ; preds = %22
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 140, ptr noundef @__PRETTY_FUNCTION__.generate_random_bytes) #5
  unreachable

29:                                               ; preds = %27
  store volatile i32 1, ptr @curstate, align 4, !tbaa !11
  br label %37

30:                                               ; preds = %19
  %31 = load ptr, ptr %4, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %31, ptr align 1 @state, i64 136, i1 false)
  %32 = load ptr, ptr %4, align 8, !tbaa !9
  %33 = call ptr @padd(ptr noundef %32, i64 noundef 136)
  store ptr %33, ptr %4, align 8, !tbaa !9
  %34 = load i64, ptr %3, align 8, !tbaa !5
  %35 = sub i64 %34, 136
  store i64 %35, ptr %3, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %30
  br label %19

37:                                               ; preds = %29, %17
  ret void
}

declare void @hash_permutation(ptr noundef) #2

; 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) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @padd(ptr noundef, i64 noundef) #4

attributes #0 = { 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 #1 = { 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 #2 = { "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 nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { inlinehint 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 #5 = { noreturn 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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"

%union.hash_state = type { [25 x i64] }

@curstate = external hidden global i32, align 4
@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [69 x i8], align 1
@state = external hidden global %union.hash_state, align 1
@__PRETTY_FUNCTION__.generate_random_bytes = external hidden unnamed_addr constant [43 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @generate_random_bytes(i64 noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = load volatile i32, ptr @curstate, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 1
  br i1 %4, label %6, label %5

5:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 125, ptr noundef nonnull @__PRETTY_FUNCTION__.generate_random_bytes) #5
  unreachable

6:                                                ; preds = %2
  store volatile i32 2, ptr @curstate, align 4, !tbaa !5
  %7 = icmp eq i64 %0, 0
  br i1 %7, label %9, label %.preheader

.preheader:                                       ; preds = %6
  tail call void @hash_permutation(ptr noundef nonnull @state) #6
  %8 = icmp ult i64 %0, 137
  br i1 %8, label %._crit_edge, label %.lr.ph

9:                                                ; preds = %6
  %10 = load volatile i32, ptr @curstate, align 4, !tbaa !5
  %11 = icmp eq i32 %10, 2
  br i1 %11, label %19, label %12

12:                                               ; preds = %9
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 130, ptr noundef nonnull @__PRETTY_FUNCTION__.generate_random_bytes) #5
  unreachable

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.06.lcssa = phi i64 [ %0, %.preheader ], [ %17, %.lr.ph ]
  %.0.lcssa = phi ptr [ %1, %.preheader ], [ %16, %.lr.ph ]
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %.0.lcssa, ptr nonnull align 1 @state, i64 %.06.lcssa, i1 false)
  %13 = load volatile i32, ptr @curstate, align 4, !tbaa !5
  %14 = icmp eq i32 %13, 2
  br i1 %14, label %19, label %15

15:                                               ; preds = %._crit_edge
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 140, ptr noundef nonnull @__PRETTY_FUNCTION__.generate_random_bytes) #5
  unreachable

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.09 = phi ptr [ %16, %.lr.ph ], [ %1, %.preheader ]
  %.068 = phi i64 [ %17, %.lr.ph ], [ %0, %.preheader ]
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(136) %.09, ptr noundef nonnull align 1 dereferenceable(136) @state, i64 136, i1 false)
  %16 = tail call ptr @padd(ptr noundef %.09, i64 noundef 136)
  %17 = add i64 %.068, -136
  tail call void @hash_permutation(ptr noundef nonnull @state) #6
  %18 = icmp ult i64 %17, 137
  br i1 %18, label %._crit_edge, label %.lr.ph

19:                                               ; preds = %._crit_edge, %9
  store volatile i32 1, ptr @curstate, align 4, !tbaa !5
  ret void
}

declare void @hash_permutation(ptr noundef) local_unnamed_addr #2

; 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) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @padd(ptr noundef, i64 noundef) local_unnamed_addr #4

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


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