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

@.str = external hidden unnamed_addr constant [27 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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @int_is_one(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @int_bit_len(ptr noundef) #1

declare ptr @wa_alloc_with_zero(i64 noundef) #2

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

declare ptr @wa_copy_with_alloc(ptr noundef) #2

declare void @wa_change_len(ptr noundef, i64 noundef) #2

declare void @wa_free(ptr noundef) #2

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

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

15:                                               ; preds = %12
  store i32 2, ptr %9, align 4, !tbaa !9
  %16 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 878, i32 noundef %16, ptr noundef null)
  br label %90

17:                                               ; preds = %12
  br label %18

18:                                               ; preds = %17
  br label %19

19:                                               ; preds = %18
  br label %20

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

23:                                               ; preds = %20
  store i32 2, ptr %9, align 4, !tbaa !9
  %24 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 879, i32 noundef %24, ptr noundef null)
  br label %90

25:                                               ; preds = %20
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  br label %28

28:                                               ; preds = %27
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = call ptr @wa_copy_with_alloc(ptr noundef %29)
  store ptr %30, ptr %7, align 8, !tbaa !5
  %31 = icmp eq ptr null, %30
  br i1 %31, label %32, label %34

32:                                               ; preds = %28
  store i32 2, ptr %9, align 4, !tbaa !9
  %33 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 881, i32 noundef %33)
  br label %90

34:                                               ; preds = %28
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = call ptr @gfp_alloc(ptr noundef %38)
  store ptr %39, ptr %8, align 8, !tbaa !5
  %40 = icmp eq ptr null, %39
  br i1 %40, label %41, label %43

41:                                               ; preds = %37
  store i32 2, ptr %9, align 4, !tbaa !9
  %42 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 883, i32 noundef %42)
  br label %90

43:                                               ; preds = %37
  br label %44

44:                                               ; preds = %43
  br label %45

45:                                               ; preds = %44
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.WordArray_st, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  %49 = getelementptr inbounds i64, ptr %48, i64 0
  %50 = load i64, ptr %49, align 8, !tbaa !16
  %51 = add i64 %50, -1
  store i64 %51, ptr %49, align 8, !tbaa !16
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = call i64 @int_bit_len(ptr noundef %52)
  store i64 %53, ptr %10, align 8, !tbaa !16
  br label %54

54:                                               ; preds = %45
  %55 = load i64, ptr %10, align 8, !tbaa !16
  %56 = sub i64 %55, 1
  %57 = call i32 @int_gen_odd(i64 noundef %56, ptr noundef %5)
  store i32 %57, ptr %9, align 4, !tbaa !9
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %62

60:                                               ; preds = %54
  %61 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 888, i32 noundef %61)
  br label %90

62:                                               ; preds = %54
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63
  br label %65

65:                                               ; preds = %64
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.GfpCtx_st, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !17
  %69 = getelementptr inbounds %struct.WordArray_st, ptr %68, i32 0, i32 1
  %70 = load i64, ptr %69, align 8, !tbaa !19
  %71 = call ptr @wa_alloc_with_zero(i64 noundef %70)
  store ptr %71, ptr %6, align 8, !tbaa !5
  %72 = icmp eq ptr null, %71
  br i1 %72, label %73, label %75

73:                                               ; preds = %65
  store i32 2, ptr %9, align 4, !tbaa !9
  %74 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 890, i32 noundef %74)
  br label %90

75:                                               ; preds = %65
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.WordArray_st, ptr %79, i32 0, i32 1
  %81 = load i64, ptr %80, align 8, !tbaa !19
  call void @wa_change_len(ptr noundef %78, i64 noundef %81)
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = load ptr, ptr %7, align 8, !tbaa !5
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  call void @gfp_mod_pow(ptr noundef %82, ptr noundef %83, ptr noundef %84, ptr noundef %85)
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = call zeroext i1 @int_is_one(ptr noundef %86)
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = zext i1 %87 to i8
  store i8 %89, ptr %88, align 1, !tbaa !11
  br label %90

90:                                               ; preds = %77, %73, %60, %41, %32, %23, %15
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  call void @wa_free(ptr noundef %91)
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  call void @gfp_free(ptr noundef %92)
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  call void @wa_free(ptr noundef %93)
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  call void @wa_free(ptr noundef %94)
  %95 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, 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 %95
}

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

declare ptr @gfp_alloc(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @int_gen_odd(i64 noundef, ptr noundef) #1

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

declare void @gfp_free(ptr noundef) #2

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 }

!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, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"WordArray_st", !6, i64 0, !15, i64 8}
!15 = !{!"long", !7, i64 0}
!16 = !{!15, !15, i64 0}
!17 = !{!18, !6, i64 0}
!18 = !{!"GfpCtx_st", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!19 = !{!14, !15, i64 8}


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @int_is_one(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @int_bit_len(ptr noundef) local_unnamed_addr #1

declare ptr @wa_alloc_with_zero(i64 noundef) local_unnamed_addr #2

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

declare ptr @wa_copy_with_alloc(ptr noundef) local_unnamed_addr #2

declare void @wa_change_len(ptr noundef, i64 noundef) local_unnamed_addr #2

declare void @wa_free(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @int_fermat_primary_test(ptr noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #1 {
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  store ptr null, ptr %3, align 8, !tbaa !5
  store i8 0, ptr %1, align 1, !tbaa !9
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %4, label %5

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

5:                                                ; preds = %2
  %6 = tail call ptr @wa_copy_with_alloc(ptr noundef nonnull %0) #3
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %5
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 881, i32 noundef 2) #3
  br label %35

9:                                                ; preds = %5
  %10 = tail call ptr @gfp_alloc(ptr noundef nonnull %6) #3
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

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

13:                                               ; preds = %9
  %14 = load ptr, ptr %6, align 8, !tbaa !11
  %15 = load i64, ptr %14, align 8, !tbaa !14
  %16 = add i64 %15, -1
  store i64 %16, ptr %14, align 8, !tbaa !14
  %17 = tail call i64 @int_bit_len(ptr noundef nonnull %6)
  %18 = add i64 %17, -1
  %19 = call i32 @int_gen_odd(i64 noundef %18, ptr noundef nonnull %3)
  %.not36 = icmp eq i32 %19, 0
  br i1 %.not36, label %21, label %20

20:                                               ; preds = %13
  call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 888, i32 noundef %19) #3
  br label %35

21:                                               ; preds = %13
  %22 = load ptr, ptr %10, align 8, !tbaa !15
  %23 = getelementptr inbounds i8, ptr %22, i64 8
  %24 = load i64, ptr %23, align 8, !tbaa !17
  %25 = call ptr @wa_alloc_with_zero(i64 noundef %24) #3
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %28

27:                                               ; preds = %21
  call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 890, i32 noundef 2) #3
  br label %35

28:                                               ; preds = %21
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %25, i64 8
  %31 = load i64, ptr %30, align 8, !tbaa !17
  call void @wa_change_len(ptr noundef %29, i64 noundef %31) #3
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  call void @gfp_mod_pow(ptr noundef nonnull %10, ptr noundef %32, ptr noundef nonnull %6, ptr noundef nonnull %25) #3
  %33 = call zeroext i1 @int_is_one(ptr noundef nonnull %25)
  %34 = zext i1 %33 to i8
  store i8 %34, ptr %1, align 1, !tbaa !9
  br label %35

35:                                               ; preds = %28, %27, %20, %12, %8, %4
  %.027 = phi ptr [ null, %8 ], [ %6, %12 ], [ %6, %20 ], [ %6, %27 ], [ %6, %28 ], [ null, %4 ]
  %.026 = phi ptr [ null, %8 ], [ null, %12 ], [ %10, %20 ], [ %10, %27 ], [ %10, %28 ], [ null, %4 ]
  %.025 = phi i32 [ 2, %8 ], [ 2, %12 ], [ %19, %20 ], [ 2, %27 ], [ 0, %28 ], [ 2, %4 ]
  %.0 = phi ptr [ null, %8 ], [ null, %12 ], [ null, %20 ], [ null, %27 ], [ %25, %28 ], [ null, %4 ]
  call void @wa_free(ptr noundef %.027) #3
  call void @gfp_free(ptr noundef %.026) #3
  call void @wa_free(ptr noundef %.0) #3
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  call void @wa_free(ptr noundef %36) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret i32 %.025
}

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

declare ptr @gfp_alloc(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @int_gen_odd(i64 noundef, ptr noundef) local_unnamed_addr #1

declare void @gfp_mod_pow(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @gfp_free(ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 }

!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 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"WordArray_st", !6, i64 0, !13, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"GfpCtx_st", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!17 = !{!12, !13, i64 8}


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