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

@.str = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @gfp_mod_inv_core(ptr noundef, ptr noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local void @gfp_init(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  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
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call ptr @wa_copy_with_alloc(ptr noundef %9)
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.GfpCtx_st, ptr %11, i32 0, i32 0
  store ptr %10, ptr %12, align 8, !tbaa !11
  %13 = icmp eq ptr null, %10
  br i1 %13, label %14, label %16

14:                                               ; preds = %8
  store i32 2, ptr %7, align 4, !tbaa !9
  %15 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 266, i32 noundef %15)
  br label %95

16:                                               ; preds = %8
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  br label %19

19:                                               ; preds = %18
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.WordArray_st, ptr %20, i32 0, i32 1
  %22 = load i64, ptr %21, align 8, !tbaa !13
  %23 = call ptr @wa_alloc_with_one(i64 noundef %22)
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.GfpCtx_st, ptr %24, i32 0, i32 1
  store ptr %23, ptr %25, align 8, !tbaa !16
  %26 = icmp eq ptr null, %23
  br i1 %26, label %27, label %29

27:                                               ; preds = %19
  store i32 2, ptr %7, align 4, !tbaa !9
  %28 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 267, i32 noundef %28)
  br label %95

29:                                               ; preds = %19
  br label %30

30:                                               ; preds = %29
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.WordArray_st, ptr %33, i32 0, i32 1
  %35 = load i64, ptr %34, align 8, !tbaa !13
  %36 = call ptr @wa_alloc_with_zero(i64 noundef %35)
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.GfpCtx_st, ptr %37, i32 0, i32 2
  store ptr %36, ptr %38, align 8, !tbaa !17
  %39 = icmp eq ptr null, %36
  br i1 %39, label %40, label %42

40:                                               ; preds = %32
  store i32 2, ptr %7, align 4, !tbaa !9
  %41 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 268, i32 noundef %41)
  br label %95

42:                                               ; preds = %32
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.GfpCtx_st, ptr %45, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !17
  %48 = getelementptr inbounds %struct.WordArray_st, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !18
  %50 = getelementptr inbounds i64, ptr %49, i64 0
  store i64 2, ptr %50, align 8, !tbaa !19
  br label %51

51:                                               ; preds = %44
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.WordArray_st, ptr %52, i32 0, i32 1
  %54 = load i64, ptr %53, align 8, !tbaa !13
  %55 = mul i64 2, %54
  %56 = call ptr @wa_alloc_with_zero(i64 noundef %55)
  store ptr %56, ptr %5, align 8, !tbaa !5
  %57 = icmp eq ptr null, %56
  br i1 %57, label %58, label %60

58:                                               ; preds = %51
  store i32 2, ptr %7, align 4, !tbaa !9
  %59 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 271, i32 noundef %59)
  br label %95

60:                                               ; preds = %51
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.WordArray_st, ptr %64, i32 0, i32 1
  %66 = load i64, ptr %65, align 8, !tbaa !13
  %67 = call ptr @wa_alloc_with_zero(i64 noundef %66)
  store ptr %67, ptr %6, align 8, !tbaa !5
  %68 = icmp eq ptr null, %67
  br i1 %68, label %69, label %71

69:                                               ; preds = %63
  store i32 2, ptr %7, align 4, !tbaa !9
  %70 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 272, i32 noundef %70)
  br label %95

71:                                               ; preds = %63
  br label %72

72:                                               ; preds = %71
  br label %73

73:                                               ; preds = %72
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.WordArray_st, ptr %74, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !18
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = call i64 @int_word_len(ptr noundef %77)
  %79 = getelementptr inbounds i64, ptr %76, i64 %78
  store i64 1, ptr %79, align 8, !tbaa !19
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  call void @int_div(ptr noundef %80, ptr noundef %81, ptr noundef null, ptr noundef %82)
  br label %83

83:                                               ; preds = %73
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = call ptr @gfp_mod_inv_core(ptr noundef %84, ptr noundef %85)
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.GfpCtx_st, ptr %87, i32 0, i32 3
  store ptr %86, ptr %88, align 8, !tbaa !20
  %89 = icmp eq ptr null, %86
  br i1 %89, label %90, label %92

90:                                               ; preds = %83
  store i32 2, ptr %7, align 4, !tbaa !9
  %91 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 276, i32 noundef %91)
  br label %95

92:                                               ; preds = %83
  br label %93

93:                                               ; preds = %92
  br label %94

94:                                               ; preds = %93
  br label %95

95:                                               ; preds = %94, %90, %69, %58, %40, %27, %14
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  call void @wa_free(ptr noundef %96)
  %97 = load ptr, ptr %6, align 8, !tbaa !5
  call void @wa_free(ptr noundef %97)
  call void @llvm.lifetime.end.p0(i64 4, 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 void
}

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

declare ptr @wa_copy_with_alloc(ptr noundef) #2

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

declare ptr @wa_alloc_with_one(i64 noundef) #2

declare ptr @wa_alloc_with_zero(i64 noundef) #2

declare i64 @int_word_len(ptr noundef) #2

declare void @int_div(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare void @wa_free(ptr noundef) #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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"GfpCtx_st", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!14, !15, i64 8}
!14 = !{!"WordArray_st", !6, i64 0, !15, i64 8}
!15 = !{!"long", !7, i64 0}
!16 = !{!12, !6, i64 8}
!17 = !{!12, !6, i64 16}
!18 = !{!14, !6, i64 0}
!19 = !{!15, !15, i64 0}
!20 = !{!12, !6, i64 24}


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

; Function Attrs: nounwind uwtable
declare dso_local ptr @gfp_mod_inv_core(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @gfp_init(ptr nocapture noundef writeonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call ptr @wa_copy_with_alloc(ptr noundef %1) #2
  store ptr %3, ptr %0, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %.sink.split, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !10
  %8 = tail call ptr @wa_alloc_with_one(i64 noundef %7) #2
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %8, ptr %9, align 8, !tbaa !13
  %10 = icmp eq ptr %8, null
  br i1 %10, label %.sink.split, label %11

11:                                               ; preds = %5
  %12 = load i64, ptr %6, align 8, !tbaa !10
  %13 = tail call ptr @wa_alloc_with_zero(i64 noundef %12) #2
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %13, ptr %14, align 8, !tbaa !14
  %15 = icmp eq ptr %13, null
  br i1 %15, label %.sink.split, label %16

16:                                               ; preds = %11
  %17 = load ptr, ptr %13, align 8, !tbaa !15
  store i64 2, ptr %17, align 8, !tbaa !16
  %18 = load i64, ptr %6, align 8, !tbaa !10
  %19 = shl i64 %18, 1
  %20 = tail call ptr @wa_alloc_with_zero(i64 noundef %19) #2
  %21 = icmp eq ptr %20, null
  br i1 %21, label %.sink.split, label %22

22:                                               ; preds = %16
  %23 = load i64, ptr %6, align 8, !tbaa !10
  %24 = tail call ptr @wa_alloc_with_zero(i64 noundef %23) #2
  %25 = icmp eq ptr %24, null
  br i1 %25, label %.sink.split, label %26

26:                                               ; preds = %22
  %27 = load ptr, ptr %20, align 8, !tbaa !15
  %28 = tail call i64 @int_word_len(ptr noundef nonnull %1) #2
  %29 = getelementptr inbounds i64, ptr %27, i64 %28
  store i64 1, ptr %29, align 8, !tbaa !16
  tail call void @int_div(ptr noundef nonnull %20, ptr noundef nonnull %1, ptr noundef null, ptr noundef nonnull %24) #2
  %30 = tail call ptr @gfp_mod_inv_core(ptr noundef nonnull %24, ptr noundef nonnull %1)
  %31 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %30, ptr %31, align 8, !tbaa !17
  %32 = icmp eq ptr %30, null
  br i1 %32, label %.sink.split, label %33

.sink.split:                                      ; preds = %26, %22, %16, %11, %5, %2
  %.sink = phi i64 [ 266, %2 ], [ 267, %5 ], [ 268, %11 ], [ 271, %16 ], [ 272, %22 ], [ 276, %26 ]
  %.024.ph = phi ptr [ null, %2 ], [ null, %5 ], [ null, %11 ], [ null, %16 ], [ %20, %22 ], [ %20, %26 ]
  %.0.ph = phi ptr [ null, %2 ], [ null, %5 ], [ null, %11 ], [ null, %16 ], [ null, %22 ], [ %24, %26 ]
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef %.sink, i32 noundef 2) #2
  br label %33

33:                                               ; preds = %.sink.split, %26
  %.024 = phi ptr [ %20, %26 ], [ %.024.ph, %.sink.split ]
  %.0 = phi ptr [ %24, %26 ], [ %.0.ph, %.sink.split ]
  tail call void @wa_free(ptr noundef %.024) #2
  tail call void @wa_free(ptr noundef %.0) #2
  ret void
}

declare ptr @wa_copy_with_alloc(ptr noundef) local_unnamed_addr #1

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

declare ptr @wa_alloc_with_one(i64 noundef) local_unnamed_addr #1

declare ptr @wa_alloc_with_zero(i64 noundef) local_unnamed_addr #1

declare i64 @int_word_len(ptr noundef) local_unnamed_addr #1

declare void @int_div(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @wa_free(ptr noundef) 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 = { "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 = !{!"GfpCtx_st", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 8}
!11 = !{!"WordArray_st", !7, i64 0, !12, i64 8}
!12 = !{!"long", !8, i64 0}
!13 = !{!6, !7, i64 8}
!14 = !{!6, !7, i64 16}
!15 = !{!11, !7, i64 0}
!16 = !{!12, !12, i64 0}
!17 = !{!6, !7, i64 24}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass