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

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

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

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

declare ptr @wa_alloc(i64 noundef) #1

declare i64 @int_bit_len(ptr noundef) #1

declare ptr @wa_to_ba(ptr noundef) #1

declare i32 @ba_change_len(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @ec_generate_privkey(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, 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
  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 %3, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %13, label %11

11:                                               ; preds = %8
  store i32 2, ptr %7, align 4, !tbaa !9
  %12 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 1299, i32 noundef %12, ptr noundef null)
  br label %88

13:                                               ; preds = %8
  br label %14

14:                                               ; preds = %13
  br label %15

15:                                               ; preds = %14
  br label %16

16:                                               ; preds = %15
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %21, label %19

19:                                               ; preds = %16
  store i32 2, ptr %7, align 4, !tbaa !9
  %20 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 1300, i32 noundef %20, ptr noundef null)
  br label %88

21:                                               ; preds = %16
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.EcCtx_st, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = getelementptr inbounds %struct.EcParamsCtx_st, ptr %27, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = getelementptr inbounds %struct.WordArray_st, ptr %29, i32 0, i32 1
  %31 = load i64, ptr %30, align 8, !tbaa !17
  %32 = call ptr @wa_alloc(i64 noundef %31)
  store ptr %32, ptr %5, align 8, !tbaa !5
  %33 = icmp eq ptr null, %32
  br i1 %33, label %34, label %36

34:                                               ; preds = %24
  store i32 2, ptr %7, align 4, !tbaa !9
  %35 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 1302, i32 noundef %35)
  br label %88

36:                                               ; preds = %24
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37
  br label %39

39:                                               ; preds = %38
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.EcCtx_st, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  %43 = getelementptr inbounds %struct.EcParamsCtx_st, ptr %42, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !14
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = call i32 @int_rand(ptr noundef %44, ptr noundef %45)
  store i32 %46, ptr %7, align 4, !tbaa !9
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %51

49:                                               ; preds = %39
  %50 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 1304, i32 noundef %50)
  br label %88

51:                                               ; preds = %39
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = call ptr @wa_to_ba(ptr noundef %54)
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %55, ptr %56, align 8, !tbaa !5
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.EcCtx_st, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !11
  %60 = getelementptr inbounds %struct.EcParamsCtx_st, ptr %59, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !14
  %62 = call i64 @int_bit_len(ptr noundef %61)
  %63 = add i64 %62, 7
  %64 = udiv i64 %63, 8
  store i64 %64, ptr %6, align 8, !tbaa !19
  br label %65

65:                                               ; preds = %53
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = load ptr, ptr %66, align 8, !tbaa !5
  %68 = load i64, ptr %6, align 8, !tbaa !19
  %69 = call i32 @ba_change_len(ptr noundef %67, i64 noundef %68)
  store i32 %69, ptr %7, align 4, !tbaa !9
  %70 = load i32, ptr %7, align 4, !tbaa !9
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %74

72:                                               ; preds = %65
  %73 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 1307, i32 noundef %73)
  br label %88

74:                                               ; preds = %65
  br label %75

75:                                               ; preds = %74
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = load ptr, ptr %78, align 8, !tbaa !5
  %80 = call i32 @ba_swap(ptr noundef %79)
  store i32 %80, ptr %7, align 4, !tbaa !9
  %81 = load i32, ptr %7, align 4, !tbaa !9
  %82 = icmp ne i32 %81, 0
  br i1 %82, label %83, label %85

83:                                               ; preds = %77
  %84 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 1308, i32 noundef %84)
  br label %88

85:                                               ; preds = %77
  br label %86

86:                                               ; preds = %85
  br label %87

87:                                               ; preds = %86
  br label %88

88:                                               ; preds = %87, %83, %72, %49, %34, %19, %11
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  call void @wa_free_private(ptr noundef %89)
  %90 = load i32, ptr %7, align 4, !tbaa !9
  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 i32 %90
}

declare i32 @int_rand(ptr noundef, ptr noundef) #1

declare i32 @ba_swap(ptr noundef) #1

declare void @wa_free_private(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = !{!"EcCtx_st", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !13, i64 33}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!15, !6, i64 16}
!15 = !{!"EcParamsCtx_st", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 40, !16, i64 48, !6, i64 56, !6, i64 64, !10, i64 72, !6, i64 80}
!16 = !{!"long", !7, i64 0}
!17 = !{!18, !16, i64 8}
!18 = !{!"WordArray_st", !6, i64 0, !16, i64 8}
!19 = !{!16, !16, i64 0}


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

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

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

declare ptr @wa_alloc(i64 noundef) local_unnamed_addr #0

declare i64 @int_bit_len(ptr noundef) local_unnamed_addr #0

declare ptr @wa_to_ba(ptr noundef) local_unnamed_addr #0

declare i32 @ba_change_len(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @ec_generate_privkey(ptr noundef readonly %0, ptr noundef %1) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %3, label %4

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

4:                                                ; preds = %2
  %.not29 = icmp eq ptr %1, null
  br i1 %.not29, label %5, label %6

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

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

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

15:                                               ; preds = %6
  %16 = load ptr, ptr %0, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = tail call i32 @int_rand(ptr noundef %18, ptr noundef nonnull %12) #2
  %.not30 = icmp eq i32 %19, 0
  br i1 %.not30, label %21, label %20

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

21:                                               ; preds = %15
  %22 = tail call ptr @wa_to_ba(ptr noundef nonnull %12) #2
  store ptr %22, ptr %1, align 8, !tbaa !17
  %23 = load ptr, ptr %0, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = tail call i64 @int_bit_len(ptr noundef %25) #2
  %27 = add i64 %26, 7
  %28 = lshr i64 %27, 3
  %29 = load ptr, ptr %1, align 8, !tbaa !17
  %30 = tail call i32 @ba_change_len(ptr noundef %29, i64 noundef %28) #2
  %.not31 = icmp eq i32 %30, 0
  br i1 %.not31, label %32, label %31

31:                                               ; preds = %21
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 1307, i32 noundef %30) #2
  br label %36

32:                                               ; preds = %21
  %33 = load ptr, ptr %1, align 8, !tbaa !17
  %34 = tail call i32 @ba_swap(ptr noundef %33) #2
  %.not32 = icmp eq i32 %34, 0
  br i1 %.not32, label %36, label %35

35:                                               ; preds = %32
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 1308, i32 noundef %34) #2
  br label %36

36:                                               ; preds = %32, %35, %31, %20, %14, %5, %3
  %.021 = phi ptr [ null, %14 ], [ %12, %20 ], [ %12, %31 ], [ %12, %35 ], [ %12, %32 ], [ null, %5 ], [ null, %3 ]
  %.0 = phi i32 [ 2, %14 ], [ %19, %20 ], [ %30, %31 ], [ %34, %35 ], [ 0, %32 ], [ 2, %5 ], [ 2, %3 ]
  tail call void @wa_free_private(ptr noundef %.021) #2
  ret i32 %.0
}

declare i32 @int_rand(ptr noundef, ptr noundef) local_unnamed_addr #0

declare i32 @ba_swap(ptr noundef) local_unnamed_addr #0

declare void @wa_free_private(ptr noundef) local_unnamed_addr #0

attributes #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 = { 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 = { 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 = !{!"EcCtx_st", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 33}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_Bool", !8, i64 0}
!11 = !{!12, !7, i64 16}
!12 = !{!"EcParamsCtx_st", !13, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !14, i64 48, !7, i64 56, !7, i64 64, !13, i64 72, !7, i64 80}
!13 = !{!"int", !8, i64 0}
!14 = !{!"long", !8, i64 0}
!15 = !{!16, !14, i64 8}
!16 = !{!"WordArray_st", !7, i64 0, !14, i64 8}
!17 = !{!7, !7, i64 0}


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