; LLVM IR from specinfo-ua/UAPKI :: library/uapkic/src (eckcdsa)

; 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.ByteArray_st = type { ptr, i64 }
%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 [17 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

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

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

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

declare void @wa_free_private(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @eckcdsa_sign(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store ptr null, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %14

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

17:                                               ; preds = %14
  store i32 2, ptr %13, align 4, !tbaa !9
  %18 = load i32, ptr %13, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 219, i32 noundef %18, ptr noundef null)
  br label %107

19:                                               ; preds = %14
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %27, label %25

25:                                               ; preds = %22
  store i32 2, ptr %13, align 4, !tbaa !9
  %26 = load i32, ptr %13, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 220, i32 noundef %26, ptr noundef null)
  br label %107

27:                                               ; preds = %22
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %35, label %33

33:                                               ; preds = %30
  store i32 2, ptr %13, align 4, !tbaa !9
  %34 = load i32, ptr %13, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 221, i32 noundef %34, ptr noundef null)
  br label %107

35:                                               ; preds = %30
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %43, label %41

41:                                               ; preds = %38
  store i32 2, ptr %13, align 4, !tbaa !9
  %42 = load i32, ptr %13, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 222, i32 noundef %42, ptr noundef null)
  br label %107

43:                                               ; preds = %38
  br label %44

44:                                               ; preds = %43
  br label %45

45:                                               ; preds = %44
  br label %46

46:                                               ; preds = %45
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ByteArray_st, ptr %47, i32 0, i32 1
  %49 = load i64, ptr %48, align 8, !tbaa !11
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = call i64 @hash_get_size(i32 noundef %50)
  %52 = icmp eq i64 %49, %51
  br i1 %52, label %55, label %53

53:                                               ; preds = %46
  store i32 2, ptr %13, align 4, !tbaa !9
  %54 = load i32, ptr %13, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 223, i32 noundef %54, ptr noundef null)
  br label %107

55:                                               ; preds = %46
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.EcCtx_st, ptr %58, i32 0, i32 4
  %60 = load i8, ptr %59, align 8, !tbaa !14, !range !17, !noundef !18
  %61 = trunc i8 %60 to i1
  br i1 %61, label %67, label %62

62:                                               ; preds = %57
  br label %63

63:                                               ; preds = %62
  store i32 14, ptr %13, align 4, !tbaa !9
  %64 = load i32, ptr %13, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 226, i32 noundef %64, ptr noundef null)
  br label %107

65:                                               ; No predecessors!
  br label %66

66:                                               ; preds = %65
  br label %67

67:                                               ; preds = %66, %57
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.EcCtx_st, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !19
  %71 = getelementptr inbounds %struct.EcParamsCtx_st, ptr %70, i32 0, i32 2
  %72 = load ptr, ptr %71, align 8, !tbaa !20
  store ptr %72, ptr %12, align 8, !tbaa !5
  br label %73

73:                                               ; preds = %67
  %74 = load ptr, ptr %12, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.WordArray_st, ptr %74, i32 0, i32 1
  %76 = load i64, ptr %75, align 8, !tbaa !22
  %77 = call ptr @wa_alloc(i64 noundef %76)
  store ptr %77, ptr %11, align 8, !tbaa !5
  %78 = icmp eq ptr null, %77
  br i1 %78, label %79, label %81

79:                                               ; preds = %73
  store i32 2, ptr %13, align 4, !tbaa !9
  %80 = load i32, ptr %13, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 231, i32 noundef %80)
  br label %107

81:                                               ; preds = %73
  br label %82

82:                                               ; preds = %81
  br label %83

83:                                               ; preds = %82
  br label %84

84:                                               ; preds = %103, %83
  br label %85

85:                                               ; preds = %84
  %86 = load ptr, ptr %12, align 8, !tbaa !5
  %87 = load ptr, ptr %11, align 8, !tbaa !5
  %88 = call i32 @int_rand(ptr noundef %86, ptr noundef %87)
  store i32 %88, ptr %13, align 4, !tbaa !9
  %89 = load i32, ptr %13, align 4, !tbaa !9
  %90 = icmp ne i32 %89, 0
  br i1 %90, label %91, label %93

91:                                               ; preds = %85
  %92 = load i32, ptr %13, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 235, i32 noundef %92)
  br label %107

93:                                               ; preds = %85
  br label %94

94:                                               ; preds = %93
  br label %95

95:                                               ; preds = %94
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  %98 = load i32, ptr %8, align 4, !tbaa !9
  %99 = load ptr, ptr %11, align 8, !tbaa !5
  %100 = load ptr, ptr %9, align 8, !tbaa !5
  %101 = load ptr, ptr %10, align 8, !tbaa !5
  %102 = call i32 @eckcdsa_sign_internal(ptr noundef %96, ptr noundef %97, i32 noundef %98, ptr noundef %99, ptr noundef %100, ptr noundef %101)
  store i32 %102, ptr %13, align 4, !tbaa !9
  br label %103

103:                                              ; preds = %95
  %104 = load i32, ptr %13, align 4, !tbaa !9
  %105 = icmp eq i32 %104, -1
  br i1 %105, label %84, label %106, !llvm.loop !24

106:                                              ; preds = %103
  br label %107

107:                                              ; preds = %106, %91, %79, %63, %53, %41, %33, %25, %17
  %108 = load ptr, ptr %11, align 8, !tbaa !5
  call void @wa_free_private(ptr noundef %108)
  %109 = load i32, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret i32 %109
}

declare i64 @hash_get_size(i32 noundef) #1

declare ptr @wa_alloc(i64 noundef) #1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @eckcdsa_sign_internal(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) #2

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, !13, i64 8}
!12 = !{!"ByteArray_st", !6, i64 0, !13, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !16, i64 32}
!15 = !{!"EcCtx_st", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !16, i64 32, !16, i64 33}
!16 = !{!"_Bool", !7, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!15, !6, i64 0}
!20 = !{!21, !6, i64 16}
!21 = !{!"EcParamsCtx_st", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !16, i64 40, !13, i64 48, !6, i64 56, !6, i64 64, !10, i64 72, !6, i64 80}
!22 = !{!23, !13, i64 8}
!23 = !{!"WordArray_st", !6, i64 0, !13, i64 8}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


; 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 [17 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 void @wa_free_private(ptr noundef) local_unnamed_addr #0

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

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

7:                                                ; preds = %5
  %.not36 = icmp eq ptr %1, null
  br i1 %.not36, label %8, label %9

8:                                                ; preds = %7
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 220, i32 noundef 2, ptr noundef null) #2
  br label %.loopexit

9:                                                ; preds = %7
  %.not37 = icmp eq ptr %3, null
  br i1 %.not37, label %10, label %11

10:                                               ; preds = %9
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 221, i32 noundef 2, ptr noundef null) #2
  br label %.loopexit

11:                                               ; preds = %9
  %.not38 = icmp eq ptr %4, null
  br i1 %.not38, label %12, label %13

12:                                               ; preds = %11
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 222, i32 noundef 2, ptr noundef null) #2
  br label %.loopexit

13:                                               ; preds = %11
  %14 = getelementptr inbounds i8, ptr %1, i64 8
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = tail call i64 @hash_get_size(i32 noundef %2) #2
  %17 = icmp eq i64 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %13
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 223, i32 noundef 2, ptr noundef null) #2
  br label %.loopexit

19:                                               ; preds = %13
  %20 = getelementptr inbounds i8, ptr %0, i64 32
  %21 = load i8, ptr %20, align 8, !tbaa !11, !range !14, !noundef !15
  %22 = trunc nuw i8 %21 to i1
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 226, i32 noundef 14, ptr noundef null) #2
  br label %.loopexit

24:                                               ; preds = %19
  %25 = load ptr, ptr %0, align 8, !tbaa !16
  %26 = getelementptr inbounds i8, ptr %25, i64 16
  %27 = load ptr, ptr %26, align 8, !tbaa !17
  %28 = getelementptr inbounds i8, ptr %27, i64 8
  %29 = load i64, ptr %28, align 8, !tbaa !20
  %30 = tail call ptr @wa_alloc(i64 noundef %29) #2
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %.preheader

32:                                               ; preds = %24
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 231, i32 noundef 2) #2
  br label %.loopexit

.preheader:                                       ; preds = %24, %35
  %33 = tail call i32 @int_rand(ptr noundef %27, ptr noundef nonnull %30) #2
  %.not39 = icmp eq i32 %33, 0
  br i1 %.not39, label %35, label %34

34:                                               ; preds = %.preheader
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 235, i32 noundef %33) #2
  br label %.loopexit

35:                                               ; preds = %.preheader
  %36 = tail call i32 @eckcdsa_sign_internal(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %2, ptr noundef nonnull %30, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %37 = icmp eq i32 %36, -1
  br i1 %37, label %.preheader, label %.loopexit, !llvm.loop !22

.loopexit:                                        ; preds = %35, %34, %32, %23, %18, %12, %10, %8, %6
  %.028 = phi ptr [ null, %32 ], [ %30, %34 ], [ null, %23 ], [ null, %18 ], [ null, %12 ], [ null, %10 ], [ null, %8 ], [ null, %6 ], [ %30, %35 ]
  %.0 = phi i32 [ 2, %32 ], [ %33, %34 ], [ 14, %23 ], [ 2, %18 ], [ 2, %12 ], [ 2, %10 ], [ 2, %8 ], [ 2, %6 ], [ %36, %35 ]
  tail call void @wa_free_private(ptr noundef %.028) #2
  ret i32 %.0
}

declare i64 @hash_get_size(i32 noundef) local_unnamed_addr #0

declare ptr @wa_alloc(i64 noundef) local_unnamed_addr #0

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

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

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, !10, i64 8}
!6 = !{!"ByteArray_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, !13, i64 32}
!12 = !{!"EcCtx_st", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !13, i64 32, !13, i64 33}
!13 = !{!"_Bool", !8, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!12, !7, i64 0}
!17 = !{!18, !7, i64 16}
!18 = !{!"EcParamsCtx_st", !19, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !13, i64 40, !10, i64 48, !7, i64 56, !7, i64 64, !19, i64 72, !7, i64 80}
!19 = !{!"int", !8, i64 0}
!20 = !{!21, !10, i64 8}
!21 = !{!"WordArray_st", !7, i64 0, !10, i64 8}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass