; LLVM IR from specinfo-ua/UAPKI :: library/uapkic/src (ec-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.EcParamsCtx_st = type { i32, ptr, ptr, ptr, ptr, i8, i64, ptr, ptr, i32, ptr }
%struct.EC2m_st = type { ptr, i64, ptr, i64 }
%struct.WordArray_st = type { ptr, i64 }

@.str = external hidden unnamed_addr constant [21 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 @stacktrace_add(ptr noundef, i64 noundef, i32 noundef) #1

declare void @wa_free(ptr noundef) #1

declare ptr @wa_alloc_with_zero(i64 noundef) #1

declare i32 @int_get_bit(ptr noundef, i64 noundef) #1

declare i32 @wa_copy(ptr noundef, ptr noundef) #1

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

22:                                               ; preds = %2
  %23 = load i64, ptr %6, align 8, !tbaa !16
  %24 = call ptr @wa_alloc_with_zero(i64 noundef %23)
  store ptr %24, ptr %5, align 8, !tbaa !5
  %25 = icmp eq ptr null, %24
  br i1 %25, label %26, label %28

26:                                               ; preds = %22
  store i32 2, ptr %11, align 4, !tbaa !18
  %27 = load i32, ptr %11, align 4, !tbaa !18
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 1147, i32 noundef %27)
  br label %89

28:                                               ; preds = %22
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  store i64 0, ptr %8, align 8, !tbaa !16
  br label %31

31:                                               ; preds = %82, %30
  %32 = load i64, ptr %8, align 8, !tbaa !16
  %33 = load i64, ptr %9, align 8, !tbaa !16
  %34 = icmp ult i64 %32, %33
  br i1 %34, label %35, label %85

35:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.EcParamsCtx_st, ptr %36, i32 0, i32 8
  %38 = load ptr, ptr %37, align 8, !tbaa !19
  %39 = load i64, ptr %8, align 8, !tbaa !16
  %40 = getelementptr inbounds ptr, ptr %38, i64 %39
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  store ptr %41, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load i64, ptr %8, align 8, !tbaa !16
  %44 = call i32 @int_get_bit(ptr noundef %42, i64 noundef %43)
  %45 = sext i32 %44 to i64
  store i64 %45, ptr %13, align 8, !tbaa !16
  store i64 0, ptr %7, align 8, !tbaa !16
  %46 = load i64, ptr %9, align 8, !tbaa !16
  %47 = sub i64 %46, 1
  store i64 %47, ptr %10, align 8, !tbaa !16
  br label %48

48:                                               ; preds = %76, %35
  %49 = load i64, ptr %7, align 8, !tbaa !16
  %50 = load i64, ptr %9, align 8, !tbaa !16
  %51 = icmp ult i64 %49, %50
  br i1 %51, label %52, label %81

52:                                               ; preds = %48
  %53 = load i64, ptr %13, align 8, !tbaa !16
  %54 = load ptr, ptr %12, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.WordArray_st, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !20
  %57 = load i64, ptr %10, align 8, !tbaa !16
  %58 = lshr i64 %57, 6
  %59 = getelementptr inbounds i64, ptr %56, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !16
  %61 = load i64, ptr %10, align 8, !tbaa !16
  %62 = and i64 %61, 63
  %63 = lshr i64 %60, %62
  %64 = and i64 %53, %63
  %65 = load i64, ptr %7, align 8, !tbaa !16
  %66 = and i64 %65, 63
  %67 = shl i64 %64, %66
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.WordArray_st, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !20
  %71 = load i64, ptr %7, align 8, !tbaa !16
  %72 = lshr i64 %71, 6
  %73 = getelementptr inbounds i64, ptr %70, i64 %72
  %74 = load i64, ptr %73, align 8, !tbaa !16
  %75 = xor i64 %74, %67
  store i64 %75, ptr %73, align 8, !tbaa !16
  br label %76

76:                                               ; preds = %52
  %77 = load i64, ptr %7, align 8, !tbaa !16
  %78 = add i64 %77, 1
  store i64 %78, ptr %7, align 8, !tbaa !16
  %79 = load i64, ptr %10, align 8, !tbaa !16
  %80 = add i64 %79, -1
  store i64 %80, ptr %10, align 8, !tbaa !16
  br label %48, !llvm.loop !22

81:                                               ; preds = %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %82

82:                                               ; preds = %81
  %83 = load i64, ptr %8, align 8, !tbaa !16
  %84 = add i64 %83, 1
  store i64 %84, ptr %8, align 8, !tbaa !16
  br label %31, !llvm.loop !24

85:                                               ; preds = %31
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = call i32 @wa_copy(ptr noundef %86, ptr noundef %87)
  br label %89

89:                                               ; preds = %85, %26
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  call void @wa_free(ptr noundef %90)
  %91 = load i32, ptr %11, align 4, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  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 %91
}

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 = { 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 #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 32}
!10 = !{!"EcParamsCtx_st", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !12, i64 40, !13, i64 48, !6, i64 56, !6, i64 64, !11, i64 72, !6, i64 80}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !13, i64 24}
!15 = !{!"EC2m_st", !6, i64 0, !13, i64 8, !6, i64 16, !13, i64 24}
!16 = !{!13, !13, i64 0}
!17 = !{!10, !13, i64 48}
!18 = !{!11, !11, i64 0}
!19 = !{!10, !6, i64 64}
!20 = !{!21, !6, i64 0}
!21 = !{!"WordArray_st", !6, i64 0, !13, i64 8}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !23}


; 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 [21 x i8], align 1

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

declare void @wa_free(ptr noundef) local_unnamed_addr #0

declare ptr @wa_alloc_with_zero(i64 noundef) local_unnamed_addr #0

declare i32 @int_get_bit(ptr noundef, i64 noundef) local_unnamed_addr #0

declare i32 @wa_copy(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @pb_to_onb(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 24
  %6 = load i64, ptr %5, align 8, !tbaa !13
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  %8 = load i64, ptr %7, align 8, !tbaa !15
  %9 = tail call ptr @wa_alloc_with_zero(i64 noundef %6) #2
  %10 = icmp eq ptr %9, null
  br i1 %10, label %12, label %.preheader

.preheader:                                       ; preds = %2
  %.not = icmp eq i64 %8, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %11 = getelementptr inbounds i8, ptr %0, i64 64
  br label %13

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

13:                                               ; preds = %.lr.ph, %35
  %.02833 = phi i64 [ 0, %.lr.ph ], [ %36, %35 ]
  %14 = load ptr, ptr %11, align 8, !tbaa !16
  %15 = getelementptr inbounds ptr, ptr %14, i64 %.02833
  %16 = load ptr, ptr %15, align 8, !tbaa !17
  %17 = tail call i32 @int_get_bit(ptr noundef %1, i64 noundef %.02833) #2
  %18 = sext i32 %17 to i64
  %19 = load ptr, ptr %16, align 8, !tbaa !18
  %20 = load ptr, ptr %9, align 8, !tbaa !18
  br label %21

21:                                               ; preds = %13, %21
  %.032 = phi i64 [ 0, %13 ], [ %34, %21 ]
  %.027.in31 = phi i64 [ %8, %13 ], [ %.027, %21 ]
  %.027 = add i64 %.027.in31, -1
  %22 = lshr i64 %.027, 6
  %23 = getelementptr inbounds i64, ptr %19, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !20
  %25 = and i64 %.027, 63
  %26 = lshr i64 %24, %25
  %27 = and i64 %26, %18
  %28 = and i64 %.032, 63
  %29 = shl i64 %27, %28
  %30 = lshr i64 %.032, 6
  %31 = getelementptr inbounds i64, ptr %20, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !20
  %33 = xor i64 %29, %32
  store i64 %33, ptr %31, align 8, !tbaa !20
  %34 = add nuw i64 %.032, 1
  %exitcond.not = icmp eq i64 %34, %8
  br i1 %exitcond.not, label %35, label %21, !llvm.loop !21

35:                                               ; preds = %21
  %36 = add nuw i64 %.02833, 1
  %exitcond34.not = icmp eq i64 %36, %8
  br i1 %exitcond34.not, label %._crit_edge, label %13, !llvm.loop !23

._crit_edge:                                      ; preds = %35, %.preheader
  %37 = tail call i32 @wa_copy(ptr noundef nonnull %9, ptr noundef %1) #2
  br label %38

38:                                               ; preds = %._crit_edge, %12
  %.026 = phi i32 [ 2, %12 ], [ 0, %._crit_edge ]
  tail call void @wa_free(ptr noundef %9) #2
  ret i32 %.026
}

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 = { 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 }

!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 32}
!6 = !{!"EcParamsCtx_st", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !11, i64 40, !12, i64 48, !10, i64 56, !10, i64 64, !7, i64 72, !10, i64 80}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = !{!14, !12, i64 24}
!14 = !{!"EC2m_st", !10, i64 0, !12, i64 8, !10, i64 16, !12, i64 24}
!15 = !{!6, !12, i64 48}
!16 = !{!6, !10, i64 64}
!17 = !{!10, !10, i64 0}
!18 = !{!19, !10, i64 0}
!19 = !{!"WordArray_st", !10, i64 0, !12, i64 8}
!20 = !{!12, !12, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


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