; LLVM IR from openssl/openssl :: crypto/hpke (hpke_util)

; 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.OSSL_HPKE_KEM_INFO = type { i16, ptr, ptr, ptr, i64, i64, i64, i64, i8 }

@hpke_kem_tab = external hidden constant [5 x %struct.OSSL_HPKE_KEM_INFO], align 16
@.str = external hidden unnamed_addr constant [73 x i8], align 1
@__func__.ossl_HPKE_KEM_INFO_find_curve = external hidden unnamed_addr constant [30 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @ossl_HPKE_KEM_INFO_find_curve(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 5, ptr %5, align 4, !tbaa !9
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %39, %1
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %12, label %42

12:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [5 x %struct.OSSL_HPKE_KEM_INFO], ptr @hpke_kem_tab, i64 0, i64 %14
  %16 = getelementptr inbounds %struct.OSSL_HPKE_KEM_INFO, ptr %15, i32 0, i32 2
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  store ptr %17, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %26

20:                                               ; preds = %12
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [5 x %struct.OSSL_HPKE_KEM_INFO], ptr @hpke_kem_tab, i64 0, i64 %22
  %24 = getelementptr inbounds %struct.OSSL_HPKE_KEM_INFO, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !15
  store ptr %25, ptr %6, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %20, %12
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = call i32 @OPENSSL_strcasecmp(ptr noundef %27, ptr noundef %28)
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %35

31:                                               ; preds = %26
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [5 x %struct.OSSL_HPKE_KEM_INFO], ptr @hpke_kem_tab, i64 0, i64 %33
  store ptr %34, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %36

35:                                               ; preds = %26
  store i32 0, ptr %7, align 4
  br label %36

36:                                               ; preds = %35, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %37 = load i32, ptr %7, align 4
  switch i32 %37, label %43 [
    i32 0, label %38
  ]

38:                                               ; preds = %36
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %4, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %4, align 4, !tbaa !9
  br label %8, !llvm.loop !16

42:                                               ; preds = %8
  call void @ERR_new()
  call void @ERR_set_debug(ptr noundef @.str, i32 noundef 168, ptr noundef @__func__.ossl_HPKE_KEM_INFO_find_curve)
  call void (i32, i32, ptr, ...) @ERR_set_error(i32 noundef 57, i32 noundef 176, ptr noundef null)
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %43

43:                                               ; preds = %42, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %44 = load ptr, ptr %2, align 8
  ret ptr %44
}

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

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

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

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

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 16}
!12 = !{!"", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !14, i64 32, !14, i64 40, !14, i64 48, !14, i64 56, !7, i64 64}
!13 = !{!"short", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!12, !6, 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.OSSL_HPKE_KEM_INFO = type { i16, ptr, ptr, ptr, i64, i64, i64, i64, i8 }

@hpke_kem_tab = external hidden constant [5 x %struct.OSSL_HPKE_KEM_INFO], align 16
@.str = external hidden unnamed_addr constant [73 x i8], align 1
@__func__.ossl_HPKE_KEM_INFO_find_curve = external hidden unnamed_addr constant [30 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @ossl_HPKE_KEM_INFO_find_curve(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr getelementptr inbounds (i8, ptr @hpke_kem_tab, i64 16), align 16, !tbaa !5
  %3 = icmp eq ptr %2, null
  %4 = load ptr, ptr getelementptr inbounds (i8, ptr @hpke_kem_tab, i64 8), align 8
  %spec.select = select i1 %3, ptr %4, ptr %2
  %5 = tail call i32 @OPENSSL_strcasecmp(ptr noundef %0, ptr noundef %spec.select) #2
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %.loopexit, label %6

6:                                                ; preds = %1
  %7 = load ptr, ptr getelementptr inbounds (i8, ptr @hpke_kem_tab, i64 88), align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  %9 = load ptr, ptr getelementptr inbounds (i8, ptr @hpke_kem_tab, i64 80), align 16
  %spec.select17 = select i1 %8, ptr %9, ptr %7
  %10 = tail call i32 @OPENSSL_strcasecmp(ptr noundef %0, ptr noundef %spec.select17) #2
  %.not.1 = icmp eq i32 %10, 0
  br i1 %.not.1, label %.loopexit, label %11

11:                                               ; preds = %6
  %12 = load ptr, ptr getelementptr inbounds (i8, ptr @hpke_kem_tab, i64 160), align 16, !tbaa !5
  %13 = icmp eq ptr %12, null
  %14 = load ptr, ptr getelementptr inbounds (i8, ptr @hpke_kem_tab, i64 152), align 8
  %spec.select18 = select i1 %13, ptr %14, ptr %12
  %15 = tail call i32 @OPENSSL_strcasecmp(ptr noundef %0, ptr noundef %spec.select18) #2
  %.not.2 = icmp eq i32 %15, 0
  br i1 %.not.2, label %.loopexit, label %16

16:                                               ; preds = %11
  %17 = load ptr, ptr getelementptr inbounds (i8, ptr @hpke_kem_tab, i64 232), align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  %19 = load ptr, ptr getelementptr inbounds (i8, ptr @hpke_kem_tab, i64 224), align 16
  %spec.select19 = select i1 %18, ptr %19, ptr %17
  %20 = tail call i32 @OPENSSL_strcasecmp(ptr noundef %0, ptr noundef %spec.select19) #2
  %.not.3 = icmp eq i32 %20, 0
  br i1 %.not.3, label %.loopexit, label %21

21:                                               ; preds = %16
  %22 = load ptr, ptr getelementptr inbounds (i8, ptr @hpke_kem_tab, i64 304), align 16, !tbaa !5
  %23 = icmp eq ptr %22, null
  %24 = load ptr, ptr getelementptr inbounds (i8, ptr @hpke_kem_tab, i64 296), align 8
  %spec.select20 = select i1 %23, ptr %24, ptr %22
  %25 = tail call i32 @OPENSSL_strcasecmp(ptr noundef %0, ptr noundef %spec.select20) #2
  %.not.4 = icmp eq i32 %25, 0
  br i1 %.not.4, label %.loopexit, label %26

26:                                               ; preds = %21
  tail call void @ERR_new() #2
  tail call void @ERR_set_debug(ptr noundef nonnull @.str, i32 noundef 168, ptr noundef nonnull @__func__.ossl_HPKE_KEM_INFO_find_curve) #2
  tail call void (i32, i32, ptr, ...) @ERR_set_error(i32 noundef 57, i32 noundef 176, ptr noundef null) #2
  br label %.loopexit

.loopexit:                                        ; preds = %1, %6, %11, %16, %21, %26
  %.2 = phi ptr [ null, %26 ], [ @hpke_kem_tab, %1 ], [ getelementptr inbounds (i8, ptr @hpke_kem_tab, i64 72), %6 ], [ getelementptr inbounds (i8, ptr @hpke_kem_tab, i64 144), %11 ], [ getelementptr inbounds (i8, ptr @hpke_kem_tab, i64 216), %16 ], [ getelementptr inbounds (i8, ptr @hpke_kem_tab, i64 288), %21 ]
  ret ptr %.2
}

declare i32 @OPENSSL_strcasecmp(ptr noundef, ptr noundef) local_unnamed_addr #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

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, !10, i64 16}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !8, i64 64}
!7 = !{!"short", !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}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass