; LLVM IR from specinfo-ua/UAPKI :: library/uapkic/src (math-ecp-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.EcGfpCtx_st = type { ptr, ptr, ptr, i8, i64 }

@.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: nounwind uwtable
define dso_local void @ecp_init(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %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 %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, 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 %6, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.WordArray_st, ptr %11, i32 0, i32 1
  %13 = load i64, ptr %12, align 8, !tbaa !11
  store i64 %13, ptr %10, align 8, !tbaa !14
  br label %14

14:                                               ; preds = %4
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = call ptr @gfp_alloc(ptr noundef %15)
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.EcGfpCtx_st, ptr %17, i32 0, i32 0
  store ptr %16, ptr %18, align 8, !tbaa !15
  %19 = icmp eq ptr null, %16
  br i1 %19, label %20, label %22

20:                                               ; preds = %14
  store i32 2, ptr %9, align 4, !tbaa !9
  %21 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 88, i32 noundef %21)
  br label %87

22:                                               ; preds = %14
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  %26 = load i64, ptr %10, align 8, !tbaa !14
  %27 = call ptr @wa_alloc(i64 noundef %26)
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.EcGfpCtx_st, ptr %28, i32 0, i32 1
  store ptr %27, ptr %29, align 8, !tbaa !18
  %30 = icmp eq ptr null, %27
  br i1 %30, label %31, label %33

31:                                               ; preds = %25
  store i32 2, ptr %9, align 4, !tbaa !9
  %32 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 89, i32 noundef %32)
  br label %87

33:                                               ; preds = %25
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  %37 = load i64, ptr %10, align 8, !tbaa !14
  %38 = call ptr @wa_alloc(i64 noundef %37)
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.EcGfpCtx_st, ptr %39, i32 0, i32 2
  store ptr %38, ptr %40, align 8, !tbaa !19
  %41 = icmp eq ptr null, %38
  br i1 %41, label %42, label %44

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

44:                                               ; preds = %36
  br label %45

45:                                               ; preds = %44
  br label %46

46:                                               ; preds = %45
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.EcGfpCtx_st, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !18
  %52 = call i32 @int_sub(ptr noundef %47, ptr noundef %48, ptr noundef %51)
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.EcGfpCtx_st, ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !18
  %56 = call i64 @int_bit_len(ptr noundef %55)
  %57 = icmp eq i64 %56, 2
  br i1 %57, label %58, label %67

58:                                               ; preds = %46
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.EcGfpCtx_st, ptr %59, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !18
  %62 = getelementptr inbounds %struct.WordArray_st, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !20
  %64 = getelementptr inbounds i64, ptr %63, i64 0
  %65 = load i64, ptr %64, align 8, !tbaa !14
  %66 = icmp eq i64 %65, 3
  br label %67

67:                                               ; preds = %58, %46
  %68 = phi i1 [ false, %46 ], [ %66, %58 ]
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.EcGfpCtx_st, ptr %69, i32 0, i32 3
  %71 = zext i1 %68 to i8
  store i8 %71, ptr %70, align 8, !tbaa !21
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.WordArray_st, ptr %72, i32 0, i32 1
  %74 = load i64, ptr %73, align 8, !tbaa !11
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.EcGfpCtx_st, ptr %75, i32 0, i32 4
  store i64 %74, ptr %76, align 8, !tbaa !22
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.EcGfpCtx_st, ptr %78, i32 0, i32 1
  %80 = load ptr, ptr %79, align 8, !tbaa !18
  %81 = call i32 @wa_copy(ptr noundef %77, ptr noundef %80)
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.EcGfpCtx_st, ptr %83, i32 0, i32 2
  %85 = load ptr, ptr %84, align 8, !tbaa !19
  %86 = call i32 @wa_copy(ptr noundef %82, ptr noundef %85)
  br label %87

87:                                               ; preds = %67, %42, %31, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

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

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

declare ptr @gfp_alloc(ptr noundef) #2

declare ptr @wa_alloc(i64 noundef) #2

declare i32 @int_sub(ptr noundef, ptr noundef, ptr noundef) #2

declare i64 @int_bit_len(ptr noundef) #2

declare i32 @wa_copy(ptr noundef, 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, !13, i64 8}
!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 = !{!"EcGfpCtx_st", !6, i64 0, !6, i64 8, !6, i64 16, !17, i64 24, !13, i64 32}
!17 = !{!"_Bool", !7, i64 0}
!18 = !{!16, !6, i64 8}
!19 = !{!16, !6, i64 16}
!20 = !{!12, !6, i64 0}
!21 = !{!16, !17, i64 24}
!22 = !{!16, !13, i64 32}


; 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
define dso_local void @ecp_init(ptr nocapture noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = tail call ptr @gfp_alloc(ptr noundef %1) #2
  store ptr %7, ptr %0, align 8, !tbaa !11
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %4
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 88, i32 noundef 2) #2
  br label %39

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

14:                                               ; preds = %10
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 89, i32 noundef 2) #2
  br label %39

15:                                               ; preds = %10
  %16 = tail call ptr @wa_alloc(i64 noundef %6) #2
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %16, ptr %17, align 8, !tbaa !15
  %18 = icmp eq ptr %16, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %15
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 90, i32 noundef 2) #2
  br label %39

20:                                               ; preds = %15
  %21 = load ptr, ptr %12, align 8, !tbaa !14
  %22 = tail call i32 @int_sub(ptr noundef nonnull %1, ptr noundef %2, ptr noundef %21) #2
  %23 = load ptr, ptr %12, align 8, !tbaa !14
  %24 = tail call i64 @int_bit_len(ptr noundef %23) #2
  %25 = icmp eq i64 %24, 2
  %.pre = load ptr, ptr %12, align 8, !tbaa !14
  br i1 %25, label %26, label %31

26:                                               ; preds = %20
  %27 = load ptr, ptr %.pre, align 8, !tbaa !16
  %28 = load i64, ptr %27, align 8, !tbaa !17
  %29 = icmp eq i64 %28, 3
  %30 = zext i1 %29 to i8
  br label %31

31:                                               ; preds = %26, %20
  %32 = phi i8 [ 0, %20 ], [ %30, %26 ]
  %33 = getelementptr inbounds i8, ptr %0, i64 24
  store i8 %32, ptr %33, align 8, !tbaa !18
  %34 = load i64, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 %34, ptr %35, align 8, !tbaa !19
  %36 = tail call i32 @wa_copy(ptr noundef %2, ptr noundef %.pre) #2
  %37 = load ptr, ptr %17, align 8, !tbaa !15
  %38 = tail call i32 @wa_copy(ptr noundef %3, ptr noundef %37) #2
  br label %39

39:                                               ; preds = %31, %19, %14, %9
  ret void
}

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

declare ptr @gfp_alloc(ptr noundef) local_unnamed_addr #1

declare ptr @wa_alloc(i64 noundef) local_unnamed_addr #1

declare i32 @int_sub(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i64 @int_bit_len(ptr noundef) local_unnamed_addr #1

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


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