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

; 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.RsaCtx_st = type { i32, i32, ptr, i64, ptr, ptr, ptr }
%struct.GfpCtx_st = type { ptr, ptr, ptr, ptr }

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

; 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) #1

declare i64 @int_bit_len(ptr noundef) #1

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

declare i64 @hash_get_size(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @rsa_init_sign_pss(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = call i64 @hash_get_size(i32 noundef %12)
  store i64 %13, ptr %10, align 8, !tbaa !11
  %14 = load i64, ptr %10, align 8, !tbaa !11
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %16, label %21

16:                                               ; preds = %4
  br label %17

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

19:                                               ; No predecessors!
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20, %4
  br label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = call i32 @rsa_init_private(ptr noundef %23, ptr noundef %24, ptr noundef %25)
  store i32 %26, ptr %9, align 4, !tbaa !9
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %22
  %30 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 942, i32 noundef %30)
  br label %74

31:                                               ; preds = %22
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.RsaCtx_st, ptr %34, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !13
  %37 = getelementptr inbounds %struct.GfpCtx_st, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  %39 = call i64 @int_bit_len(ptr noundef %38)
  %40 = add i64 %39, 6
  %41 = udiv i64 %40, 8
  store i64 %41, ptr %11, align 8, !tbaa !11
  %42 = load i64, ptr %11, align 8, !tbaa !11
  %43 = load i64, ptr %10, align 8, !tbaa !11
  %44 = mul i64 %43, 2
  %45 = icmp ult i64 %42, %44
  br i1 %45, label %46, label %51

46:                                               ; preds = %33
  br label %47

47:                                               ; preds = %46
  store i32 2, ptr %9, align 4, !tbaa !9
  %48 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 946, i32 noundef %48, ptr noundef null)
  br label %74

49:                                               ; No predecessors!
  br label %50

50:                                               ; preds = %49
  br label %51

51:                                               ; preds = %50, %33
  %52 = load i64, ptr %11, align 8, !tbaa !11
  %53 = load i64, ptr %10, align 8, !tbaa !11
  %54 = mul i64 %53, 2
  %55 = add i64 %54, 2
  %56 = icmp uge i64 %52, %55
  br i1 %56, label %57, label %61

57:                                               ; preds = %51
  %58 = load i64, ptr %10, align 8, !tbaa !11
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.RsaCtx_st, ptr %59, i32 0, i32 3
  store i64 %58, ptr %60, align 8, !tbaa !17
  br label %68

61:                                               ; preds = %51
  %62 = load i64, ptr %11, align 8, !tbaa !11
  %63 = load i64, ptr %10, align 8, !tbaa !11
  %64 = sub i64 %62, %63
  %65 = sub i64 %64, 2
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.RsaCtx_st, ptr %66, i32 0, i32 3
  store i64 %65, ptr %67, align 8, !tbaa !17
  br label %68

68:                                               ; preds = %61, %57
  %69 = load i32, ptr %6, align 4, !tbaa !9
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.RsaCtx_st, ptr %70, i32 0, i32 1
  store i32 %69, ptr %71, align 4, !tbaa !18
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.RsaCtx_st, ptr %72, i32 0, i32 0
  store i32 7, ptr %73, align 8, !tbaa !19
  br label %74

74:                                               ; preds = %68, %47, %29, %17
  %75 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret i32 %75
}

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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 24}
!14 = !{!"RsaCtx_st", !10, i64 0, !10, i64 4, !6, i64 8, !12, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!15 = !{!16, !6, i64 0}
!16 = !{!"GfpCtx_st", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!17 = !{!14, !12, i64 16}
!18 = !{!14, !10, i64 4}
!19 = !{!14, !10, 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 [13 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 i64 @int_bit_len(ptr noundef) local_unnamed_addr #0

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

declare i64 @hash_get_size(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @rsa_init_sign_pss(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = tail call i64 @hash_get_size(i32 noundef %1) #2
  %6 = icmp eq i64 %5, 0
  br i1 %6, label %7, label %8

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

8:                                                ; preds = %4
  %9 = tail call i32 @rsa_init_private(ptr noundef %0, ptr noundef %2, ptr noundef %3)
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %11, label %10

10:                                               ; preds = %8
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 942, i32 noundef %9) #2
  br label %26

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = tail call i64 @int_bit_len(ptr noundef %14) #2
  %16 = add i64 %15, 6
  %17 = lshr i64 %16, 3
  %18 = shl i64 %5, 1
  %19 = icmp ult i64 %17, %18
  br i1 %19, label %20, label %21

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

21:                                               ; preds = %11
  %22 = add nuw nsw i64 %18, 2
  %.not26 = icmp ult i64 %17, %22
  %reass.sub = sub i64 %17, %5
  %23 = add i64 %reass.sub, -2
  %.sink = select i1 %.not26, i64 %23, i64 %5
  %24 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %.sink, ptr %24, align 8
  %25 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %1, ptr %25, align 4, !tbaa !14
  store i32 7, ptr %0, align 8, !tbaa !15
  br label %26

26:                                               ; preds = %21, %20, %10, %7
  %.0 = phi i32 [ 2, %7 ], [ %9, %10 ], [ 2, %20 ], [ 0, %21 ]
  ret i32 %.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, !10, i64 24}
!6 = !{!"RsaCtx_st", !7, i64 0, !7, i64 4, !10, i64 8, !11, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!13, !10, i64 0}
!13 = !{!"GfpCtx_st", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!14 = !{!6, !7, i64 4}
!15 = !{!6, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass