; LLVM IR from openssl/openssl :: crypto/evp (ec_support)

; 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_name2nid_st = type { ptr, i32 }

@curve_list = external hidden constant [82 x %struct.ec_name2nid_st], align 16

; 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
define dso_local i32 @ossl_ec_curve_name2nid(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %37

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = call i32 @ossl_ec_curve_nist2nid_int(ptr noundef %10)
  store i32 %11, ptr %5, align 4, !tbaa !9
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %13, label %15

13:                                               ; preds = %9
  %14 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %14, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %38

15:                                               ; preds = %9
  store i64 0, ptr %4, align 8, !tbaa !11
  br label %16

16:                                               ; preds = %33, %15
  %17 = load i64, ptr %4, align 8, !tbaa !11
  %18 = icmp ult i64 %17, 82
  br i1 %18, label %19, label %36

19:                                               ; preds = %16
  %20 = load i64, ptr %4, align 8, !tbaa !11
  %21 = getelementptr inbounds [82 x %struct.ec_name2nid_st], ptr @curve_list, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.ec_name2nid_st, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 16, !tbaa !13
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = call i32 @OPENSSL_strcasecmp(ptr noundef %23, ptr noundef %24)
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %32

27:                                               ; preds = %19
  %28 = load i64, ptr %4, align 8, !tbaa !11
  %29 = getelementptr inbounds [82 x %struct.ec_name2nid_st], ptr @curve_list, i64 0, i64 %28
  %30 = getelementptr inbounds %struct.ec_name2nid_st, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 8, !tbaa !15
  store i32 %31, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %38

32:                                               ; preds = %19
  br label %33

33:                                               ; preds = %32
  %34 = load i64, ptr %4, align 8, !tbaa !11
  %35 = add i64 %34, 1
  store i64 %35, ptr %4, align 8, !tbaa !11
  br label %16, !llvm.loop !16

36:                                               ; preds = %16
  br label %37

37:                                               ; preds = %36, %1
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %38

38:                                               ; preds = %37, %27, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %39 = load i32, ptr %2, align 4
  ret i32 %39
}

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

declare i32 @OPENSSL_strcasecmp(ptr noundef, 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 = { 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 0}
!14 = !{!"ec_name2nid_st", !6, i64 0, !10, i64 8}
!15 = !{!14, !10, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"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"

%struct.ec_name2nid_st = type { ptr, i32 }

@curve_list = external hidden local_unnamed_addr constant [82 x %struct.ec_name2nid_st], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @ossl_ec_curve_name2nid(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.loopexit, label %2

2:                                                ; preds = %1
  %3 = tail call i32 @ossl_ec_curve_nist2nid_int(ptr noundef nonnull %0)
  %.not11 = icmp eq i32 %3, 0
  br i1 %.not11, label %.preheader, label %.loopexit

4:                                                ; preds = %.preheader
  %5 = add nuw nsw i64 %.0812, 1
  %exitcond.not = icmp eq i64 %5, 82
  br i1 %exitcond.not, label %.loopexit, label %.preheader, !llvm.loop !5

.preheader:                                       ; preds = %2, %4
  %.0812 = phi i64 [ %5, %4 ], [ 0, %2 ]
  %6 = getelementptr inbounds [82 x %struct.ec_name2nid_st], ptr @curve_list, i64 0, i64 %.0812
  %7 = load ptr, ptr %6, align 16, !tbaa !7
  %8 = tail call i32 @OPENSSL_strcasecmp(ptr noundef %7, ptr noundef nonnull %0) #2
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %4

10:                                               ; preds = %.preheader
  %11 = getelementptr inbounds i8, ptr %6, i64 8
  %12 = load i32, ptr %11, align 8, !tbaa !13
  br label %.loopexit

.loopexit:                                        ; preds = %4, %1, %2, %10
  %.0 = phi i32 [ %12, %10 ], [ %3, %2 ], [ 0, %1 ], [ 0, %4 ]
  ret i32 %.0
}

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

declare i32 @OPENSSL_strcasecmp(ptr noundef, 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !9, i64 0}
!8 = !{!"ec_name2nid_st", !9, i64 0, !12, i64 8}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"int", !10, i64 0}
!13 = !{!8, !12, i64 8}


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