; LLVM IR from aws/s2n-tls :: crypto (s2n_certificate)

; 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_debug_info = type { ptr, ptr }
%struct.s2n_blob = type { ptr, i32, i32, i8 }
%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_stuffer = type { %struct.s2n_blob, i32, i32, i32, i8 }

@_s2n_debug_info = external thread_local global %struct.s2n_debug_info, align 8
@s2n_errno = external thread_local global i32, align 4
@.str.3 = external hidden unnamed_addr constant [95 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strrchr(ptr noundef, i32 noundef) #1

declare i32 @s2n_calculate_stacktrace() #2

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

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

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_cert_chain_and_key_set_private_key_from_stuffer(ptr noundef %0, ptr noundef %1, ptr noundef %2) #6 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %struct.s2n_blob, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = 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 24, ptr %8) #7
  call void @llvm.memset.p0.i64(ptr align 8 %8, i8 0, i64 24, i1 false)
  br label %12

12:                                               ; preds = %3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.s2n_cert_chain_and_key, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = call i32 @s2n_pkey_zero_init(ptr noundef %15)
  %17 = icmp sgt i32 %16, -1
  br i1 %17, label %19, label %18

18:                                               ; preds = %12
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %99

19:                                               ; preds = %12
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  store i32 0, ptr %10, align 4, !tbaa !13
  br label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = call i32 @s2n_stuffer_private_key_from_pem(ptr noundef %23, ptr noundef %24, ptr noundef %10)
  %26 = icmp sgt i32 %25, -1
  br i1 %26, label %28, label %27

27:                                               ; preds = %22
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %98

28:                                               ; preds = %22
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.s2n_stuffer, ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 4, !tbaa !14
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.s2n_stuffer, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 8, !tbaa !16
  %37 = sub i32 %33, %36
  %38 = getelementptr inbounds %struct.s2n_blob, ptr %8, i32 0, i32 1
  store i32 %37, ptr %38, align 8, !tbaa !17
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.s2n_blob, ptr %8, i32 0, i32 1
  %41 = load i32, ptr %40, align 8, !tbaa !17
  %42 = call ptr @s2n_stuffer_raw_read(ptr noundef %39, i32 noundef %41)
  %43 = getelementptr inbounds %struct.s2n_blob, ptr %8, i32 0, i32 0
  store ptr %42, ptr %43, align 8, !tbaa !18
  br label %44

44:                                               ; preds = %30
  %45 = getelementptr inbounds %struct.s2n_blob, ptr %8, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !18
  %47 = icmp ne ptr %46, null
  br i1 %47, label %81, label %48

48:                                               ; preds = %44
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  %51 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %52 = getelementptr inbounds %struct.s2n_debug_info, ptr %51, i32 0, i32 0
  store ptr @.str.3, ptr %52, align 8, !tbaa !19
  %53 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %54 = getelementptr inbounds %struct.s2n_debug_info, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !19
  %56 = getelementptr inbounds i8, ptr %55, i64 21
  %57 = call ptr @strrchr(ptr noundef %56, i32 noundef 47) #8
  %58 = icmp ne ptr %57, null
  br i1 %58, label %59, label %66

59:                                               ; preds = %50
  %60 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %61 = getelementptr inbounds %struct.s2n_debug_info, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !19
  %63 = getelementptr inbounds i8, ptr %62, i64 21
  %64 = call ptr @strrchr(ptr noundef %63, i32 noundef 47) #8
  %65 = getelementptr inbounds i8, ptr %64, i64 1
  br label %71

66:                                               ; preds = %50
  %67 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %68 = getelementptr inbounds %struct.s2n_debug_info, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !19
  %70 = getelementptr inbounds i8, ptr %69, i64 21
  br label %71

71:                                               ; preds = %66, %59
  %72 = phi ptr [ %65, %59 ], [ %70, %66 ]
  %73 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %74 = getelementptr inbounds %struct.s2n_debug_info, ptr %73, i32 0, i32 1
  store ptr %72, ptr %74, align 8, !tbaa !21
  %75 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %75, align 4, !tbaa !13
  %76 = call i32 @s2n_calculate_stacktrace()
  br label %77

77:                                               ; preds = %71
  br label %78

78:                                               ; preds = %77
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %98

79:                                               ; No predecessors!
  br label %80

80:                                               ; preds = %79
  br label %81

81:                                               ; preds = %80, %44
  br label %82

82:                                               ; preds = %81
  br label %83

83:                                               ; preds = %82
  br label %84

84:                                               ; preds = %83
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.s2n_cert_chain_and_key, ptr %85, i32 0, i32 1
  %87 = load ptr, ptr %86, align 8, !tbaa !9
  %88 = load i32, ptr %10, align 4, !tbaa !13
  %89 = call i32 @s2n_asn1der_to_private_key(ptr noundef %87, ptr noundef %8, i32 noundef %88)
  %90 = getelementptr inbounds %struct.s2n_result, ptr %11, i32 0, i32 0
  store i32 %89, ptr %90, align 4
  %91 = getelementptr inbounds %struct.s2n_result, ptr %11, i32 0, i32 0
  %92 = load i32, ptr %91, align 4
  %93 = call zeroext i1 @s2n_result_is_ok(i32 %92)
  br i1 %93, label %95, label %94

94:                                               ; preds = %84
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %98

95:                                               ; preds = %84
  br label %96

96:                                               ; preds = %95
  br label %97

97:                                               ; preds = %96
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %98

98:                                               ; preds = %97, %94, %78, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  br label %99

99:                                               ; preds = %98, %18
  call void @llvm.lifetime.end.p0(i64 24, ptr %8) #7
  %100 = load i32, ptr %4, align 4
  ret i32 %100
}

declare i32 @s2n_pkey_zero_init(ptr noundef) #2

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

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

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

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { 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 #7 = { nounwind }
attributes #8 = { 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, !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 = !{!12, !12, i64 0}
!14 = !{!15, !12, i64 28}
!15 = !{!"s2n_stuffer", !11, i64 0, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 36, !12, i64 36}
!16 = !{!15, !12, i64 24}
!17 = !{!11, !12, i64 8}
!18 = !{!11, !6, i64 0}
!19 = !{!20, !6, i64 0}
!20 = !{!"s2n_debug_info", !6, i64 0, !6, i64 8}
!21 = !{!20, !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"

%struct.s2n_debug_info = type { ptr, ptr }
%struct.s2n_blob = type { ptr, i32, i32, i8 }

@_s2n_debug_info = external thread_local local_unnamed_addr global %struct.s2n_debug_info, align 8
@s2n_errno = external thread_local local_unnamed_addr global i32, align 4
@.str.3 = external hidden unnamed_addr constant [95 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0

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

declare i32 @s2n_calculate_stacktrace() local_unnamed_addr #2

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @s2n_cert_chain_and_key_set_private_key_from_stuffer(ptr nocapture noundef readonly %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #6 {
  %4 = alloca %struct.s2n_blob, align 8
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #7
  %6 = getelementptr inbounds i8, ptr %4, i64 8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %6, i8 0, i64 16, i1 false)
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = tail call i32 @s2n_pkey_zero_init(ptr noundef %8) #7
  %10 = icmp sgt i32 %9, -1
  br i1 %10, label %11, label %36

11:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #7
  store i32 0, ptr %5, align 4, !tbaa !12
  %12 = call i32 @s2n_stuffer_private_key_from_pem(ptr noundef %1, ptr noundef %2, ptr noundef nonnull %5) #7
  %13 = icmp sgt i32 %12, -1
  br i1 %13, label %14, label %35

14:                                               ; preds = %11
  %15 = getelementptr inbounds i8, ptr %2, i64 28
  %16 = load i32, ptr %15, align 4, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %2, i64 24
  %18 = load i32, ptr %17, align 8, !tbaa !15
  %19 = sub i32 %16, %18
  %20 = getelementptr inbounds i8, ptr %4, i64 8
  store i32 %19, ptr %20, align 8, !tbaa !16
  %21 = call ptr @s2n_stuffer_raw_read(ptr noundef %2, i32 noundef %19) #7
  store ptr %21, ptr %4, align 8, !tbaa !17
  %.not = icmp eq ptr %21, null
  br i1 %.not, label %22, label %30

22:                                               ; preds = %14
  %23 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  store ptr @.str.3, ptr %23, align 8, !tbaa !18
  %24 = call ptr @strrchr(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @.str.3, i64 21), i32 noundef 47) #8
  %.not8 = icmp eq ptr %24, null
  %25 = getelementptr inbounds i8, ptr %24, i64 1
  %26 = select i1 %.not8, ptr getelementptr inbounds (i8, ptr @.str.3, i64 21), ptr %25
  %27 = getelementptr inbounds i8, ptr %23, i64 8
  store ptr %26, ptr %27, align 8, !tbaa !20
  %28 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %28, align 4, !tbaa !12
  %29 = call i32 @s2n_calculate_stacktrace() #7
  br label %35

30:                                               ; preds = %14
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = load i32, ptr %5, align 4, !tbaa !12
  %33 = call i32 @s2n_asn1der_to_private_key(ptr noundef %31, ptr noundef nonnull %4, i32 noundef %32) #7
  %34 = call zeroext i1 @s2n_result_is_ok(i32 %33)
  %not. = xor i1 %34, true
  %. = sext i1 %not. to i32
  br label %35

35:                                               ; preds = %30, %11, %22
  %.0 = phi i32 [ -1, %22 ], [ -1, %11 ], [ %., %30 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #7
  br label %36

36:                                               ; preds = %3, %35
  %.1 = phi i32 [ %.0, %35 ], [ -1, %3 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #7
  ret i32 %.1
}

declare i32 @s2n_pkey_zero_init(ptr noundef) local_unnamed_addr #2

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

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { "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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { 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 #7 = { nounwind }
attributes #8 = { 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, !7, i64 8}
!6 = !{!"s2n_cert_chain_and_key", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 40, !7, i64 64, !7, i64 72, !7, i64 80}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"s2n_blob", !7, i64 0, !11, i64 8, !11, i64 12, !11, i64 16}
!11 = !{!"int", !8, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !11, i64 28}
!14 = !{!"s2n_stuffer", !10, i64 0, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 36, !11, i64 36}
!15 = !{!14, !11, i64 24}
!16 = !{!10, !11, i64 8}
!17 = !{!10, !7, i64 0}
!18 = !{!19, !7, i64 0}
!19 = !{!"s2n_debug_info", !7, i64 0, !7, i64 8}
!20 = !{!19, !7, i64 8}


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