; LLVM IR from openssl/openssl :: crypto/evp (dh_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.dh_name2id_st = type { ptr, i32, i32 }

@dhtype2id = external hidden constant [4 x %struct.dh_name2id_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_dh_gen_type_name2id(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, 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) #3
  store i64 0, ptr %6, align 8, !tbaa !11
  br label %8

8:                                                ; preds = %38, %2
  %9 = load i64, ptr %6, align 8, !tbaa !11
  %10 = icmp ult i64 %9, 4
  br i1 %10, label %11, label %41

11:                                               ; preds = %8
  %12 = load i64, ptr %6, align 8, !tbaa !11
  %13 = getelementptr inbounds [4 x %struct.dh_name2id_st], ptr @dhtype2id, i64 0, i64 %12
  %14 = getelementptr inbounds %struct.dh_name2id_st, ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 4, !tbaa !13
  %16 = icmp eq i32 %15, -1
  br i1 %16, label %24, label %17

17:                                               ; preds = %11
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = load i64, ptr %6, align 8, !tbaa !11
  %20 = getelementptr inbounds [4 x %struct.dh_name2id_st], ptr @dhtype2id, i64 0, i64 %19
  %21 = getelementptr inbounds %struct.dh_name2id_st, ptr %20, i32 0, i32 2
  %22 = load i32, ptr %21, align 4, !tbaa !13
  %23 = icmp eq i32 %18, %22
  br i1 %23, label %24, label %37

24:                                               ; preds = %17, %11
  %25 = load i64, ptr %6, align 8, !tbaa !11
  %26 = getelementptr inbounds [4 x %struct.dh_name2id_st], ptr @dhtype2id, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.dh_name2id_st, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 16, !tbaa !15
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = call i32 @strcmp(ptr noundef %28, ptr noundef %29) #4
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %37

32:                                               ; preds = %24
  %33 = load i64, ptr %6, align 8, !tbaa !11
  %34 = getelementptr inbounds [4 x %struct.dh_name2id_st], ptr @dhtype2id, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.dh_name2id_st, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 8, !tbaa !16
  store i32 %36, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %42

37:                                               ; preds = %24, %17
  br label %38

38:                                               ; preds = %37
  %39 = load i64, ptr %6, align 8, !tbaa !11
  %40 = add i64 %39, 1
  store i64 %40, ptr %6, align 8, !tbaa !11
  br label %8, !llvm.loop !17

41:                                               ; preds = %8
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %42

42:                                               ; preds = %41, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %43 = load i32, ptr %3, align 4
  ret i32 %43
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(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 = { nounwind willreturn memory(read) "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 }
attributes #4 = { nounwind willreturn memory(read) }

!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, !10, i64 12}
!14 = !{!"dh_name2id_st", !6, i64 0, !10, i64 8, !10, i64 12}
!15 = !{!14, !6, i64 0}
!16 = !{!14, !10, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"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.dh_name2id_st = type { ptr, i32, i32 }

@dhtype2id = external hidden local_unnamed_addr constant [4 x %struct.dh_name2id_st], align 16

; Function Attrs: mustprogress nofree nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local i32 @ossl_dh_gen_type_name2id(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @dhtype2id, i64 12), align 4, !tbaa !5
  %4 = icmp eq i32 %3, -1
  %5 = icmp eq i32 %3, %1
  %or.cond = or i1 %4, %5
  br i1 %or.cond, label %6, label %13

6:                                                ; preds = %2
  %7 = load ptr, ptr @dhtype2id, align 16, !tbaa !11
  %8 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %7, ptr noundef nonnull dereferenceable(1) %0) #2
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %13

10:                                               ; preds = %33, %25, %17, %6
  %.lcssa = phi ptr [ @dhtype2id, %6 ], [ getelementptr inbounds (i8, ptr @dhtype2id, i64 16), %17 ], [ getelementptr inbounds (i8, ptr @dhtype2id, i64 32), %25 ], [ getelementptr inbounds (i8, ptr @dhtype2id, i64 48), %33 ]
  %11 = getelementptr inbounds i8, ptr %.lcssa, i64 8
  %12 = load i32, ptr %11, align 8, !tbaa !12
  br label %.loopexit

13:                                               ; preds = %2, %6
  %14 = load i32, ptr getelementptr inbounds (i8, ptr @dhtype2id, i64 28), align 4, !tbaa !5
  %15 = icmp eq i32 %14, -1
  %16 = icmp eq i32 %14, %1
  %or.cond.1 = or i1 %15, %16
  br i1 %or.cond.1, label %17, label %21

17:                                               ; preds = %13
  %18 = load ptr, ptr getelementptr inbounds (i8, ptr @dhtype2id, i64 16), align 16, !tbaa !11
  %19 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %18, ptr noundef nonnull dereferenceable(1) %0) #2
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %10, label %21

21:                                               ; preds = %17, %13
  %22 = load i32, ptr getelementptr inbounds (i8, ptr @dhtype2id, i64 44), align 4, !tbaa !5
  %23 = icmp eq i32 %22, -1
  %24 = icmp eq i32 %22, %1
  %or.cond.2 = or i1 %23, %24
  br i1 %or.cond.2, label %25, label %29

25:                                               ; preds = %21
  %26 = load ptr, ptr getelementptr inbounds (i8, ptr @dhtype2id, i64 32), align 16, !tbaa !11
  %27 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %26, ptr noundef nonnull dereferenceable(1) %0) #2
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %10, label %29

29:                                               ; preds = %25, %21
  %30 = load i32, ptr getelementptr inbounds (i8, ptr @dhtype2id, i64 60), align 4, !tbaa !5
  %31 = icmp eq i32 %30, -1
  %32 = icmp eq i32 %30, %1
  %or.cond.3 = or i1 %31, %32
  br i1 %or.cond.3, label %33, label %.loopexit

33:                                               ; preds = %29
  %34 = load ptr, ptr getelementptr inbounds (i8, ptr @dhtype2id, i64 48), align 16, !tbaa !11
  %35 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %34, ptr noundef nonnull dereferenceable(1) %0) #2
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %10, label %.loopexit

.loopexit:                                        ; preds = %29, %33, %10
  %.08 = phi i32 [ %12, %10 ], [ -1, %33 ], [ -1, %29 ]
  ret i32 %.08
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nofree nounwind willreturn memory(read, inaccessiblemem: none) 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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 willreturn memory(read) }

!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 12}
!6 = !{!"dh_name2id_st", !7, i64 0, !10, i64 8, !10, i64 12}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 8}


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