; LLVM IR from specinfo-ua/UAPKI :: library/uapkic/src (math-ec-precomp-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.EcPrecomp_st = type { i32, %union.anon }
%union.anon = type { ptr }
%struct.EcPrecompComb_st = type { ptr, i32 }
%struct.EcPrecompWin_st = type { ptr, i32, i32 }

; 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
define dso_local void @ec_precomp_free(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = icmp ne ptr %4, null
  br i1 %5, label %6, label %99

6:                                                ; preds = %1
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.EcPrecomp_st, ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = icmp eq i32 %9, 1
  br i1 %10, label %11, label %52

11:                                               ; preds = %6
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.EcPrecomp_st, ptr %12, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = getelementptr inbounds %struct.EcPrecompComb_st, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %48

18:                                               ; preds = %11
  store i32 0, ptr %3, align 4, !tbaa !15
  br label %19

19:                                               ; preds = %39, %18
  %20 = load i32, ptr %3, align 4, !tbaa !15
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.EcPrecomp_st, ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !12
  %24 = getelementptr inbounds %struct.EcPrecompComb_st, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 8, !tbaa !16
  %26 = shl i32 1, %25
  %27 = sub nsw i32 %26, 1
  %28 = icmp slt i32 %20, %27
  br i1 %28, label %29, label %42

29:                                               ; preds = %19
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.EcPrecomp_st, ptr %30, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !12
  %33 = getelementptr inbounds %struct.EcPrecompComb_st, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !13
  %35 = load i32, ptr %3, align 4, !tbaa !15
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds ptr, ptr %34, i64 %36
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  call void @ec_point_free(ptr noundef %38)
  br label %39

39:                                               ; preds = %29
  %40 = load i32, ptr %3, align 4, !tbaa !15
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %3, align 4, !tbaa !15
  br label %19, !llvm.loop !17

42:                                               ; preds = %19
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.EcPrecomp_st, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !12
  %46 = getelementptr inbounds %struct.EcPrecompComb_st, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !13
  call void @free(ptr noundef %47) #4
  br label %48

48:                                               ; preds = %42, %11
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.EcPrecomp_st, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !12
  call void @free(ptr noundef %51) #4
  br label %97

52:                                               ; preds = %6
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.EcPrecomp_st, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !9
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %96

57:                                               ; preds = %52
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.EcPrecomp_st, ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %59, align 8, !tbaa !12
  %61 = getelementptr inbounds %struct.EcPrecompWin_st, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !19
  %63 = icmp ne ptr %62, null
  br i1 %63, label %64, label %92

64:                                               ; preds = %57
  store i32 0, ptr %3, align 4, !tbaa !15
  br label %65

65:                                               ; preds = %83, %64
  %66 = load i32, ptr %3, align 4, !tbaa !15
  %67 = load ptr, ptr %2, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.EcPrecomp_st, ptr %67, i32 0, i32 1
  %69 = load ptr, ptr %68, align 8, !tbaa !12
  %70 = getelementptr inbounds %struct.EcPrecompWin_st, ptr %69, i32 0, i32 1
  %71 = load i32, ptr %70, align 8, !tbaa !21
  %72 = icmp slt i32 %66, %71
  br i1 %72, label %73, label %86

73:                                               ; preds = %65
  %74 = load ptr, ptr %2, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.EcPrecomp_st, ptr %74, i32 0, i32 1
  %76 = load ptr, ptr %75, align 8, !tbaa !12
  %77 = getelementptr inbounds %struct.EcPrecompWin_st, ptr %76, i32 0, i32 0
  %78 = load ptr, ptr %77, align 8, !tbaa !19
  %79 = load i32, ptr %3, align 4, !tbaa !15
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds ptr, ptr %78, i64 %80
  %82 = load ptr, ptr %81, align 8, !tbaa !5
  call void @ec_point_free(ptr noundef %82)
  br label %83

83:                                               ; preds = %73
  %84 = load i32, ptr %3, align 4, !tbaa !15
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %3, align 4, !tbaa !15
  br label %65, !llvm.loop !22

86:                                               ; preds = %65
  %87 = load ptr, ptr %2, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.EcPrecomp_st, ptr %87, i32 0, i32 1
  %89 = load ptr, ptr %88, align 8, !tbaa !12
  %90 = getelementptr inbounds %struct.EcPrecompWin_st, ptr %89, i32 0, i32 0
  %91 = load ptr, ptr %90, align 8, !tbaa !19
  call void @free(ptr noundef %91) #4
  br label %92

92:                                               ; preds = %86, %57
  %93 = load ptr, ptr %2, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.EcPrecomp_st, ptr %93, i32 0, i32 1
  %95 = load ptr, ptr %94, align 8, !tbaa !12
  call void @free(ptr noundef %95) #4
  br label %96

96:                                               ; preds = %92, %52
  br label %97

97:                                               ; preds = %96, %48
  %98 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %98) #4
  br label %99

99:                                               ; preds = %97, %1
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret void
}

declare void @ec_point_free(ptr noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

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 "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 #4 = { 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, !11, i64 0}
!10 = !{!"EcPrecomp_st", !11, i64 0, !7, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"EcPrecompComb_st", !6, i64 0, !11, i64 8}
!15 = !{!11, !11, i64 0}
!16 = !{!14, !11, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !6, i64 0}
!20 = !{!"EcPrecompWin_st", !6, i64 0, !11, i64 8, !11, i64 12}
!21 = !{!20, !11, i64 8}
!22 = distinct !{!22, !18}


; 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
define dso_local void @ec_precomp_free(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %37, label %2

2:                                                ; preds = %1
  %3 = load i32, ptr %0, align 8, !tbaa !5
  switch i32 %3, label %36 [
    i32 1, label %4
    i32 0, label %20
  ]

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !10
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %.not22 = icmp eq ptr %7, null
  br i1 %.not22, label %.sink.split, label %.preheader

.preheader:                                       ; preds = %4
  %8 = getelementptr inbounds i8, ptr %6, i64 8
  %9 = load i32, ptr %8, align 8, !tbaa !14
  %.not31 = icmp eq i32 %9, 0
  br i1 %.not31, label %.sink.split.sink.split, label %.lr.ph28

.lr.ph28:                                         ; preds = %.preheader, %.lr.ph28
  %indvars.iv35 = phi i64 [ %indvars.iv.next36, %.lr.ph28 ], [ 0, %.preheader ]
  %10 = phi ptr [ %14, %.lr.ph28 ], [ %6, %.preheader ]
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = getelementptr inbounds ptr, ptr %11, i64 %indvars.iv35
  %13 = load ptr, ptr %12, align 8, !tbaa !15
  tail call void @ec_point_free(ptr noundef %13) #3
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %14 = load ptr, ptr %5, align 8, !tbaa !10
  %15 = getelementptr inbounds i8, ptr %14, i64 8
  %16 = load i32, ptr %15, align 8, !tbaa !14
  %notmask = shl nsw i32 -1, %16
  %17 = xor i32 %notmask, -1
  %18 = zext nneg i32 %17 to i64
  %19 = icmp ult i64 %indvars.iv.next36, %18
  br i1 %19, label %.lr.ph28, label %.sink.split.sink.split.sink.split, !llvm.loop !16

20:                                               ; preds = %2
  %21 = getelementptr inbounds i8, ptr %0, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !10
  %23 = load ptr, ptr %22, align 8, !tbaa !18
  %.not21 = icmp eq ptr %23, null
  br i1 %.not21, label %.sink.split, label %.preheader23

.preheader23:                                     ; preds = %20
  %24 = getelementptr inbounds i8, ptr %22, i64 8
  %25 = load i32, ptr %24, align 8, !tbaa !20
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %.lr.ph, label %.sink.split.sink.split

.lr.ph:                                           ; preds = %.preheader23, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader23 ]
  %27 = phi ptr [ %31, %.lr.ph ], [ %22, %.preheader23 ]
  %28 = load ptr, ptr %27, align 8, !tbaa !18
  %29 = getelementptr inbounds ptr, ptr %28, i64 %indvars.iv
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  tail call void @ec_point_free(ptr noundef %30) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %31 = load ptr, ptr %21, align 8, !tbaa !10
  %32 = getelementptr inbounds i8, ptr %31, i64 8
  %33 = load i32, ptr %32, align 8, !tbaa !20
  %34 = sext i32 %33 to i64
  %35 = icmp slt i64 %indvars.iv.next, %34
  br i1 %35, label %.lr.ph, label %.sink.split.sink.split.sink.split, !llvm.loop !21

.sink.split.sink.split.sink.split:                ; preds = %.lr.ph, %.lr.ph28
  %.lcssa41.sink = phi ptr [ %14, %.lr.ph28 ], [ %31, %.lr.ph ]
  %.sink42.ph = phi ptr [ %5, %.lr.ph28 ], [ %21, %.lr.ph ]
  %.pre = load ptr, ptr %.lcssa41.sink, align 8, !tbaa !15
  br label %.sink.split.sink.split

.sink.split.sink.split:                           ; preds = %.sink.split.sink.split.sink.split, %.preheader23, %.preheader
  %.sink43 = phi ptr [ %7, %.preheader ], [ %23, %.preheader23 ], [ %.pre, %.sink.split.sink.split.sink.split ]
  %.sink42 = phi ptr [ %5, %.preheader ], [ %21, %.preheader23 ], [ %.sink42.ph, %.sink.split.sink.split.sink.split ]
  tail call void @free(ptr noundef %.sink43) #3
  %.pre38 = load ptr, ptr %.sink42, align 8, !tbaa !10
  br label %.sink.split

.sink.split:                                      ; preds = %.sink.split.sink.split, %20, %4
  %.sink = phi ptr [ %6, %4 ], [ %22, %20 ], [ %.pre38, %.sink.split.sink.split ]
  tail call void @free(ptr noundef %.sink) #3
  br label %36

36:                                               ; preds = %.sink.split, %2
  tail call void @free(ptr noundef nonnull %0) #3
  br label %37

37:                                               ; preds = %36, %1
  ret void
}

declare void @ec_point_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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, !7, i64 0}
!6 = !{!"EcPrecomp_st", !7, i64 0, !8, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"EcPrecompComb_st", !13, i64 0, !7, i64 8}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!12, !7, i64 8}
!15 = !{!13, !13, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !13, i64 0}
!19 = !{!"EcPrecompWin_st", !13, i64 0, !7, i64 8, !7, i64 12}
!20 = !{!19, !7, i64 8}
!21 = distinct !{!21, !17}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass