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

; 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 [16 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 @ecgdsa_sign(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  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 8, ptr %9) #3
  store ptr null, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %12

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

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

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 %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.EcCtx_st, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = getelementptr inbounds %struct.EcParamsCtx_st, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !14
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %29, label %27

27:                                               ; preds = %20
  store i32 2, ptr %11, align 4, !tbaa !9
  %28 = load i32, ptr %11, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 189, i32 noundef %28, ptr noundef null)
  br label %104

29:                                               ; preds = %20
  br label %30

30:                                               ; preds = %29
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %37, label %35

35:                                               ; preds = %32
  store i32 2, ptr %11, align 4, !tbaa !9
  %36 = load i32, ptr %11, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 190, i32 noundef %36, ptr noundef null)
  br label %104

37:                                               ; preds = %32
  br label %38

38:                                               ; preds = %37
  br label %39

39:                                               ; preds = %38
  br label %40

40:                                               ; preds = %39
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = icmp ne ptr %41, null
  br i1 %42, label %45, label %43

43:                                               ; preds = %40
  store i32 2, ptr %11, align 4, !tbaa !9
  %44 = load i32, ptr %11, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 191, i32 noundef %44, ptr noundef null)
  br label %104

45:                                               ; preds = %40
  br label %46

46:                                               ; preds = %45
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %53, label %51

51:                                               ; preds = %48
  store i32 2, ptr %11, align 4, !tbaa !9
  %52 = load i32, ptr %11, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 192, i32 noundef %52, ptr noundef null)
  br label %104

53:                                               ; preds = %48
  br label %54

54:                                               ; preds = %53
  br label %55

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

60:                                               ; preds = %55
  br label %61

61:                                               ; preds = %60
  store i32 14, ptr %11, align 4, !tbaa !9
  %62 = load i32, ptr %11, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 195, i32 noundef %62, ptr noundef null)
  br label %104

63:                                               ; No predecessors!
  br label %64

64:                                               ; preds = %63
  br label %65

65:                                               ; preds = %64, %55
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.EcCtx_st, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !11
  %69 = getelementptr inbounds %struct.EcParamsCtx_st, ptr %68, i32 0, i32 2
  %70 = load ptr, ptr %69, align 8, !tbaa !20
  store ptr %70, ptr %10, align 8, !tbaa !5
  br label %71

71:                                               ; preds = %65
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.WordArray_st, ptr %72, i32 0, i32 1
  %74 = load i64, ptr %73, align 8, !tbaa !21
  %75 = call ptr @wa_alloc(i64 noundef %74)
  store ptr %75, ptr %9, align 8, !tbaa !5
  %76 = icmp eq ptr null, %75
  br i1 %76, label %77, label %79

77:                                               ; preds = %71
  store i32 2, ptr %11, align 4, !tbaa !9
  %78 = load i32, ptr %11, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 200, i32 noundef %78)
  br label %104

79:                                               ; preds = %71
  br label %80

80:                                               ; preds = %79
  br label %81

81:                                               ; preds = %80
  br label %82

82:                                               ; preds = %100, %81
  br label %83

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

89:                                               ; preds = %83
  %90 = load i32, ptr %11, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 204, i32 noundef %90)
  br label %104

91:                                               ; preds = %83
  br label %92

92:                                               ; preds = %91
  br label %93

93:                                               ; preds = %92
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  %95 = load ptr, ptr %6, align 8, !tbaa !5
  %96 = load ptr, ptr %9, align 8, !tbaa !5
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  %98 = load ptr, ptr %8, align 8, !tbaa !5
  %99 = call i32 @ecgdsa_sign_internal(ptr noundef %94, ptr noundef %95, ptr noundef %96, ptr noundef %97, ptr noundef %98)
  store i32 %99, ptr %11, align 4, !tbaa !9
  br label %100

100:                                              ; preds = %93
  %101 = load i32, ptr %11, align 4, !tbaa !9
  %102 = icmp eq i32 %101, -1
  br i1 %102, label %82, label %103, !llvm.loop !23

103:                                              ; preds = %100
  br label %104

104:                                              ; preds = %103, %89, %77, %61, %51, %43, %35, %27, %15
  %105 = load ptr, ptr %9, align 8, !tbaa !5
  call void @wa_free_private(ptr noundef %105)
  %106 = load i32, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret i32 %106
}

declare ptr @wa_alloc(i64 noundef) #1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @ecgdsa_sign_internal(ptr noundef, ptr 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, !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, !10, i64 0}
!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 = !{!12, !13, i64 32}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!15, !6, i64 16}
!21 = !{!22, !16, i64 8}
!22 = !{!"WordArray_st", !6, i64 0, !16, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"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 [16 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 @ecgdsa_sign(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %5, label %6

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

6:                                                ; preds = %4
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  %8 = load i32, ptr %7, align 8, !tbaa !11
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %11, label %10

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

11:                                               ; preds = %6
  %.not34 = icmp eq ptr %1, null
  br i1 %.not34, label %12, label %13

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

13:                                               ; preds = %11
  %.not35 = icmp eq ptr %2, null
  br i1 %.not35, label %14, label %15

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

15:                                               ; preds = %13
  %.not36 = icmp eq ptr %3, null
  br i1 %.not36, label %16, label %17

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

17:                                               ; preds = %15
  %18 = getelementptr inbounds i8, ptr %0, i64 32
  %19 = load i8, ptr %18, align 8, !tbaa !15, !range !16, !noundef !17
  %20 = trunc nuw i8 %19 to i1
  br i1 %20, label %22, label %21

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

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

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

.preheader:                                       ; preds = %22, %32
  %30 = tail call i32 @int_rand(ptr noundef %24, ptr noundef nonnull %27) #2
  %.not37 = icmp eq i32 %30, 0
  br i1 %.not37, label %32, label %31

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

32:                                               ; preds = %.preheader
  %33 = tail call i32 @ecgdsa_sign_internal(ptr noundef nonnull %0, ptr noundef nonnull %1, ptr noundef nonnull %27, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %34 = icmp eq i32 %33, -1
  br i1 %34, label %.preheader, label %.loopexit, !llvm.loop !21

.loopexit:                                        ; preds = %32, %31, %29, %21, %16, %14, %12, %10, %5
  %.026 = phi ptr [ null, %29 ], [ %27, %31 ], [ null, %21 ], [ null, %16 ], [ null, %14 ], [ null, %12 ], [ null, %10 ], [ null, %5 ], [ %27, %32 ]
  %.0 = phi i32 [ 2, %29 ], [ %30, %31 ], [ 14, %21 ], [ 2, %16 ], [ 2, %14 ], [ 2, %12 ], [ 2, %10 ], [ 2, %5 ], [ %33, %32 ]
  tail call void @wa_free_private(ptr noundef %.026) #2
  ret i32 %.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 @ecgdsa_sign_internal(ptr noundef, ptr 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, !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, !13, i64 0}
!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 = !{!6, !10, i64 32}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!12, !7, i64 16}
!19 = !{!20, !14, i64 8}
!20 = !{!"WordArray_st", !7, i64 0, !14, i64 8}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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