; LLVM IR from openssl/openssl :: crypto/ec (ecp_nist)

; 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.ec_group_st = type { ptr, ptr, ptr, ptr, i32, i32, i32, i32, ptr, i64, ptr, [6 x i32], ptr, ptr, i32, ptr, ptr, ptr, ptr, i32, %union.anon, ptr, ptr }
%union.anon = type { ptr }

@.str = external hidden unnamed_addr constant [70 x i8], align 1
@__func__.ossl_ec_GFp_nist_group_set_curve = external hidden unnamed_addr constant [33 x i8], align 1

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

17:                                               ; preds = %5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ec_group_st, ptr %18, i32 0, i32 21
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = call ptr @BN_CTX_new_ex(ptr noundef %20)
  store ptr %21, ptr %13, align 8, !tbaa !5
  store ptr %21, ptr %11, align 8, !tbaa !5
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %24

23:                                               ; preds = %17
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %82

24:                                               ; preds = %17
  br label %25

25:                                               ; preds = %24, %5
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  call void @BN_CTX_start(ptr noundef %26)
  %27 = call ptr @BN_get0_nist_prime_192()
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = call i32 @BN_ucmp(ptr noundef %27, ptr noundef %28)
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %34

31:                                               ; preds = %25
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.ec_group_st, ptr %32, i32 0, i32 17
  store ptr @BN_nist_mod_192, ptr %33, align 8, !tbaa !14
  br label %71

34:                                               ; preds = %25
  %35 = call ptr @BN_get0_nist_prime_224()
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = call i32 @BN_ucmp(ptr noundef %35, ptr noundef %36)
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %42

39:                                               ; preds = %34
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ec_group_st, ptr %40, i32 0, i32 17
  store ptr @BN_nist_mod_224, ptr %41, align 8, !tbaa !14
  br label %70

42:                                               ; preds = %34
  %43 = call ptr @BN_get0_nist_prime_256()
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = call i32 @BN_ucmp(ptr noundef %43, ptr noundef %44)
  %46 = icmp eq i32 %45, 0
  br i1 %46, label %47, label %50

47:                                               ; preds = %42
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.ec_group_st, ptr %48, i32 0, i32 17
  store ptr @BN_nist_mod_256, ptr %49, align 8, !tbaa !14
  br label %69

50:                                               ; preds = %42
  %51 = call ptr @BN_get0_nist_prime_384()
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = call i32 @BN_ucmp(ptr noundef %51, ptr noundef %52)
  %54 = icmp eq i32 %53, 0
  br i1 %54, label %55, label %58

55:                                               ; preds = %50
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.ec_group_st, ptr %56, i32 0, i32 17
  store ptr @BN_nist_mod_384, ptr %57, align 8, !tbaa !14
  br label %68

58:                                               ; preds = %50
  %59 = call ptr @BN_get0_nist_prime_521()
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = call i32 @BN_ucmp(ptr noundef %59, ptr noundef %60)
  %62 = icmp eq i32 %61, 0
  br i1 %62, label %63, label %66

63:                                               ; preds = %58
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.ec_group_st, ptr %64, i32 0, i32 17
  store ptr @BN_nist_mod_521, ptr %65, align 8, !tbaa !14
  br label %67

66:                                               ; preds = %58
  call void @ERR_new()
  call void @ERR_set_debug(ptr noundef @.str, i32 noundef 116, ptr noundef @__func__.ossl_ec_GFp_nist_group_set_curve)
  call void (i32, i32, ptr, ...) @ERR_set_error(i32 noundef 16, i32 noundef 135, ptr noundef null)
  br label %78

67:                                               ; preds = %63
  br label %68

68:                                               ; preds = %67, %55
  br label %69

69:                                               ; preds = %68, %47
  br label %70

70:                                               ; preds = %69, %39
  br label %71

71:                                               ; preds = %70, %31
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  %75 = load ptr, ptr %10, align 8, !tbaa !5
  %76 = load ptr, ptr %11, align 8, !tbaa !5
  %77 = call i32 @ossl_ec_GFp_simple_group_set_curve(ptr noundef %72, ptr noundef %73, ptr noundef %74, ptr noundef %75, ptr noundef %76)
  store i32 %77, ptr %12, align 4, !tbaa !9
  br label %78

78:                                               ; preds = %71, %66
  %79 = load ptr, ptr %11, align 8, !tbaa !5
  call void @BN_CTX_end(ptr noundef %79)
  %80 = load ptr, ptr %13, align 8, !tbaa !5
  call void @BN_CTX_free(ptr noundef %80)
  %81 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %81, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %82

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare ptr @BN_CTX_new_ex(ptr noundef) #2

declare void @BN_CTX_start(ptr noundef) #2

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

declare ptr @BN_get0_nist_prime_192() #2

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

declare ptr @BN_get0_nist_prime_224() #2

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

declare ptr @BN_get0_nist_prime_256() #2

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

declare ptr @BN_get0_nist_prime_384() #2

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

declare ptr @BN_get0_nist_prime_521() #2

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

declare void @ERR_new() #2

declare void @ERR_set_debug(ptr noundef, i32 noundef, ptr noundef) #2

declare void @ERR_set_error(i32 noundef, i32 noundef, ptr noundef, ...) #2

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

declare void @BN_CTX_end(ptr noundef) #2

declare void @BN_CTX_free(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 168}
!12 = !{!"ec_group_st", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !6, i64 48, !13, i64 56, !6, i64 64, !7, i64 72, !6, i64 96, !6, i64 104, !10, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !10, i64 152, !7, i64 160, !6, i64 168, !6, i64 176}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 136}


; 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 [70 x i8], align 1
@__func__.ossl_ec_GFp_nist_group_set_curve = external hidden unnamed_addr constant [33 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @ossl_ec_GFp_nist_group_set_curve(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = icmp eq ptr %4, null
  br i1 %6, label %7, label %12

7:                                                ; preds = %5
  %8 = getelementptr inbounds i8, ptr %0, i64 168
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = tail call ptr @BN_CTX_new_ex(ptr noundef %9) #2
  %11 = icmp eq ptr %10, null
  br i1 %11, label %37, label %12

12:                                               ; preds = %7, %5
  %.022 = phi ptr [ %10, %7 ], [ %4, %5 ]
  %.0 = phi ptr [ %10, %7 ], [ null, %5 ]
  tail call void @BN_CTX_start(ptr noundef nonnull %.022) #2
  %13 = tail call ptr @BN_get0_nist_prime_192() #2
  %14 = tail call i32 @BN_ucmp(ptr noundef %13, ptr noundef %1) #2
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %33, label %16

16:                                               ; preds = %12
  %17 = tail call ptr @BN_get0_nist_prime_224() #2
  %18 = tail call i32 @BN_ucmp(ptr noundef %17, ptr noundef %1) #2
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %33, label %20

20:                                               ; preds = %16
  %21 = tail call ptr @BN_get0_nist_prime_256() #2
  %22 = tail call i32 @BN_ucmp(ptr noundef %21, ptr noundef %1) #2
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %33, label %24

24:                                               ; preds = %20
  %25 = tail call ptr @BN_get0_nist_prime_384() #2
  %26 = tail call i32 @BN_ucmp(ptr noundef %25, ptr noundef %1) #2
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %33, label %28

28:                                               ; preds = %24
  %29 = tail call ptr @BN_get0_nist_prime_521() #2
  %30 = tail call i32 @BN_ucmp(ptr noundef %29, ptr noundef %1) #2
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  tail call void @ERR_new() #2
  tail call void @ERR_set_debug(ptr noundef nonnull @.str, i32 noundef 116, ptr noundef nonnull @__func__.ossl_ec_GFp_nist_group_set_curve) #2
  tail call void (i32, i32, ptr, ...) @ERR_set_error(i32 noundef 16, i32 noundef 135, ptr noundef null) #2
  br label %36

33:                                               ; preds = %28, %24, %20, %16, %12
  %BN_nist_mod_224.sink = phi ptr [ @BN_nist_mod_192, %12 ], [ @BN_nist_mod_224, %16 ], [ @BN_nist_mod_256, %20 ], [ @BN_nist_mod_384, %24 ], [ @BN_nist_mod_521, %28 ]
  %34 = getelementptr inbounds i8, ptr %0, i64 136
  store ptr %BN_nist_mod_224.sink, ptr %34, align 8, !tbaa !12
  %35 = tail call i32 @ossl_ec_GFp_simple_group_set_curve(ptr noundef nonnull %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef nonnull %.022) #2
  br label %36

36:                                               ; preds = %33, %32
  %.021 = phi i32 [ %35, %33 ], [ 0, %32 ]
  tail call void @BN_CTX_end(ptr noundef nonnull %.022) #2
  tail call void @BN_CTX_free(ptr noundef %.0) #2
  br label %37

37:                                               ; preds = %7, %36
  %.023 = phi i32 [ %.021, %36 ], [ 0, %7 ]
  ret i32 %.023
}

declare ptr @BN_CTX_new_ex(ptr noundef) local_unnamed_addr #1

declare void @BN_CTX_start(ptr noundef) local_unnamed_addr #1

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

declare ptr @BN_get0_nist_prime_192() local_unnamed_addr #1

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

declare ptr @BN_get0_nist_prime_224() local_unnamed_addr #1

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

declare ptr @BN_get0_nist_prime_256() local_unnamed_addr #1

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

declare ptr @BN_get0_nist_prime_384() local_unnamed_addr #1

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

declare ptr @BN_get0_nist_prime_521() local_unnamed_addr #1

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

declare void @ERR_new() local_unnamed_addr #1

declare void @ERR_set_debug(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare void @ERR_set_error(i32 noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #1

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

declare void @BN_CTX_end(ptr noundef) local_unnamed_addr #1

declare void @BN_CTX_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 = { 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 168}
!6 = !{!"ec_group_st", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !7, i64 48, !11, i64 56, !7, i64 64, !8, i64 72, !7, i64 96, !7, i64 104, !10, i64 112, !7, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !10, i64 152, !8, i64 160, !7, i64 168, !7, i64 176}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !7, i64 136}


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