; 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_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) #1

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

declare void @wa_free(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @onb_to_pb(ptr noundef %0, ptr noundef %1) #2 {
  %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
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  br label %13

13:                                               ; preds = %2
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %18, label %16

16:                                               ; preds = %13
  store i32 2, ptr %6, align 4, !tbaa !9
  %17 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 1108, i32 noundef %17, ptr noundef null)
  br label %104

18:                                               ; preds = %13
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %26, label %24

24:                                               ; preds = %21
  store i32 2, ptr %6, align 4, !tbaa !9
  %25 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 1109, i32 noundef %25, ptr noundef null)
  br label %104

26:                                               ; preds = %21
  br label %27

27:                                               ; preds = %26
  br label %28

28:                                               ; preds = %27
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.EcParamsCtx_st, ptr %29, i32 0, i32 4
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  %32 = getelementptr inbounds %struct.EC2m_st, ptr %31, i32 0, i32 3
  %33 = load i64, ptr %32, align 8, !tbaa !15
  store i64 %33, ptr %10, align 8, !tbaa !17
  br label %34

34:                                               ; preds = %28
  %35 = load i64, ptr %10, align 8, !tbaa !17
  %36 = call ptr @wa_alloc_with_zero(i64 noundef %35)
  store ptr %36, ptr %5, align 8, !tbaa !5
  %37 = icmp eq ptr null, %36
  br i1 %37, label %38, label %40

38:                                               ; preds = %34
  store i32 2, ptr %6, align 4, !tbaa !9
  %39 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 1112, i32 noundef %39)
  br label %104

40:                                               ; preds = %34
  br label %41

41:                                               ; preds = %40
  br label %42

42:                                               ; preds = %41
  store i64 0, ptr %8, align 8, !tbaa !17
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.EcParamsCtx_st, ptr %43, i32 0, i32 6
  %45 = load i64, ptr %44, align 8, !tbaa !18
  %46 = sub i64 %45, 1
  store i64 %46, ptr %9, align 8, !tbaa !17
  br label %47

47:                                               ; preds = %95, %42
  %48 = load i64, ptr %8, align 8, !tbaa !17
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.EcParamsCtx_st, ptr %49, i32 0, i32 6
  %51 = load i64, ptr %50, align 8, !tbaa !18
  %52 = icmp ult i64 %48, %51
  br i1 %52, label %53, label %100

53:                                               ; preds = %47
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.EcParamsCtx_st, ptr %54, i32 0, i32 7
  %56 = load ptr, ptr %55, align 8, !tbaa !19
  %57 = load i64, ptr %8, align 8, !tbaa !17
  %58 = getelementptr inbounds ptr, ptr %56, i64 %57
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  store ptr %59, ptr %11, align 8, !tbaa !5
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load i64, ptr %9, align 8, !tbaa !17
  %62 = call i32 @int_get_bit(ptr noundef %60, i64 noundef %61)
  %63 = sext i32 %62 to i64
  store i64 %63, ptr %12, align 8, !tbaa !17
  store i64 0, ptr %7, align 8, !tbaa !17
  br label %64

64:                                               ; preds = %91, %53
  %65 = load i64, ptr %7, align 8, !tbaa !17
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.EcParamsCtx_st, ptr %66, i32 0, i32 6
  %68 = load i64, ptr %67, align 8, !tbaa !18
  %69 = icmp ult i64 %65, %68
  br i1 %69, label %70, label %94

70:                                               ; preds = %64
  %71 = load i64, ptr %12, align 8, !tbaa !17
  %72 = load i64, ptr %7, align 8, !tbaa !17
  %73 = and i64 %72, 63
  %74 = shl i64 %71, %73
  %75 = load ptr, ptr %11, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.WordArray_st, ptr %75, i32 0, i32 0
  %77 = load ptr, ptr %76, align 8, !tbaa !20
  %78 = load i64, ptr %7, align 8, !tbaa !17
  %79 = lshr i64 %78, 6
  %80 = getelementptr inbounds i64, ptr %77, i64 %79
  %81 = load i64, ptr %80, align 8, !tbaa !17
  %82 = and i64 %74, %81
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.WordArray_st, ptr %83, i32 0, i32 0
  %85 = load ptr, ptr %84, align 8, !tbaa !20
  %86 = load i64, ptr %7, align 8, !tbaa !17
  %87 = lshr i64 %86, 6
  %88 = getelementptr inbounds i64, ptr %85, i64 %87
  %89 = load i64, ptr %88, align 8, !tbaa !17
  %90 = xor i64 %89, %82
  store i64 %90, ptr %88, align 8, !tbaa !17
  br label %91

91:                                               ; preds = %70
  %92 = load i64, ptr %7, align 8, !tbaa !17
  %93 = add i64 %92, 1
  store i64 %93, ptr %7, align 8, !tbaa !17
  br label %64, !llvm.loop !22

94:                                               ; preds = %64
  br label %95

95:                                               ; preds = %94
  %96 = load i64, ptr %8, align 8, !tbaa !17
  %97 = add i64 %96, 1
  store i64 %97, ptr %8, align 8, !tbaa !17
  %98 = load i64, ptr %9, align 8, !tbaa !17
  %99 = add i64 %98, -1
  store i64 %99, ptr %9, align 8, !tbaa !17
  br label %47, !llvm.loop !24

100:                                              ; preds = %47
  %101 = load ptr, ptr %5, align 8, !tbaa !5
  %102 = load ptr, ptr %4, align 8, !tbaa !5
  %103 = call i32 @wa_copy(ptr noundef %101, ptr noundef %102)
  br label %104

104:                                              ; preds = %100, %38, %24, %16
  %105 = load ptr, ptr %5, align 8, !tbaa !5
  call void @wa_free(ptr noundef %105)
  %106 = load i32, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, 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 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i32 %106
}

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

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 32}
!12 = !{!"EcParamsCtx_st", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 40, !14, i64 48, !6, i64 56, !6, i64 64, !10, i64 72, !6, i64 80}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !14, i64 24}
!16 = !{!"EC2m_st", !6, i64 0, !14, i64 8, !6, i64 16, !14, i64 24}
!17 = !{!14, !14, i64 0}
!18 = !{!12, !14, i64 48}
!19 = !{!12, !6, i64 56}
!20 = !{!21, !6, i64 0}
!21 = !{!"WordArray_st", !6, i64 0, !14, 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_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

declare void @wa_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @onb_to_pb(ptr noundef readonly %0, ptr noundef %1) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %3, label %4

3:                                                ; preds = %2
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 1108, i32 noundef 2, ptr noundef null) #2
  br label %43

4:                                                ; preds = %2
  %.not35 = icmp eq ptr %1, null
  br i1 %.not35, label %5, label %6

5:                                                ; preds = %4
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 1109, i32 noundef 2, ptr noundef null) #2
  br label %43

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 24
  %10 = load i64, ptr %9, align 8, !tbaa !13
  %11 = tail call ptr @wa_alloc_with_zero(i64 noundef %10) #2
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %6
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 1112, i32 noundef 2) #2
  br label %43

14:                                               ; preds = %6
  %15 = getelementptr inbounds i8, ptr %0, i64 48
  %16 = load i64, ptr %15, align 8, !tbaa !15
  %.not43 = icmp eq i64 %16, 0
  br i1 %.not43, label %._crit_edge42, label %.lr.ph41

.lr.ph41:                                         ; preds = %14
  %17 = getelementptr inbounds i8, ptr %0, i64 56
  br label %18

18:                                               ; preds = %.lr.ph41, %._crit_edge
  %.03039.in = phi i64 [ %16, %.lr.ph41 ], [ %.03039, %._crit_edge ]
  %.03138 = phi i64 [ 0, %.lr.ph41 ], [ %40, %._crit_edge ]
  %.03039 = add i64 %.03039.in, -1
  %19 = load ptr, ptr %17, align 8, !tbaa !16
  %20 = getelementptr inbounds ptr, ptr %19, i64 %.03138
  %21 = load ptr, ptr %20, align 8, !tbaa !17
  %22 = tail call i32 @int_get_bit(ptr noundef nonnull %1, i64 noundef %.03039) #2
  %23 = sext i32 %22 to i64
  %24 = load i64, ptr %15, align 8, !tbaa !15
  %.not44 = icmp eq i64 %24, 0
  br i1 %.not44, label %._crit_edge42, label %.lr.ph

.lr.ph:                                           ; preds = %18
  %25 = load ptr, ptr %21, align 8, !tbaa !18
  %26 = load ptr, ptr %11, align 8, !tbaa !18
  br label %27

27:                                               ; preds = %.lr.ph, %27
  %.02936 = phi i64 [ 0, %.lr.ph ], [ %37, %27 ]
  %28 = and i64 %.02936, 63
  %29 = shl i64 %23, %28
  %30 = lshr i64 %.02936, 6
  %31 = getelementptr inbounds i64, ptr %25, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !20
  %33 = and i64 %32, %29
  %34 = getelementptr inbounds i64, ptr %26, i64 %30
  %35 = load i64, ptr %34, align 8, !tbaa !20
  %36 = xor i64 %35, %33
  store i64 %36, ptr %34, align 8, !tbaa !20
  %37 = add nuw i64 %.02936, 1
  %38 = load i64, ptr %15, align 8, !tbaa !15
  %39 = icmp ult i64 %37, %38
  br i1 %39, label %27, label %._crit_edge, !llvm.loop !21

._crit_edge:                                      ; preds = %27
  %40 = add nuw i64 %.03138, 1
  %41 = icmp ult i64 %40, %38
  br i1 %41, label %18, label %._crit_edge42, !llvm.loop !23

._crit_edge42:                                    ; preds = %18, %._crit_edge, %14
  %42 = tail call i32 @wa_copy(ptr noundef nonnull %11, ptr noundef nonnull %1) #2
  br label %43

43:                                               ; preds = %._crit_edge42, %13, %5, %3
  %.028 = phi i32 [ 2, %13 ], [ 0, %._crit_edge42 ], [ 2, %5 ], [ 2, %3 ]
  %.0 = phi ptr [ null, %13 ], [ %11, %._crit_edge42 ], [ null, %5 ], [ null, %3 ]
  tail call void @wa_free(ptr noundef %.0) #2
  ret i32 %.028
}

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

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 56}
!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,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass