; LLVM IR from albertobsd/keyhunt :: secp256k1/IntGroup.ll (ZN8IntGroup6ModInvEv)

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

%class.Int = type { %union.anon }
%union.anon = type { [5 x i64] }
%class.IntGroup = type <{ ptr, ptr, i32, [4 x i8] }>

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8IntGroup6ModInvEv(ptr noundef nonnull align 8 dereferenceable(20) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca %class.Int, align 8
  %4 = alloca %class.Int, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 40, ptr %3) #3
  call void @_ZN3IntC1Ev(ptr noundef nonnull align 8 dereferenceable(40) %3)
  call void @llvm.lifetime.start.p0(i64 40, ptr %4) #3
  call void @_ZN3IntC1Ev(ptr noundef nonnull align 8 dereferenceable(40) %4)
  %8 = getelementptr inbounds %class.IntGroup, ptr %7, i32 0, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds %class.Int, ptr %9, i64 0
  %11 = getelementptr inbounds %class.IntGroup, ptr %7, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !12
  %13 = getelementptr inbounds %class.Int, ptr %12, i64 0
  call void @_ZN3Int3SetEPS_(ptr noundef nonnull align 8 dereferenceable(40) %10, ptr noundef %13)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 1, ptr %5, align 4, !tbaa !13
  br label %14

14:                                               ; preds = %37, %1
  %15 = load i32, ptr %5, align 4, !tbaa !13
  %16 = getelementptr inbounds %class.IntGroup, ptr %7, i32 0, i32 2
  %17 = load i32, ptr %16, align 8, !tbaa !14
  %18 = icmp slt i32 %15, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %40

20:                                               ; preds = %14
  %21 = getelementptr inbounds %class.IntGroup, ptr %7, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = load i32, ptr %5, align 4, !tbaa !13
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds %class.Int, ptr %22, i64 %24
  %26 = getelementptr inbounds %class.IntGroup, ptr %7, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = load i32, ptr %5, align 4, !tbaa !13
  %29 = sub nsw i32 %28, 1
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %class.Int, ptr %27, i64 %30
  %32 = getelementptr inbounds %class.IntGroup, ptr %7, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !12
  %34 = load i32, ptr %5, align 4, !tbaa !13
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds %class.Int, ptr %33, i64 %35
  call void @_ZN3Int8ModMulK1EPS_S0_(ptr noundef nonnull align 8 dereferenceable(40) %25, ptr noundef %31, ptr noundef %36)
  br label %37

37:                                               ; preds = %20
  %38 = load i32, ptr %5, align 4, !tbaa !13
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %5, align 4, !tbaa !13
  br label %14, !llvm.loop !15

40:                                               ; preds = %19
  %41 = getelementptr inbounds %class.IntGroup, ptr %7, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  %43 = getelementptr inbounds %class.IntGroup, ptr %7, i32 0, i32 2
  %44 = load i32, ptr %43, align 8, !tbaa !14
  %45 = sub nsw i32 %44, 1
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds %class.Int, ptr %42, i64 %46
  call void @_ZN3Int3SetEPS_(ptr noundef nonnull align 8 dereferenceable(40) %4, ptr noundef %47)
  call void @_ZN3Int6ModInvEv(ptr noundef nonnull align 8 dereferenceable(40) %4)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %48 = getelementptr inbounds %class.IntGroup, ptr %7, i32 0, i32 2
  %49 = load i32, ptr %48, align 8, !tbaa !14
  %50 = sub nsw i32 %49, 1
  store i32 %50, ptr %6, align 4, !tbaa !13
  br label %51

51:                                               ; preds = %72, %40
  %52 = load i32, ptr %6, align 4, !tbaa !13
  %53 = icmp sgt i32 %52, 0
  br i1 %53, label %55, label %54

54:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %75

55:                                               ; preds = %51
  %56 = getelementptr inbounds %class.IntGroup, ptr %7, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !9
  %58 = load i32, ptr %6, align 4, !tbaa !13
  %59 = sub nsw i32 %58, 1
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds %class.Int, ptr %57, i64 %60
  call void @_ZN3Int8ModMulK1EPS_S0_(ptr noundef nonnull align 8 dereferenceable(40) %3, ptr noundef %61, ptr noundef %4)
  %62 = getelementptr inbounds %class.IntGroup, ptr %7, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !12
  %64 = load i32, ptr %6, align 4, !tbaa !13
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds %class.Int, ptr %63, i64 %65
  call void @_ZN3Int8ModMulK1EPS_(ptr noundef nonnull align 8 dereferenceable(40) %4, ptr noundef %66)
  %67 = getelementptr inbounds %class.IntGroup, ptr %7, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !12
  %69 = load i32, ptr %6, align 4, !tbaa !13
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds %class.Int, ptr %68, i64 %70
  call void @_ZN3Int3SetEPS_(ptr noundef nonnull align 8 dereferenceable(40) %71, ptr noundef %3)
  br label %72

72:                                               ; preds = %55
  %73 = load i32, ptr %6, align 4, !tbaa !13
  %74 = add nsw i32 %73, -1
  store i32 %74, ptr %6, align 4, !tbaa !13
  br label %51, !llvm.loop !17

75:                                               ; preds = %54
  %76 = getelementptr inbounds %class.IntGroup, ptr %7, i32 0, i32 0
  %77 = load ptr, ptr %76, align 8, !tbaa !12
  %78 = getelementptr inbounds %class.Int, ptr %77, i64 0
  call void @_ZN3Int3SetEPS_(ptr noundef nonnull align 8 dereferenceable(40) %78, ptr noundef %4)
  call void @llvm.lifetime.end.p0(i64 40, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 40, ptr %3) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare void @_ZN3IntC1Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #2

declare void @_ZN3Int3SetEPS_(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef) #2

declare void @_ZN3Int8ModMulK1EPS_S0_(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare void @_ZN3Int6ModInvEv(ptr noundef nonnull align 8 dereferenceable(40)) #2

declare void @_ZN3Int8ModMulK1EPS_(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef) #2

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


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

%class.Int = type { %union.anon }
%union.anon = type { [5 x i64] }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8IntGroup6ModInvEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(20) %0) local_unnamed_addr #0 align 2 {
  %2 = alloca %class.Int, align 8
  %3 = alloca %class.Int, align 8
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %2) #3
  call void @_ZN3IntC1Ev(ptr noundef nonnull align 8 dereferenceable(40) %2)
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #3
  call void @_ZN3IntC1Ev(ptr noundef nonnull align 8 dereferenceable(40) %3)
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %0, align 8, !tbaa !11
  call void @_ZN3Int3SetEPS_(ptr noundef nonnull align 8 dereferenceable(40) %5, ptr noundef %6)
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load i32, ptr %7, align 8, !tbaa !12
  %9 = icmp sgt i32 %8, 1
  br i1 %9, label %.lr.ph, label %.._crit_edge_crit_edge

.._crit_edge_crit_edge:                           ; preds = %1
  %.pre = sext i32 %8 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.._crit_edge_crit_edge ], [ %22, %.lr.ph ]
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr %class.Int, ptr %10, i64 %.pre-phi
  %12 = getelementptr i8, ptr %11, i64 -40
  call void @_ZN3Int3SetEPS_(ptr noundef nonnull align 8 dereferenceable(40) %3, ptr noundef %12)
  call void @_ZN3Int6ModInvEv(ptr noundef nonnull align 8 dereferenceable(40) %3)
  %13 = load i32, ptr %7, align 8, !tbaa !12
  %14 = icmp sgt i32 %13, 1
  br i1 %14, label %.lr.ph16.preheader, label %._crit_edge17

.lr.ph16.preheader:                               ; preds = %._crit_edge
  %15 = zext nneg i32 %13 to i64
  br label %.lr.ph16

.lr.ph:                                           ; preds = %1, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %1 ]
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %class.Int, ptr %16, i64 %indvars.iv
  %18 = getelementptr i8, ptr %17, i64 -40
  %19 = load ptr, ptr %0, align 8, !tbaa !11
  %20 = getelementptr inbounds %class.Int, ptr %19, i64 %indvars.iv
  call void @_ZN3Int8ModMulK1EPS_S0_(ptr noundef nonnull align 8 dereferenceable(40) %17, ptr noundef %18, ptr noundef nonnull %20)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = load i32, ptr %7, align 8, !tbaa !12
  %22 = sext i32 %21 to i64
  %23 = icmp slt i64 %indvars.iv.next, %22
  br i1 %23, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge17:                                    ; preds = %.lr.ph16, %._crit_edge
  %24 = load ptr, ptr %0, align 8, !tbaa !11
  call void @_ZN3Int3SetEPS_(ptr noundef nonnull align 8 dereferenceable(40) %24, ptr noundef nonnull %3)
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %2) #3
  ret void

.lr.ph16:                                         ; preds = %.lr.ph16.preheader, %.lr.ph16
  %indvars.iv20 = phi i64 [ %15, %.lr.ph16.preheader ], [ %indvars.iv.next21, %.lr.ph16 ]
  %indvars.iv.next21 = add nsw i64 %indvars.iv20, -1
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr %class.Int, ptr %25, i64 %indvars.iv20
  %27 = getelementptr i8, ptr %26, i64 -80
  call void @_ZN3Int8ModMulK1EPS_S0_(ptr noundef nonnull align 8 dereferenceable(40) %2, ptr noundef %27, ptr noundef nonnull %3)
  %28 = load ptr, ptr %0, align 8, !tbaa !11
  %29 = getelementptr inbounds %class.Int, ptr %28, i64 %indvars.iv.next21
  call void @_ZN3Int8ModMulK1EPS_(ptr noundef nonnull align 8 dereferenceable(40) %3, ptr noundef %29)
  %30 = load ptr, ptr %0, align 8, !tbaa !11
  %31 = getelementptr inbounds %class.Int, ptr %30, i64 %indvars.iv.next21
  call void @_ZN3Int3SetEPS_(ptr noundef nonnull align 8 dereferenceable(40) %31, ptr noundef nonnull %2)
  %32 = icmp ugt i64 %indvars.iv20, 2
  br i1 %32, label %.lr.ph16, label %._crit_edge17, !llvm.loop !15
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare void @_ZN3IntC1Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #2

declare void @_ZN3Int3SetEPS_(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef) local_unnamed_addr #2

declare void @_ZN3Int8ModMulK1EPS_S0_(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare void @_ZN3Int6ModInvEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #2

declare void @_ZN3Int8ModMulK1EPS_(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !7, i64 8}
!6 = !{!"_ZTS8IntGroup", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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