; LLVM IR from aws/s2n-tls :: tests/unit (s2n_pkey_test)

; 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.s2n_result = type { i32 }
%struct.s2n_cert_chain_and_key = type { ptr, ptr, %struct.s2n_blob, %struct.s2n_blob, ptr, ptr, ptr }
%struct.s2n_blob = type { ptr, i32, i32, i8 }
%struct.s2n_test_pkeys = type { %struct.s2n_pkey, ptr, i8 }
%struct.s2n_pkey = type { ptr, ptr, ptr, ptr, ptr, ptr }
%struct.s2n_cert_chain = type { i32, ptr }
%struct.s2n_cert = type { i32, %struct.s2n_pkey, %struct.s2n_cert_info, %struct.s2n_blob, ptr }
%struct.s2n_cert_info = type { i32, i32, i32, i32, i8 }

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_test_pkeys_init(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca %struct.s2n_result, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca %struct.s2n_result, align 4
  %12 = alloca %struct.s2n_result, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store ptr null, ptr %8, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = call i32 @s2n_test_cert_chain_and_key_new(ptr noundef %8, ptr noundef %14, ptr noundef %15)
  %17 = icmp sgt i32 %16, -1
  br i1 %17, label %20, label %18

18:                                               ; preds = %13
  %19 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  store i32 -1, ptr %19, align 4, !tbaa !9
  store i32 1, ptr %9, align 4
  br label %53

20:                                               ; preds = %13
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.s2n_cert_chain_and_key, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.s2n_test_pkeys, ptr %26, i32 0, i32 1
  store ptr %25, ptr %27, align 8, !tbaa !15
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.s2n_cert_chain_and_key, ptr %28, i32 0, i32 1
  store ptr null, ptr %29, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !19
  br label %30

30:                                               ; preds = %22
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.s2n_test_pkeys, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.s2n_cert_chain_and_key, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !20
  %36 = getelementptr inbounds %struct.s2n_cert_chain, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !21
  %38 = getelementptr inbounds %struct.s2n_cert, ptr %37, i32 0, i32 3
  %39 = call i32 @s2n_asn1der_to_public_key_and_type(ptr noundef %32, ptr noundef %10, ptr noundef %38)
  %40 = getelementptr inbounds %struct.s2n_result, ptr %11, i32 0, i32 0
  store i32 %39, ptr %40, align 4
  %41 = getelementptr inbounds %struct.s2n_result, ptr %11, i32 0, i32 0
  %42 = load i32, ptr %41, align 4
  %43 = call zeroext i1 @s2n_result_is_ok(i32 %42)
  br i1 %43, label %46, label %44

44:                                               ; preds = %30
  %45 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  store i32 -1, ptr %45, align 4, !tbaa !9
  store i32 1, ptr %9, align 4
  br label %52

46:                                               ; preds = %30
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.s2n_test_pkeys, ptr %49, i32 0, i32 2
  store i8 1, ptr %50, align 8, !tbaa !23
  %51 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  store i32 0, ptr %51, align 4, !tbaa !9
  store i32 1, ptr %9, align 4
  br label %52

52:                                               ; preds = %48, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %53

53:                                               ; preds = %52, %18
  %54 = call i32 @s2n_cert_chain_and_key_ptr_free(ptr noundef %8)
  %55 = getelementptr inbounds %struct.s2n_result, ptr %12, i32 0, i32 0
  store i32 %54, ptr %55, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %56 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  %57 = load i32, ptr %56, align 4
  ret i32 %57
}

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

declare i32 @s2n_cert_chain_and_key_ptr_free(ptr noundef) #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @s2n_result_is_ok(i32) #3

declare i32 @s2n_asn1der_to_public_key_and_type(ptr noundef, 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

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, !11, i64 0}
!10 = !{!"", !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 8}
!13 = !{!"s2n_cert_chain_and_key", !6, i64 0, !6, i64 8, !14, i64 16, !14, i64 40, !6, i64 64, !6, i64 72, !6, i64 80}
!14 = !{!"s2n_blob", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16}
!15 = !{!16, !6, i64 48}
!16 = !{!"s2n_test_pkeys", !17, i64 0, !6, i64 48, !18, i64 56}
!17 = !{!"s2n_pkey", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!18 = !{!"_Bool", !7, i64 0}
!19 = !{!11, !11, i64 0}
!20 = !{!13, !6, i64 0}
!21 = !{!22, !6, i64 8}
!22 = !{!"s2n_cert_chain", !11, i64 0, !6, i64 8}
!23 = !{!16, !18, i64 56}


; 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"

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @s2n_test_pkeys_init(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  store ptr null, ptr %4, align 8, !tbaa !5
  %6 = call i32 @s2n_test_cert_chain_and_key_new(ptr noundef nonnull %4, ptr noundef %1, ptr noundef %2) #4
  %7 = icmp sgt i32 %6, -1
  br i1 %7, label %8, label %22

8:                                                ; preds = %3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %0, i64 48
  store ptr %11, ptr %12, align 8, !tbaa !13
  store ptr null, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #4
  store i32 0, ptr %5, align 4, !tbaa !17
  %13 = load ptr, ptr %9, align 8, !tbaa !18
  %14 = getelementptr inbounds i8, ptr %13, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !19
  %16 = getelementptr inbounds i8, ptr %15, i64 80
  %17 = call i32 @s2n_asn1der_to_public_key_and_type(ptr noundef %0, ptr noundef nonnull %5, ptr noundef nonnull %16) #4
  %18 = call zeroext i1 @s2n_result_is_ok(i32 %17)
  br i1 %18, label %19, label %21

19:                                               ; preds = %8
  %20 = getelementptr inbounds i8, ptr %0, i64 56
  store i8 1, ptr %20, align 8, !tbaa !21
  br label %21

21:                                               ; preds = %8, %19
  %.sroa.06.0 = phi i32 [ 0, %19 ], [ -1, %8 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #4
  br label %22

22:                                               ; preds = %3, %21
  %.sroa.06.1 = phi i32 [ %.sroa.06.0, %21 ], [ -1, %3 ]
  %23 = call i32 @s2n_cert_chain_and_key_ptr_free(ptr noundef nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  ret i32 %.sroa.06.1
}

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

declare i32 @s2n_cert_chain_and_key_ptr_free(ptr noundef) local_unnamed_addr #2

declare i32 @s2n_test_cert_chain_and_key_new(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @s2n_result_is_ok(i32) local_unnamed_addr #3

declare i32 @s2n_asn1der_to_public_key_and_type(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress 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 = { mustprogress 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, !6, i64 8}
!10 = !{!"s2n_cert_chain_and_key", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 40, !6, i64 64, !6, i64 72, !6, i64 80}
!11 = !{!"s2n_blob", !6, i64 0, !12, i64 8, !12, i64 12, !12, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 48}
!14 = !{!"s2n_test_pkeys", !15, i64 0, !6, i64 48, !16, i64 56}
!15 = !{!"s2n_pkey", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!16 = !{!"_Bool", !7, i64 0}
!17 = !{!12, !12, i64 0}
!18 = !{!10, !6, i64 0}
!19 = !{!20, !6, i64 8}
!20 = !{!"s2n_cert_chain", !12, i64 0, !6, i64 8}
!21 = !{!14, !16, i64 56}


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