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

; 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 [18 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 @dstu4145_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 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 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %11

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

14:                                               ; preds = %11
  store i32 2, ptr %10, align 4, !tbaa !9
  %15 = load i32, ptr %10, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 280, i32 noundef %15, ptr noundef null)
  br label %126

16:                                               ; preds = %11
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  br label %19

19:                                               ; preds = %18
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %24, label %22

22:                                               ; preds = %19
  store i32 2, ptr %10, align 4, !tbaa !9
  %23 = load i32, ptr %10, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 281, i32 noundef %23, ptr noundef null)
  br label %126

24:                                               ; preds = %19
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.ByteArray_st, ptr %28, i32 0, i32 1
  %30 = load i64, ptr %29, align 8, !tbaa !11
  %31 = icmp eq i64 %30, 32
  br i1 %31, label %44, label %32

32:                                               ; preds = %27
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ByteArray_st, ptr %33, i32 0, i32 1
  %35 = load i64, ptr %34, align 8, !tbaa !11
  %36 = icmp eq i64 %35, 48
  br i1 %36, label %44, label %37

37:                                               ; preds = %32
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ByteArray_st, ptr %38, i32 0, i32 1
  %40 = load i64, ptr %39, align 8, !tbaa !11
  %41 = icmp eq i64 %40, 64
  br i1 %41, label %44, label %42

42:                                               ; preds = %37
  store i32 2, ptr %10, align 4, !tbaa !9
  %43 = load i32, ptr %10, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 282, i32 noundef %43, ptr noundef null)
  br label %126

44:                                               ; preds = %37, %32, %27
  br label %45

45:                                               ; preds = %44
  br label %46

46:                                               ; preds = %45
  br label %47

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

50:                                               ; preds = %47
  store i32 2, ptr %10, align 4, !tbaa !9
  %51 = load i32, ptr %10, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 283, i32 noundef %51, ptr noundef null)
  br label %126

52:                                               ; preds = %47
  br label %53

53:                                               ; preds = %52
  br label %54

54:                                               ; preds = %53
  br label %55

55:                                               ; preds = %54
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = icmp ne ptr %56, null
  br i1 %57, label %60, label %58

58:                                               ; preds = %55
  store i32 2, ptr %10, align 4, !tbaa !9
  %59 = load i32, ptr %10, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 284, i32 noundef %59, ptr noundef null)
  br label %126

60:                                               ; preds = %55
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.EcCtx_st, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !14
  %67 = getelementptr inbounds %struct.EcParamsCtx_st, ptr %66, i32 0, i32 0
  %68 = load i32, ptr %67, align 8, !tbaa !17
  %69 = icmp eq i32 %68, 1
  br i1 %69, label %72, label %70

70:                                               ; preds = %63
  store i32 2, ptr %10, align 4, !tbaa !9
  %71 = load i32, ptr %10, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 285, i32 noundef %71, ptr noundef null)
  br label %126

72:                                               ; preds = %63
  br label %73

73:                                               ; preds = %72
  br label %74

74:                                               ; preds = %73
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.EcCtx_st, ptr %75, i32 0, i32 4
  %77 = load i8, ptr %76, align 8, !tbaa !19, !range !20, !noundef !21
  %78 = trunc i8 %77 to i1
  br i1 %78, label %84, label %79

79:                                               ; preds = %74
  br label %80

80:                                               ; preds = %79
  store i32 14, ptr %10, align 4, !tbaa !9
  %81 = load i32, ptr %10, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 288, i32 noundef %81, ptr noundef null)
  br label %126

82:                                               ; No predecessors!
  br label %83

83:                                               ; preds = %82
  br label %84

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

85:                                               ; preds = %84
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.EcCtx_st, ptr %86, i32 0, i32 0
  %88 = load ptr, ptr %87, align 8, !tbaa !14
  %89 = getelementptr inbounds %struct.EcParamsCtx_st, ptr %88, i32 0, i32 2
  %90 = load ptr, ptr %89, align 8, !tbaa !22
  %91 = getelementptr inbounds %struct.WordArray_st, ptr %90, i32 0, i32 1
  %92 = load i64, ptr %91, align 8, !tbaa !23
  %93 = call ptr @wa_alloc(i64 noundef %92)
  store ptr %93, ptr %9, align 8, !tbaa !5
  %94 = icmp eq ptr null, %93
  br i1 %94, label %95, label %97

95:                                               ; preds = %85
  store i32 2, ptr %10, align 4, !tbaa !9
  %96 = load i32, ptr %10, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 291, i32 noundef %96)
  br label %126

97:                                               ; preds = %85
  br label %98

98:                                               ; preds = %97
  br label %99

99:                                               ; preds = %98
  br label %100

100:                                              ; preds = %122, %99
  br label %101

101:                                              ; preds = %100
  %102 = load ptr, ptr %5, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.EcCtx_st, ptr %102, i32 0, i32 0
  %104 = load ptr, ptr %103, align 8, !tbaa !14
  %105 = getelementptr inbounds %struct.EcParamsCtx_st, ptr %104, i32 0, i32 2
  %106 = load ptr, ptr %105, align 8, !tbaa !22
  %107 = load ptr, ptr %9, align 8, !tbaa !5
  %108 = call i32 @int_rand(ptr noundef %106, ptr noundef %107)
  store i32 %108, ptr %10, align 4, !tbaa !9
  %109 = load i32, ptr %10, align 4, !tbaa !9
  %110 = icmp ne i32 %109, 0
  br i1 %110, label %111, label %113

111:                                              ; preds = %101
  %112 = load i32, ptr %10, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 294, i32 noundef %112)
  br label %126

113:                                              ; preds = %101
  br label %114

114:                                              ; preds = %113
  br label %115

115:                                              ; preds = %114
  %116 = load ptr, ptr %5, align 8, !tbaa !5
  %117 = load ptr, ptr %6, align 8, !tbaa !5
  %118 = load ptr, ptr %9, align 8, !tbaa !5
  %119 = load ptr, ptr %7, align 8, !tbaa !5
  %120 = load ptr, ptr %8, align 8, !tbaa !5
  %121 = call i32 @dstu4145_sign_internal(ptr noundef %116, ptr noundef %117, ptr noundef %118, ptr noundef %119, ptr noundef %120)
  store i32 %121, ptr %10, align 4, !tbaa !9
  br label %122

122:                                              ; preds = %115
  %123 = load i32, ptr %10, align 4, !tbaa !9
  %124 = icmp eq i32 %123, -1
  br i1 %124, label %100, label %125, !llvm.loop !25

125:                                              ; preds = %122
  br label %126

126:                                              ; preds = %125, %111, %95, %80, %70, %58, %50, %42, %22, %14
  %127 = load ptr, ptr %9, align 8, !tbaa !5
  call void @wa_free_private(ptr noundef %127)
  %128 = load i32, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret i32 %128
}

declare ptr @wa_alloc(i64 noundef) #1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @dstu4145_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, !13, i64 8}
!12 = !{!"ByteArray_st", !6, i64 0, !13, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !6, i64 0}
!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 = !{!18, !10, i64 0}
!18 = !{!"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}
!19 = !{!15, !16, i64 32}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!18, !6, i64 16}
!23 = !{!24, !13, i64 8}
!24 = !{!"WordArray_st", !6, i64 0, !13, i64 8}
!25 = distinct !{!25, !26}
!26 = !{!"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 [18 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 @dstu4145_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 280, i32 noundef 2, ptr noundef null) #2
  br label %.loopexit

6:                                                ; preds = %4
  %.not38 = icmp eq ptr %1, null
  br i1 %.not38, label %7, label %8

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

8:                                                ; preds = %6
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load i64, ptr %9, align 8, !tbaa !5
  switch i64 %10, label %11 [
    i64 32, label %12
    i64 48, label %12
    i64 64, label %12
  ]

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

12:                                               ; preds = %8, %8, %8
  %.not39 = icmp eq ptr %2, null
  br i1 %.not39, label %13, label %14

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

14:                                               ; preds = %12
  %.not40 = icmp eq ptr %3, null
  br i1 %.not40, label %15, label %16

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

16:                                               ; preds = %14
  %17 = load ptr, ptr %0, align 8, !tbaa !11
  %18 = load i32, ptr %17, align 8, !tbaa !14
  %19 = icmp eq i32 %18, 1
  br i1 %19, label %21, label %20

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

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

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

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

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

.preheader:                                       ; preds = %26, %39
  %34 = load ptr, ptr %0, align 8, !tbaa !11
  %35 = getelementptr inbounds i8, ptr %34, i64 16
  %36 = load ptr, ptr %35, align 8, !tbaa !20
  %37 = tail call i32 @int_rand(ptr noundef %36, ptr noundef nonnull %31) #2
  %.not41 = icmp eq i32 %37, 0
  br i1 %.not41, label %39, label %38

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

39:                                               ; preds = %.preheader
  %40 = tail call i32 @dstu4145_sign_internal(ptr noundef nonnull %0, ptr noundef nonnull %1, ptr noundef nonnull %31, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %41 = icmp eq i32 %40, -1
  br i1 %41, label %.preheader, label %.loopexit, !llvm.loop !23

.loopexit:                                        ; preds = %39, %38, %33, %25, %20, %15, %13, %11, %7, %5
  %.029 = phi ptr [ null, %33 ], [ %31, %38 ], [ null, %25 ], [ null, %20 ], [ null, %15 ], [ null, %13 ], [ null, %11 ], [ null, %7 ], [ null, %5 ], [ %31, %39 ]
  %.0 = phi i32 [ 2, %33 ], [ %37, %38 ], [ 14, %25 ], [ 2, %20 ], [ 2, %15 ], [ 2, %13 ], [ 2, %11 ], [ 2, %7 ], [ 2, %5 ], [ %40, %39 ]
  tail call void @wa_free_private(ptr noundef %.029) #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 @dstu4145_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, !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, !7, i64 0}
!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 = !{!15, !16, i64 0}
!15 = !{!"EcParamsCtx_st", !16, 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, !16, i64 72, !7, i64 80}
!16 = !{!"int", !8, i64 0}
!17 = !{!12, !13, i64 32}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!15, !7, i64 16}
!21 = !{!22, !10, i64 8}
!22 = !{!"WordArray_st", !7, i64 0, !10, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


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