; LLVM IR from Triple-Z/Crypto-DSA :: src/dsa.ll (ZN5MyDSAC2Ev)

; 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"

%class.MyDSA = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr }

; 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 ptr @BN_new() #1

declare void @BN_clear_free(ptr noundef) #1

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

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

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

declare i32 @BN_is_zero(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5MyDSAC2Ev(ptr noundef nonnull align 8 dereferenceable(56) %0) unnamed_addr #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  %7 = call ptr @BN_new()
  %8 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 0
  store ptr %7, ptr %8, align 8, !tbaa !9
  %9 = call ptr @BN_new()
  %10 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 1
  store ptr %9, ptr %10, align 8, !tbaa !11
  %11 = call ptr @BN_new()
  %12 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 2
  store ptr %11, ptr %12, align 8, !tbaa !12
  %13 = call ptr @BN_new()
  %14 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 3
  store ptr %13, ptr %14, align 8, !tbaa !13
  %15 = call ptr @BN_new()
  %16 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 6
  store ptr %15, ptr %16, align 8, !tbaa !14
  %17 = call ptr @BN_new()
  %18 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 4
  store ptr %17, ptr %18, align 8, !tbaa !15
  %19 = call ptr @BN_CTX_new()
  %20 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 5
  store ptr %19, ptr %20, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %21 = call ptr @BN_new()
  store ptr %21, ptr %3, align 8, !tbaa !5
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = call i32 @BN_set_word(ptr noundef %22, i64 noundef 1)
  %24 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = call i32 @BN_generate_prime_ex(ptr noundef %25, i32 noundef 160, i32 noundef 1, ptr noundef null, ptr noundef null, ptr noundef null)
  %27 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %29 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = call i32 @BN_generate_prime_ex(ptr noundef %28, i32 noundef 576, i32 noundef 0, ptr noundef %30, ptr noundef %31, ptr noundef null)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %33 = call ptr @BN_new()
  store ptr %33, ptr %4, align 8, !tbaa !5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = call i32 @BN_sub(ptr noundef %34, ptr noundef %36, ptr noundef %37)
  br label %39

39:                                               ; preds = %54, %1
  %40 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 4
  %41 = load ptr, ptr %40, align 8, !tbaa !15
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = call i32 @BN_rand_range(ptr noundef %41, ptr noundef %42)
  br label %44

44:                                               ; preds = %39
  %45 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 4
  %46 = load ptr, ptr %45, align 8, !tbaa !15
  %47 = call i32 @BN_is_zero(ptr noundef %46)
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %54, label %49

49:                                               ; preds = %44
  %50 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 4
  %51 = load ptr, ptr %50, align 8, !tbaa !15
  %52 = call i32 @BN_is_one(ptr noundef %51)
  %53 = icmp ne i32 %52, 0
  br label %54

54:                                               ; preds = %49, %44
  %55 = phi i1 [ true, %44 ], [ %53, %49 ]
  br i1 %55, label %39, label %56, !llvm.loop !17

56:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %57 = call ptr @BN_new()
  store ptr %57, ptr %5, align 8, !tbaa !5
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !11
  %62 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 5
  %63 = load ptr, ptr %62, align 8, !tbaa !16
  %64 = call i32 @BN_div(ptr noundef %58, ptr noundef null, ptr noundef %59, ptr noundef %61, ptr noundef %63)
  %65 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !12
  %67 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 4
  %68 = load ptr, ptr %67, align 8, !tbaa !15
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !9
  %72 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 5
  %73 = load ptr, ptr %72, align 8, !tbaa !16
  %74 = call i32 @BN_mod_exp(ptr noundef %66, ptr noundef %68, ptr noundef %69, ptr noundef %71, ptr noundef %73)
  br label %75

75:                                               ; preds = %81, %56
  %76 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 6
  %77 = load ptr, ptr %76, align 8, !tbaa !14
  %78 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 1
  %79 = load ptr, ptr %78, align 8, !tbaa !11
  %80 = call i32 @BN_rand_range(ptr noundef %77, ptr noundef %79)
  br label %81

81:                                               ; preds = %75
  %82 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 6
  %83 = load ptr, ptr %82, align 8, !tbaa !14
  %84 = call i32 @BN_is_zero(ptr noundef %83)
  %85 = icmp ne i32 %84, 0
  br i1 %85, label %75, label %86, !llvm.loop !19

86:                                               ; preds = %81
  %87 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 3
  %88 = load ptr, ptr %87, align 8, !tbaa !13
  %89 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 2
  %90 = load ptr, ptr %89, align 8, !tbaa !12
  %91 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 6
  %92 = load ptr, ptr %91, align 8, !tbaa !14
  %93 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 0
  %94 = load ptr, ptr %93, align 8, !tbaa !9
  %95 = getelementptr inbounds %class.MyDSA, ptr %6, i32 0, i32 5
  %96 = load ptr, ptr %95, align 8, !tbaa !16
  %97 = call i32 @BN_mod_exp(ptr noundef %88, ptr noundef %90, ptr noundef %92, ptr noundef %94, ptr noundef %96)
  %98 = load ptr, ptr %3, align 8, !tbaa !5
  call void @BN_clear_free(ptr noundef %98)
  %99 = load ptr, ptr %4, align 8, !tbaa !5
  call void @BN_clear_free(ptr noundef %99)
  %100 = load ptr, ptr %5, align 8, !tbaa !5
  call void @BN_clear_free(ptr noundef %100)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

declare ptr @BN_CTX_new() #1

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

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

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

declare i32 @BN_is_one(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 = { mustprogress 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++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS5MyDSA", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!11 = !{!10, !6, i64 8}
!12 = !{!10, !6, i64 16}
!13 = !{!10, !6, i64 24}
!14 = !{!10, !6, i64 48}
!15 = !{!10, !6, i64 32}
!16 = !{!10, !6, i64 40}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; 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"

declare ptr @BN_new() local_unnamed_addr #0

declare void @BN_clear_free(ptr noundef) local_unnamed_addr #0

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

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

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

declare i32 @BN_is_zero(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5MyDSAC2Ev(ptr nocapture noundef nonnull align 8 dereferenceable(56) %0) unnamed_addr #1 align 2 {
  %2 = tail call ptr @BN_new()
  store ptr %2, ptr %0, align 8, !tbaa !5
  %3 = tail call ptr @BN_new()
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %3, ptr %4, align 8, !tbaa !10
  %5 = tail call ptr @BN_new()
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %5, ptr %6, align 8, !tbaa !11
  %7 = tail call ptr @BN_new()
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %7, ptr %8, align 8, !tbaa !12
  %9 = tail call ptr @BN_new()
  %10 = getelementptr inbounds i8, ptr %0, i64 48
  store ptr %9, ptr %10, align 8, !tbaa !13
  %11 = tail call ptr @BN_new()
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %11, ptr %12, align 8, !tbaa !14
  %13 = tail call ptr @BN_CTX_new()
  %14 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %13, ptr %14, align 8, !tbaa !15
  %15 = tail call ptr @BN_new()
  %16 = tail call i32 @BN_set_word(ptr noundef %15, i64 noundef 1)
  %17 = load ptr, ptr %4, align 8, !tbaa !10
  %18 = tail call i32 @BN_generate_prime_ex(ptr noundef %17, i32 noundef 160, i32 noundef 1, ptr noundef null, ptr noundef null, ptr noundef null)
  %19 = load ptr, ptr %0, align 8, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !10
  %21 = tail call i32 @BN_generate_prime_ex(ptr noundef %19, i32 noundef 576, i32 noundef 0, ptr noundef %20, ptr noundef %15, ptr noundef null)
  %22 = tail call ptr @BN_new()
  %23 = load ptr, ptr %0, align 8, !tbaa !5
  %24 = tail call i32 @BN_sub(ptr noundef %22, ptr noundef %23, ptr noundef %15)
  br label %.critedge

.critedge:                                        ; preds = %.critedge.backedge, %1
  %25 = load ptr, ptr %12, align 8, !tbaa !14
  %26 = tail call i32 @BN_rand_range(ptr noundef %25, ptr noundef %22)
  %27 = load ptr, ptr %12, align 8, !tbaa !14
  %28 = tail call i32 @BN_is_zero(ptr noundef %27)
  %.not = icmp eq i32 %28, 0
  br i1 %.not, label %29, label %.critedge.backedge

29:                                               ; preds = %.critedge
  %30 = load ptr, ptr %12, align 8, !tbaa !14
  %31 = tail call i32 @BN_is_one(ptr noundef %30)
  %.not12 = icmp eq i32 %31, 0
  br i1 %.not12, label %32, label %.critedge.backedge

.critedge.backedge:                               ; preds = %29, %.critedge
  br label %.critedge, !llvm.loop !16

32:                                               ; preds = %29
  %33 = tail call ptr @BN_new()
  %34 = load ptr, ptr %4, align 8, !tbaa !10
  %35 = load ptr, ptr %14, align 8, !tbaa !15
  %36 = tail call i32 @BN_div(ptr noundef %33, ptr noundef null, ptr noundef %22, ptr noundef %34, ptr noundef %35)
  %37 = load ptr, ptr %6, align 8, !tbaa !11
  %38 = load ptr, ptr %12, align 8, !tbaa !14
  %39 = load ptr, ptr %0, align 8, !tbaa !5
  %40 = load ptr, ptr %14, align 8, !tbaa !15
  %41 = tail call i32 @BN_mod_exp(ptr noundef %37, ptr noundef %38, ptr noundef %33, ptr noundef %39, ptr noundef %40)
  br label %42

42:                                               ; preds = %42, %32
  %43 = load ptr, ptr %10, align 8, !tbaa !13
  %44 = load ptr, ptr %4, align 8, !tbaa !10
  %45 = tail call i32 @BN_rand_range(ptr noundef %43, ptr noundef %44)
  %46 = load ptr, ptr %10, align 8, !tbaa !13
  %47 = tail call i32 @BN_is_zero(ptr noundef %46)
  %.not13 = icmp eq i32 %47, 0
  br i1 %.not13, label %48, label %42, !llvm.loop !18

48:                                               ; preds = %42
  %49 = load ptr, ptr %8, align 8, !tbaa !12
  %50 = load ptr, ptr %6, align 8, !tbaa !11
  %51 = load ptr, ptr %10, align 8, !tbaa !13
  %52 = load ptr, ptr %0, align 8, !tbaa !5
  %53 = load ptr, ptr %14, align 8, !tbaa !15
  %54 = tail call i32 @BN_mod_exp(ptr noundef %49, ptr noundef %50, ptr noundef %51, ptr noundef %52, ptr noundef %53)
  tail call void @BN_clear_free(ptr noundef %15)
  tail call void @BN_clear_free(ptr noundef %22)
  tail call void @BN_clear_free(ptr noundef %33)
  ret void
}

declare ptr @BN_CTX_new() local_unnamed_addr #0

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

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

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

declare i32 @BN_is_one(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 = { mustprogress 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" }

!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 = !{!"_ZTS5MyDSA", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!6, !7, i64 16}
!12 = !{!6, !7, i64 24}
!13 = !{!6, !7, i64 48}
!14 = !{!6, !7, i64 32}
!15 = !{!6, !7, i64 40}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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