; LLVM IR from specinfo-ua/UAPKI :: library/uapkic/src (math-int-internal)

; 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.WordArray_st = type { ptr, i64 }

@.str = external hidden unnamed_addr constant [27 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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @int_is_zero(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @int_cmp(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @int_bit_len(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @int_truncate(ptr noundef, i64 noundef) #1

declare void @stacktrace_add(ptr noundef, i64 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @int_rand(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = 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
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = call i64 @int_bit_len(ptr noundef %8)
  store i64 %9, ptr %7, align 8, !tbaa !11
  br label %10

10:                                               ; preds = %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.WordArray_st, ptr %11, i32 0, i32 1
  %13 = load i64, ptr %12, align 8, !tbaa !13
  %14 = mul i64 %13, 8
  %15 = call ptr @ba_alloc_by_len(i64 noundef %14)
  store ptr %15, ptr %5, align 8, !tbaa !5
  %16 = icmp eq ptr null, %15
  br i1 %16, label %17, label %19

17:                                               ; preds = %10
  store i32 2, ptr %6, align 4, !tbaa !9
  %18 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 801, i32 noundef %18)
  br label %57

19:                                               ; preds = %10
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %54, %21
  br label %23

23:                                               ; preds = %22
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = call i32 @drbg_random(ptr noundef %24)
  store i32 %25, ptr %6, align 4, !tbaa !9
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %30

28:                                               ; preds = %23
  %29 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 804, i32 noundef %29)
  br label %57

30:                                               ; preds = %23
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = call i32 @wa_from_ba(ptr noundef %34, ptr noundef %35)
  store i32 %36, ptr %6, align 4, !tbaa !9
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %41

39:                                               ; preds = %33
  %40 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 805, i32 noundef %40)
  br label %57

41:                                               ; preds = %33
  br label %42

42:                                               ; preds = %41
  br label %43

43:                                               ; preds = %42
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = load i64, ptr %7, align 8, !tbaa !11
  call void @int_truncate(ptr noundef %44, i64 noundef %45)
  br label %46

46:                                               ; preds = %43
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = call i32 @int_cmp(ptr noundef %47, ptr noundef %48)
  %50 = icmp sge i32 %49, 0
  br i1 %50, label %54, label %51

51:                                               ; preds = %46
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = call zeroext i1 @int_is_zero(ptr noundef %52)
  br label %54

54:                                               ; preds = %51, %46
  %55 = phi i1 [ true, %46 ], [ %53, %51 ]
  br i1 %55, label %22, label %56, !llvm.loop !15

56:                                               ; preds = %54
  br label %57

57:                                               ; preds = %56, %39, %28, %17
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  call void @ba_free(ptr noundef %58)
  %59 = load i32, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i32 %59
}

declare ptr @ba_alloc_by_len(i64 noundef) #2

declare i32 @drbg_random(ptr noundef) #2

declare i32 @wa_from_ba(ptr noundef, ptr noundef) #2

declare void @ba_free(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"WordArray_st", !6, i64 0, !12, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@.str = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @int_is_zero(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @int_cmp(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @int_bit_len(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @int_truncate(ptr noundef, i64 noundef) local_unnamed_addr #0

declare void @stacktrace_add(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @int_rand(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call i64 @int_bit_len(ptr noundef %0)
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = shl i64 %5, 3
  %7 = tail call ptr @ba_alloc_by_len(i64 noundef %6) #2
  %8 = icmp eq ptr %7, null
  br i1 %8, label %10, label %.critedge.preheader

.critedge.preheader:                              ; preds = %2
  %9 = tail call i32 @drbg_random(ptr noundef nonnull %7) #2
  %.not23 = icmp eq i32 %9, 0
  br i1 %.not23, label %.lr.ph, label %.critedge._crit_edge

10:                                               ; preds = %2
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 801, i32 noundef 2) #2
  br label %.loopexit

.critedge._crit_edge:                             ; preds = %.critedge.backedge, %.critedge.preheader
  %.lcssa = phi i32 [ %9, %.critedge.preheader ], [ %18, %.critedge.backedge ]
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 804, i32 noundef %.lcssa) #2
  br label %.loopexit

.lr.ph:                                           ; preds = %.critedge.preheader, %.critedge.backedge
  %11 = tail call i32 @wa_from_ba(ptr noundef nonnull %7, ptr noundef %1) #2
  %.not18 = icmp eq i32 %11, 0
  br i1 %.not18, label %13, label %12

12:                                               ; preds = %.lr.ph
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 805, i32 noundef %11) #2
  br label %.loopexit

13:                                               ; preds = %.lr.ph
  tail call void @int_truncate(ptr noundef %1, i64 noundef %3)
  %14 = tail call i32 @int_cmp(ptr noundef %1, ptr noundef %0)
  %15 = icmp sgt i32 %14, -1
  br i1 %15, label %.critedge.backedge, label %16

16:                                               ; preds = %13
  %17 = tail call zeroext i1 @int_is_zero(ptr noundef %1)
  br i1 %17, label %.critedge.backedge, label %.loopexit

.critedge.backedge:                               ; preds = %16, %13
  %18 = tail call i32 @drbg_random(ptr noundef nonnull %7) #2
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %.lr.ph, label %.critedge._crit_edge, !llvm.loop !11

.loopexit:                                        ; preds = %16, %12, %.critedge._crit_edge, %10
  %.0 = phi i32 [ 2, %10 ], [ %.lcssa, %.critedge._crit_edge ], [ %11, %12 ], [ 0, %16 ]
  tail call void @ba_free(ptr noundef %7) #2
  ret i32 %.0
}

declare ptr @ba_alloc_by_len(i64 noundef) local_unnamed_addr #1

declare i32 @drbg_random(ptr noundef) local_unnamed_addr #1

declare i32 @wa_from_ba(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @ba_free(ptr noundef) 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 = { "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, !10, i64 8}
!6 = !{!"WordArray_st", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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