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

; 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

; Function Attrs: nounwind uwtable
define dso_local i32 @int_prand(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.WordArray_st, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %11, ptr %7, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.WordArray_st, ptr %12, i32 0, i32 1
  %14 = load i64, ptr %13, align 8, !tbaa !12
  %15 = mul i64 %14, 8
  %16 = udiv i64 %15, 2
  store i64 %16, ptr %8, align 8, !tbaa !13
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = call i64 @int_bit_len(ptr noundef %17)
  store i64 %18, ptr %6, align 8, !tbaa !13
  br label %19

19:                                               ; preds = %44, %2
  store i64 0, ptr %5, align 8, !tbaa !13
  br label %20

20:                                               ; preds = %30, %19
  %21 = load i64, ptr %5, align 8, !tbaa !13
  %22 = load i64, ptr %8, align 8, !tbaa !13
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %24, label %33

24:                                               ; preds = %20
  %25 = call i32 @rand() #3
  %26 = trunc i32 %25 to i16
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load i64, ptr %5, align 8, !tbaa !13
  %29 = getelementptr inbounds i16, ptr %27, i64 %28
  store i16 %26, ptr %29, align 2, !tbaa !14
  br label %30

30:                                               ; preds = %24
  %31 = load i64, ptr %5, align 8, !tbaa !13
  %32 = add i64 %31, 1
  store i64 %32, ptr %5, align 8, !tbaa !13
  br label %20, !llvm.loop !16

33:                                               ; preds = %20
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load i64, ptr %6, align 8, !tbaa !13
  call void @int_truncate(ptr noundef %34, i64 noundef %35)
  br label %36

36:                                               ; preds = %33
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = call i32 @int_cmp(ptr noundef %37, ptr noundef %38)
  %40 = icmp sge i32 %39, 0
  br i1 %40, label %44, label %41

41:                                               ; preds = %36
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = call zeroext i1 @int_is_zero(ptr noundef %42)
  br label %44

44:                                               ; preds = %41, %36
  %45 = phi i1 [ true, %36 ], [ %43, %41 ]
  br i1 %45, label %19, label %46, !llvm.loop !18

46:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i32 0
}

; Function Attrs: nounwind
declare i32 @rand() #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 = { 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 = { 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, !6, i64 0}
!10 = !{!"WordArray_st", !6, i64 0, !11, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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

; 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

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

9:                                                ; preds = %._crit_edge.us
  %10 = tail call zeroext i1 @int_is_zero(ptr noundef nonnull %1)
  br i1 %10, label %.critedge.us.backedge, label %.split14.us

.critedge.us:                                     ; preds = %2, %.critedge.us.backedge
  %.012.us = phi i64 [ %.012.us.be, %.critedge.us.backedge ], [ 0, %2 ]
  %11 = tail call i32 @rand() #2
  %12 = trunc i32 %11 to i16
  %13 = getelementptr inbounds i16, ptr %3, i64 %.012.us
  store i16 %12, ptr %13, align 2, !tbaa !12
  %14 = add nuw nsw i64 %.012.us, 1
  %exitcond.not = icmp eq i64 %14, %7
  br i1 %exitcond.not, label %._crit_edge.us, label %.critedge.us.backedge

.critedge.us.backedge:                            ; preds = %.critedge.us, %9, %._crit_edge.us
  %.012.us.be = phi i64 [ %14, %.critedge.us ], [ 0, %9 ], [ 0, %._crit_edge.us ]
  br label %.critedge.us, !llvm.loop !14

._crit_edge.us:                                   ; preds = %.critedge.us
  tail call void @int_truncate(ptr noundef nonnull %1, i64 noundef %8)
  %15 = tail call i32 @int_cmp(ptr noundef nonnull %1, ptr noundef %0)
  %16 = icmp sgt i32 %15, -1
  br i1 %16, label %.critedge.us.backedge, label %9

.critedge:                                        ; preds = %2, %.critedge.backedge
  tail call void @int_truncate(ptr noundef nonnull %1, i64 noundef %8)
  %17 = tail call i32 @int_cmp(ptr noundef nonnull %1, ptr noundef %0)
  %18 = icmp sgt i32 %17, -1
  br i1 %18, label %.critedge.backedge, label %19

19:                                               ; preds = %.critedge
  %20 = tail call zeroext i1 @int_is_zero(ptr noundef nonnull %1)
  br i1 %20, label %.critedge.backedge, label %.split14.us

.critedge.backedge:                               ; preds = %19, %.critedge
  br label %.critedge, !llvm.loop !14

.split14.us:                                      ; preds = %9, %19
  ret i32 0
}

; Function Attrs: nounwind
declare i32 @rand() 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 = { 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 #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, !7, i64 0}
!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 = !{!6, !10, i64 8}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass