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

; 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_cert_validation_info = type { i8, [3 x i8] }
%struct.s2n_x509_validator = type { ptr, ptr, i8, i8, i16, ptr, i32, ptr, %struct.s2n_cert_validation_info, i8 }
%struct.s2n_x509_trust_store = type { ptr, i8 }

@_s2n_debug_info = external thread_local global %struct.s2n_debug_info, align 8
@s2n_errno = external thread_local global i32, align 4
@.str.7 = external hidden unnamed_addr constant [95 x i8], align 1
@.str.8 = 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

declare ptr @OPENSSL_sk_new_null() #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_x509_validator_init(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2) #4 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca %struct.s2n_cert_validation_info, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i8 %2, ptr %7, align 1, !tbaa !9
  br label %9

9:                                                ; preds = %3
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %43, label %12

12:                                               ; preds = %9
  br label %13

13:                                               ; preds = %12
  br label %14

14:                                               ; preds = %13
  %15 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %16 = getelementptr inbounds %struct.s2n_debug_info, ptr %15, i32 0, i32 0
  store ptr @.str.7, ptr %16, align 8, !tbaa !10
  %17 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %18 = getelementptr inbounds %struct.s2n_debug_info, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !10
  %20 = getelementptr inbounds i8, ptr %19, i64 21
  %21 = call ptr @strrchr(ptr noundef %20, i32 noundef 47) #5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %30

23:                                               ; preds = %14
  %24 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %25 = getelementptr inbounds %struct.s2n_debug_info, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !10
  %27 = getelementptr inbounds i8, ptr %26, i64 21
  %28 = call ptr @strrchr(ptr noundef %27, i32 noundef 47) #5
  %29 = getelementptr inbounds i8, ptr %28, i64 1
  br label %35

30:                                               ; preds = %14
  %31 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %32 = getelementptr inbounds %struct.s2n_debug_info, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !10
  %34 = getelementptr inbounds i8, ptr %33, i64 21
  br label %35

35:                                               ; preds = %30, %23
  %36 = phi ptr [ %29, %23 ], [ %34, %30 ]
  %37 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %38 = getelementptr inbounds %struct.s2n_debug_info, ptr %37, i32 0, i32 1
  store ptr %36, ptr %38, align 8, !tbaa !12
  %39 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %39, align 4, !tbaa !13
  %40 = call i32 @s2n_calculate_stacktrace()
  br label %41

41:                                               ; preds = %35
  store i32 -1, ptr %4, align 4
  br label %123

42:                                               ; No predecessors!
  br label %43

43:                                               ; preds = %42, %9
  br label %44

44:                                               ; preds = %43
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.s2n_x509_validator, ptr %46, i32 0, i32 0
  store ptr %45, ptr %47, align 8, !tbaa !15
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.s2n_x509_validator, ptr %48, i32 0, i32 2
  store i8 0, ptr %49, align 8, !tbaa !20
  %50 = load i8, ptr %7, align 1, !tbaa !9
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.s2n_x509_validator, ptr %51, i32 0, i32 3
  store i8 %50, ptr %52, align 1, !tbaa !21
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.s2n_x509_validator, ptr %53, i32 0, i32 4
  store i16 7, ptr %54, align 2, !tbaa !22
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.s2n_x509_validator, ptr %55, i32 0, i32 1
  store ptr null, ptr %56, align 8, !tbaa !23
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.s2n_x509_validator, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !15
  %60 = getelementptr inbounds %struct.s2n_x509_trust_store, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !24
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %105

63:                                               ; preds = %44
  %64 = call ptr @X509_STORE_CTX_new()
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.s2n_x509_validator, ptr %65, i32 0, i32 1
  store ptr %64, ptr %66, align 8, !tbaa !23
  br label %67

67:                                               ; preds = %63
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.s2n_x509_validator, ptr %68, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !23
  %71 = icmp ne ptr %70, null
  br i1 %71, label %103, label %72

72:                                               ; preds = %67
  br label %73

73:                                               ; preds = %72
  br label %74

74:                                               ; preds = %73
  %75 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %76 = getelementptr inbounds %struct.s2n_debug_info, ptr %75, i32 0, i32 0
  store ptr @.str.8, ptr %76, align 8, !tbaa !10
  %77 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %78 = getelementptr inbounds %struct.s2n_debug_info, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8, !tbaa !10
  %80 = getelementptr inbounds i8, ptr %79, i64 21
  %81 = call ptr @strrchr(ptr noundef %80, i32 noundef 47) #5
  %82 = icmp ne ptr %81, null
  br i1 %82, label %83, label %90

83:                                               ; preds = %74
  %84 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %85 = getelementptr inbounds %struct.s2n_debug_info, ptr %84, i32 0, i32 0
  %86 = load ptr, ptr %85, align 8, !tbaa !10
  %87 = getelementptr inbounds i8, ptr %86, i64 21
  %88 = call ptr @strrchr(ptr noundef %87, i32 noundef 47) #5
  %89 = getelementptr inbounds i8, ptr %88, i64 1
  br label %95

90:                                               ; preds = %74
  %91 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %92 = getelementptr inbounds %struct.s2n_debug_info, ptr %91, i32 0, i32 0
  %93 = load ptr, ptr %92, align 8, !tbaa !10
  %94 = getelementptr inbounds i8, ptr %93, i64 21
  br label %95

95:                                               ; preds = %90, %83
  %96 = phi ptr [ %89, %83 ], [ %94, %90 ]
  %97 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %98 = getelementptr inbounds %struct.s2n_debug_info, ptr %97, i32 0, i32 1
  store ptr %96, ptr %98, align 8, !tbaa !12
  %99 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %99, align 4, !tbaa !13
  %100 = call i32 @s2n_calculate_stacktrace()
  br label %101

101:                                              ; preds = %95
  store i32 -1, ptr %4, align 4
  br label %123

102:                                              ; No predecessors!
  br label %103

103:                                              ; preds = %102, %67
  br label %104

104:                                              ; preds = %103
  br label %105

105:                                              ; preds = %104, %44
  %106 = call ptr @OPENSSL_sk_new_null()
  %107 = load ptr, ptr %5, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.s2n_x509_validator, ptr %107, i32 0, i32 5
  store ptr %106, ptr %108, align 8, !tbaa !26
  %109 = load ptr, ptr %5, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.s2n_x509_validator, ptr %109, i32 0, i32 6
  store i32 1, ptr %110, align 8, !tbaa !27
  %111 = load ptr, ptr %5, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.s2n_x509_validator, ptr %111, i32 0, i32 7
  store ptr null, ptr %112, align 8, !tbaa !28
  %113 = load ptr, ptr %5, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.s2n_x509_validator, ptr %113, i32 0, i32 8
  %115 = load i8, ptr %8, align 4
  %116 = and i8 %115, -2
  %117 = or i8 %116, 0
  store i8 %117, ptr %8, align 4
  %118 = load i8, ptr %8, align 4
  %119 = and i8 %118, -3
  %120 = or i8 %119, 0
  store i8 %120, ptr %8, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %114, ptr align 4 %8, i64 4, i1 false), !tbaa.struct !29
  %121 = load ptr, ptr %5, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.s2n_x509_validator, ptr %121, i32 0, i32 9
  store i8 0, ptr %122, align 4, !tbaa !30
  store i32 0, ptr %4, align 4
  br label %123

123:                                              ; preds = %105, %101, %41
  %124 = load i32, ptr %4, align 4
  ret i32 %124
}

declare ptr @X509_STORE_CTX_new() #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 0}
!11 = !{!"s2n_debug_info", !6, i64 0, !6, i64 8}
!12 = !{!11, !6, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"s2n_x509_validator", !6, i64 0, !6, i64 8, !7, i64 16, !7, i64 17, !17, i64 18, !6, i64 24, !14, i64 32, !6, i64 40, !18, i64 48, !19, i64 52}
!17 = !{!"short", !7, i64 0}
!18 = !{!"s2n_cert_validation_info", !14, i64 0, !14, i64 0}
!19 = !{!"_Bool", !7, i64 0}
!20 = !{!16, !7, i64 16}
!21 = !{!16, !7, i64 17}
!22 = !{!16, !17, i64 18}
!23 = !{!16, !6, i64 8}
!24 = !{!25, !6, i64 0}
!25 = !{!"s2n_x509_trust_store", !6, i64 0, !14, i64 8}
!26 = !{!16, !6, i64 24}
!27 = !{!16, !14, i64 32}
!28 = !{!16, !6, i64 40}
!29 = !{i64 0, i64 1, !9}
!30 = !{!16, !19, i64 52}


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

@_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.7 = external hidden unnamed_addr constant [95 x i8], align 1
@.str.8 = 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

declare ptr @OPENSSL_sk_new_null() local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @s2n_x509_validator_init(ptr nocapture noundef writeonly %0, ptr noundef %1, i8 noundef zeroext %2) local_unnamed_addr #3 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %4, label %12

4:                                                ; preds = %3
  %5 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  store ptr @.str.7, ptr %5, align 8, !tbaa !5
  %6 = tail call ptr @strrchr(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @.str.7, i64 21), i32 noundef 47) #4
  %.not20 = icmp eq ptr %6, null
  %7 = getelementptr inbounds i8, ptr %6, i64 1
  %8 = select i1 %.not20, ptr getelementptr inbounds (i8, ptr @.str.7, i64 21), ptr %7
  %9 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr %8, ptr %9, align 8, !tbaa !10
  %10 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %10, align 4, !tbaa !11
  %11 = tail call i32 @s2n_calculate_stacktrace() #5
  br label %35

12:                                               ; preds = %3
  store ptr %1, ptr %0, align 8, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  store i8 0, ptr %13, align 8, !tbaa !18
  %14 = getelementptr inbounds i8, ptr %0, i64 17
  store i8 %2, ptr %14, align 1, !tbaa !19
  %15 = getelementptr inbounds i8, ptr %0, i64 18
  store i16 7, ptr %15, align 2, !tbaa !20
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr null, ptr %16, align 8, !tbaa !21
  %17 = load ptr, ptr %1, align 8, !tbaa !22
  %.not21 = icmp eq ptr %17, null
  br i1 %.not21, label %28, label %18

18:                                               ; preds = %12
  %19 = tail call ptr @X509_STORE_CTX_new() #5
  store ptr %19, ptr %16, align 8, !tbaa !21
  %.not22 = icmp eq ptr %19, null
  br i1 %.not22, label %20, label %28

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

28:                                               ; preds = %18, %12
  %29 = tail call ptr @OPENSSL_sk_new_null() #5
  %30 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %29, ptr %30, align 8, !tbaa !24
  %31 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 1, ptr %31, align 8, !tbaa !25
  %32 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr null, ptr %32, align 8, !tbaa !26
  %33 = getelementptr inbounds i8, ptr %0, i64 48
  store i8 0, ptr %33, align 8, !tbaa !27
  %34 = getelementptr inbounds i8, ptr %0, i64 52
  store i8 0, ptr %34, align 4, !tbaa !28
  br label %35

35:                                               ; preds = %28, %20, %4
  %.0 = phi i32 [ 0, %28 ], [ -1, %20 ], [ -1, %4 ]
  ret i32 %.0
}

declare ptr @X509_STORE_CTX_new() 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 = { 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 willreturn memory(read) }
attributes #5 = { 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 = !{!"s2n_debug_info", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!14, !7, i64 0}
!14 = !{!"s2n_x509_validator", !7, i64 0, !7, i64 8, !8, i64 16, !8, i64 17, !15, i64 18, !7, i64 24, !12, i64 32, !7, i64 40, !16, i64 48, !17, i64 52}
!15 = !{!"short", !8, i64 0}
!16 = !{!"s2n_cert_validation_info", !12, i64 0, !12, i64 0}
!17 = !{!"_Bool", !8, i64 0}
!18 = !{!14, !8, i64 16}
!19 = !{!14, !8, i64 17}
!20 = !{!14, !15, i64 18}
!21 = !{!14, !7, i64 8}
!22 = !{!23, !7, i64 0}
!23 = !{!"s2n_x509_trust_store", !7, i64 0, !12, i64 8}
!24 = !{!14, !7, i64 24}
!25 = !{!14, !12, i64 32}
!26 = !{!14, !7, i64 40}
!27 = !{!8, !8, i64 0}
!28 = !{!14, !17, i64 52}


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