; LLVM IR from openssl/openssl :: crypto/dsa (dsa_backend)

; 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.dsa_st = type { i32, i32, %struct.ffc_params_st, ptr, ptr, i32, ptr, %struct.CRYPTO_REF_COUNT, %struct.crypto_ex_data_st, ptr, ptr, ptr, ptr, i64 }
%struct.ffc_params_st = type { ptr, ptr, ptr, ptr, ptr, i64, i32, i32, i32, i32, i32, ptr, ptr, i32 }
%struct.CRYPTO_REF_COUNT = type { i32 }
%struct.crypto_ex_data_st = type { 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

; Function Attrs: nounwind uwtable
declare dso_local i32 @ossl_dsa_is_foreign(ptr noundef) #1

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

11:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %82

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.dsa_st, ptr %13, i32 0, i32 12
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = call ptr @ossl_dsa_new(ptr noundef %15)
  store ptr %16, ptr %6, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %12
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %82

19:                                               ; preds = %12
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = and i32 %20, 4
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %31

23:                                               ; preds = %19
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.dsa_st, ptr %24, i32 0, i32 2
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.dsa_st, ptr %26, i32 0, i32 2
  %28 = call i32 @ossl_ffc_params_copy(ptr noundef %25, ptr noundef %27)
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %31, label %30

30:                                               ; preds = %23
  br label %80

31:                                               ; preds = %23, %19
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.dsa_st, ptr %32, i32 0, i32 5
  %34 = load i32, ptr %33, align 8, !tbaa !17
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.dsa_st, ptr %35, i32 0, i32 5
  store i32 %34, ptr %36, align 8, !tbaa !17
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = and i32 %37, 2
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %53

40:                                               ; preds = %31
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = and i32 %41, 4
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %52, label %44

44:                                               ; preds = %40
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.dsa_st, ptr %45, i32 0, i32 3
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.dsa_st, ptr %47, i32 0, i32 3
  %49 = load ptr, ptr %48, align 8, !tbaa !18
  %50 = call i32 @dsa_bn_dup_check(ptr noundef %46, ptr noundef %49)
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %53, label %52

52:                                               ; preds = %44, %40
  br label %80

53:                                               ; preds = %44, %31
  %54 = load i32, ptr %5, align 4, !tbaa !9
  %55 = and i32 %54, 1
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %70

57:                                               ; preds = %53
  %58 = load i32, ptr %5, align 4, !tbaa !9
  %59 = and i32 %58, 4
  %60 = icmp eq i32 %59, 0
  br i1 %60, label %69, label %61

61:                                               ; preds = %57
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.dsa_st, ptr %62, i32 0, i32 4
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.dsa_st, ptr %64, i32 0, i32 4
  %66 = load ptr, ptr %65, align 8, !tbaa !19
  %67 = call i32 @dsa_bn_dup_check(ptr noundef %63, ptr noundef %66)
  %68 = icmp ne i32 %67, 0
  br i1 %68, label %70, label %69

69:                                               ; preds = %61, %57
  br label %80

70:                                               ; preds = %61, %53
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.dsa_st, ptr %71, i32 0, i32 8
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.dsa_st, ptr %73, i32 0, i32 8
  %75 = call i32 @CRYPTO_dup_ex_data(i32 noundef 7, ptr noundef %72, ptr noundef %74)
  %76 = icmp ne i32 %75, 0
  br i1 %76, label %78, label %77

77:                                               ; preds = %70
  br label %80

78:                                               ; preds = %70
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %79, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %82

80:                                               ; preds = %77, %69, %52, %30
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  call void @DSA_free(ptr noundef %81)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %82

82:                                               ; preds = %80, %78, %18, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %83 = load ptr, ptr %3, align 8
  ret ptr %83
}

declare ptr @ossl_dsa_new(ptr noundef) #2

declare i32 @ossl_ffc_params_copy(ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @dsa_bn_dup_check(ptr noundef, ptr noundef) #3

declare i32 @CRYPTO_dup_ex_data(i32 noundef, ptr noundef, ptr noundef) #2

declare void @DSA_free(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = { inlinehint 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 #4 = { 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 184}
!12 = !{!"dsa_st", !10, i64 0, !10, i64 4, !13, i64 8, !6, i64 104, !6, i64 112, !10, i64 120, !6, i64 128, !15, i64 136, !16, i64 144, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !14, i64 192}
!13 = !{!"ffc_params_st", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !14, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !6, i64 72, !6, i64 80, !10, i64 88}
!14 = !{!"long", !7, i64 0}
!15 = !{!"", !7, i64 0}
!16 = !{!"crypto_ex_data_st", !6, i64 0, !6, i64 8}
!17 = !{!12, !10, i64 120}
!18 = !{!12, !6, i64 104}
!19 = !{!12, !6, i64 112}


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

; Function Attrs: nounwind uwtable
declare dso_local i32 @ossl_dsa_is_foreign(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @ossl_dsa_dup(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @ossl_dsa_is_foreign(ptr noundef %0)
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %4, label %41

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 184
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = tail call ptr @ossl_dsa_new(ptr noundef %6) #3
  %8 = icmp eq ptr %7, null
  br i1 %8, label %41, label %9

9:                                                ; preds = %4
  %10 = and i32 %1, 4
  %.not20 = icmp eq i32 %10, 0
  br i1 %.not20, label %15, label %11

11:                                               ; preds = %9
  %12 = getelementptr inbounds i8, ptr %7, i64 8
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = tail call i32 @ossl_ffc_params_copy(ptr noundef nonnull %12, ptr noundef nonnull %13) #3
  %.not21 = icmp eq i32 %14, 0
  br i1 %.not21, label %.thread31, label %.thread

15:                                               ; preds = %9
  %16 = getelementptr inbounds i8, ptr %0, i64 120
  %17 = load i32, ptr %16, align 8, !tbaa !15
  %18 = getelementptr inbounds i8, ptr %7, i64 120
  store i32 %17, ptr %18, align 8, !tbaa !15
  %19 = and i32 %1, 3
  %or.cond = icmp eq i32 %19, 0
  br i1 %or.cond, label %37, label %.thread31

.thread:                                          ; preds = %11
  %20 = getelementptr inbounds i8, ptr %0, i64 120
  %21 = load i32, ptr %20, align 8, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %7, i64 120
  store i32 %21, ptr %22, align 8, !tbaa !15
  %23 = and i32 %1, 2
  %.not2227 = icmp eq i32 %23, 0
  br i1 %.not2227, label %29, label %24

24:                                               ; preds = %.thread
  %25 = getelementptr inbounds i8, ptr %7, i64 104
  %26 = getelementptr inbounds i8, ptr %0, i64 104
  %27 = load ptr, ptr %26, align 8, !tbaa !16
  %28 = tail call i32 @dsa_bn_dup_check(ptr noundef nonnull %25, ptr noundef %27)
  %.not23 = icmp eq i32 %28, 0
  br i1 %.not23, label %.thread31, label %29

29:                                               ; preds = %.thread, %24
  %30 = and i32 %1, 1
  %.not24 = icmp eq i32 %30, 0
  br i1 %.not24, label %37, label %31

31:                                               ; preds = %29
  br i1 %.not20, label %.thread31, label %32

32:                                               ; preds = %31
  %33 = getelementptr inbounds i8, ptr %7, i64 112
  %34 = getelementptr inbounds i8, ptr %0, i64 112
  %35 = load ptr, ptr %34, align 8, !tbaa !17
  %36 = tail call i32 @dsa_bn_dup_check(ptr noundef nonnull %33, ptr noundef %35)
  %.not25 = icmp eq i32 %36, 0
  br i1 %.not25, label %.thread31, label %37

37:                                               ; preds = %15, %32, %29
  %38 = getelementptr inbounds i8, ptr %7, i64 144
  %39 = getelementptr inbounds i8, ptr %0, i64 144
  %40 = tail call i32 @CRYPTO_dup_ex_data(i32 noundef 7, ptr noundef nonnull %38, ptr noundef nonnull %39) #3
  %.not26 = icmp eq i32 %40, 0
  br i1 %.not26, label %.thread31, label %41

.thread31:                                        ; preds = %15, %37, %31, %32, %24, %11
  tail call void @DSA_free(ptr noundef nonnull %7) #3
  br label %41

41:                                               ; preds = %37, %4, %2, %.thread31
  %.0 = phi ptr [ null, %.thread31 ], [ null, %2 ], [ null, %4 ], [ %7, %37 ]
  ret ptr %.0
}

declare ptr @ossl_dsa_new(ptr noundef) local_unnamed_addr #1

declare i32 @ossl_ffc_params_copy(ptr noundef, ptr noundef) local_unnamed_addr #1

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

declare i32 @CRYPTO_dup_ex_data(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @DSA_free(ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 = { inlinehint 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, !11, i64 184}
!6 = !{!"dsa_st", !7, i64 0, !7, i64 4, !10, i64 8, !11, i64 104, !11, i64 112, !7, i64 120, !11, i64 128, !13, i64 136, !14, i64 144, !11, i64 160, !11, i64 168, !11, i64 176, !11, i64 184, !12, i64 192}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"ffc_params_st", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !12, i64 40, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !7, i64 64, !11, i64 72, !11, i64 80, !7, i64 88}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = !{!"", !8, i64 0}
!14 = !{!"crypto_ex_data_st", !11, i64 0, !11, i64 8}
!15 = !{!6, !7, i64 120}
!16 = !{!6, !11, i64 104}
!17 = !{!6, !11, i64 112}


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