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

; 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.ecx_key_st = type { ptr, ptr, i8, [57 x i8], ptr, i64, i32, %struct.CRYPTO_REF_COUNT }
%struct.CRYPTO_REF_COUNT = type { i32 }

@.str = external hidden unnamed_addr constant [69 x i8], align 1

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

15:                                               ; preds = %4
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %78

16:                                               ; preds = %4
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %10, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ecx_key_st, ptr %18, i32 0, i32 0
  store ptr %17, ptr %19, align 8, !tbaa !11
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.ecx_key_st, ptr %21, i32 0, i32 2
  %23 = trunc i32 %20 to i8
  %24 = load i8, ptr %22, align 8
  %25 = and i8 %23, 1
  %26 = and i8 %24, -2
  %27 = or i8 %26, %25
  store i8 %27, ptr %22, align 8
  %28 = zext i8 %25 to i32
  %29 = load i32, ptr %7, align 4, !tbaa !9
  switch i32 %29, label %42 [
    i32 0, label %30
    i32 1, label %33
    i32 2, label %36
    i32 3, label %39
  ]

30:                                               ; preds = %16
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ecx_key_st, ptr %31, i32 0, i32 5
  store i64 32, ptr %32, align 8, !tbaa !15
  br label %42

33:                                               ; preds = %16
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ecx_key_st, ptr %34, i32 0, i32 5
  store i64 56, ptr %35, align 8, !tbaa !15
  br label %42

36:                                               ; preds = %16
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ecx_key_st, ptr %37, i32 0, i32 5
  store i64 32, ptr %38, align 8, !tbaa !15
  br label %42

39:                                               ; preds = %16
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ecx_key_st, ptr %40, i32 0, i32 5
  store i64 57, ptr %41, align 8, !tbaa !15
  br label %42

42:                                               ; preds = %39, %36, %33, %30, %16
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ecx_key_st, ptr %44, i32 0, i32 6
  store i32 %43, ptr %45, align 8, !tbaa !16
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.ecx_key_st, ptr %46, i32 0, i32 7
  %48 = call i32 @CRYPTO_NEW_REF(ptr noundef %47, i32 noundef 1)
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %51, label %50

50:                                               ; preds = %42
  br label %67

51:                                               ; preds = %42
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %65

54:                                               ; preds = %51
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = call ptr @CRYPTO_strdup(ptr noundef %55, ptr noundef @.str, i32 noundef 50)
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.ecx_key_st, ptr %57, i32 0, i32 1
  store ptr %56, ptr %58, align 8, !tbaa !17
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.ecx_key_st, ptr %59, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !17
  %62 = icmp eq ptr %61, null
  br i1 %62, label %63, label %64

63:                                               ; preds = %54
  br label %67

64:                                               ; preds = %54
  br label %65

65:                                               ; preds = %64, %51
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %66, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %78

67:                                               ; preds = %63, %50
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = icmp ne ptr %68, null
  br i1 %69, label %70, label %76

70:                                               ; preds = %67
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.ecx_key_st, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !17
  call void @CRYPTO_free(ptr noundef %73, ptr noundef @.str, i32 noundef 57)
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.ecx_key_st, ptr %74, i32 0, i32 7
  call void @CRYPTO_FREE_REF(ptr noundef %75)
  br label %76

76:                                               ; preds = %70, %67
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  call void @CRYPTO_free(ptr noundef %77, ptr noundef @.str, i32 noundef 60)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %78

78:                                               ; preds = %76, %65, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %79 = load ptr, ptr %5, align 8
  ret ptr %79
}

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

declare ptr @CRYPTO_zalloc(i64 noundef, ptr noundef, i32 noundef) #2

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @CRYPTO_FREE_REF(ptr noundef) #3

; 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 = { 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 0}
!12 = !{!"ecx_key_st", !6, i64 0, !6, i64 8, !10, i64 16, !7, i64 17, !6, i64 80, !13, i64 88, !10, i64 96, !14, i64 100}
!13 = !{!"long", !7, i64 0}
!14 = !{!"", !7, i64 0}
!15 = !{!12, !13, i64 88}
!16 = !{!12, !10, i64 96}
!17 = !{!12, !6, i64 8}


; 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 [69 x i8], align 1
@switch.table.ossl_ecx_key_new = private unnamed_addr constant [4 x i64] [i64 32, i64 56, i64 32, i64 57], align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @ossl_ecx_key_new(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = tail call ptr @CRYPTO_zalloc(i64 noundef 104, ptr noundef nonnull @.str, i32 noundef 23) #3
  %6 = icmp eq ptr %5, null
  br i1 %6, label %28, label %7

7:                                                ; preds = %4
  store ptr %0, ptr %5, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %5, i64 16
  %9 = trunc i32 %2 to i8
  %10 = load i8, ptr %8, align 8
  %11 = and i8 %9, 1
  %12 = and i8 %10, -2
  %13 = or disjoint i8 %12, %11
  store i8 %13, ptr %8, align 8
  %14 = icmp ult i32 %1, 4
  br i1 %14, label %switch.lookup, label %17

switch.lookup:                                    ; preds = %7
  %15 = zext nneg i32 %1 to i64
  %switch.gep = getelementptr inbounds [4 x i64], ptr @switch.table.ossl_ecx_key_new, i64 0, i64 %15
  %switch.load = load i64, ptr %switch.gep, align 8
  %16 = getelementptr inbounds i8, ptr %5, i64 88
  store i64 %switch.load, ptr %16, align 8, !tbaa !13
  br label %17

17:                                               ; preds = %7, %switch.lookup
  %18 = getelementptr inbounds i8, ptr %5, i64 96
  store i32 %1, ptr %18, align 8, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %5, i64 100
  %20 = tail call i32 @CRYPTO_NEW_REF(ptr noundef nonnull %19, i32 noundef 1)
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %._crit_edge, label %21

._crit_edge:                                      ; preds = %17
  %.phi.trans.insert = getelementptr inbounds i8, ptr %5, i64 8
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !15
  br label %26

21:                                               ; preds = %17
  %.not24 = icmp eq ptr %3, null
  br i1 %.not24, label %28, label %22

22:                                               ; preds = %21
  %23 = tail call ptr @CRYPTO_strdup(ptr noundef nonnull %3, ptr noundef nonnull @.str, i32 noundef 50) #3
  %24 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr %23, ptr %24, align 8, !tbaa !15
  %25 = icmp eq ptr %23, null
  br i1 %25, label %26, label %28

26:                                               ; preds = %._crit_edge, %22
  %27 = phi ptr [ %.pre, %._crit_edge ], [ null, %22 ]
  tail call void @CRYPTO_free(ptr noundef %27, ptr noundef nonnull @.str, i32 noundef 57) #3
  tail call void @CRYPTO_FREE_REF(ptr noundef nonnull %19)
  tail call void @CRYPTO_free(ptr noundef nonnull %5, ptr noundef nonnull @.str, i32 noundef 60) #3
  br label %28

28:                                               ; preds = %21, %22, %4, %26
  %.0 = phi ptr [ null, %26 ], [ null, %4 ], [ %5, %22 ], [ %5, %21 ]
  ret ptr %.0
}

declare ptr @CRYPTO_zalloc(i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @CRYPTO_FREE_REF(ptr noundef) local_unnamed_addr #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 = { "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, !7, i64 0}
!6 = !{!"ecx_key_st", !7, i64 0, !7, i64 8, !10, i64 16, !8, i64 17, !7, i64 80, !11, i64 88, !10, i64 96, !12, i64 100}
!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 = !{!"", !8, i64 0}
!13 = !{!6, !11, i64 88}
!14 = !{!6, !10, i64 96}
!15 = !{!6, !7, i64 8}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass