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

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_x509_validator_wipe(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca %struct.s2n_result, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.s2n_x509_validator, ptr %5, i32 0, i32 1
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %15

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.s2n_x509_validator, ptr %10, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  call void @X509_STORE_CTX_free(ptr noundef %12)
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.s2n_x509_validator, ptr %13, i32 0, i32 1
  store ptr null, ptr %14, align 8, !tbaa !9
  br label %15

15:                                               ; preds = %9, %1
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.s2n_x509_validator, ptr %16, i32 0, i32 5
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  call void @wipe_cert_chain(ptr noundef %18)
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.s2n_x509_validator, ptr %19, i32 0, i32 5
  store ptr null, ptr %20, align 8, !tbaa !15
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.s2n_x509_validator, ptr %21, i32 0, i32 0
  store ptr null, ptr %22, align 8, !tbaa !16
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.s2n_x509_validator, ptr %23, i32 0, i32 2
  store i8 0, ptr %24, align 8, !tbaa !17
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.s2n_x509_validator, ptr %25, i32 0, i32 6
  store i32 0, ptr %26, align 8, !tbaa !18
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.s2n_x509_validator, ptr %27, i32 0, i32 4
  store i16 0, ptr %28, align 2, !tbaa !19
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.s2n_x509_validator, ptr %29, i32 0, i32 7
  %31 = load ptr, ptr %30, align 8, !tbaa !20
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %48

33:                                               ; preds = %15
  br label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.s2n_x509_validator, ptr %35, i32 0, i32 7
  %37 = load ptr, ptr %36, align 8, !tbaa !20
  %38 = call i32 @s2n_array_free(ptr noundef %37)
  %39 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  store i32 %38, ptr %39, align 4
  %40 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  %41 = load i32, ptr %40, align 4
  %42 = call zeroext i1 @s2n_result_is_ok(i32 %41)
  br i1 %42, label %44, label %43

43:                                               ; preds = %34
  store i32 -1, ptr %2, align 4
  br label %49

44:                                               ; preds = %34
  br label %45

45:                                               ; preds = %44
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.s2n_x509_validator, ptr %46, i32 0, i32 7
  store ptr null, ptr %47, align 8, !tbaa !20
  br label %48

48:                                               ; preds = %45, %15
  store i32 0, ptr %2, align 4
  br label %49

49:                                               ; preds = %48, %43
  %50 = load i32, ptr %2, align 4
  ret i32 %50
}

declare void @X509_STORE_CTX_free(ptr noundef) #1

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

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

declare i32 @s2n_array_free(ptr noundef) #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 = { "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" }

!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_x509_validator", !6, i64 0, !6, i64 8, !7, i64 16, !7, i64 17, !11, i64 18, !6, i64 24, !12, i64 32, !6, i64 40, !13, i64 48, !14, i64 52}
!11 = !{!"short", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"s2n_cert_validation_info", !12, i64 0, !12, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!10, !6, i64 24}
!16 = !{!10, !6, i64 0}
!17 = !{!10, !7, i64 16}
!18 = !{!10, !12, i64 32}
!19 = !{!10, !11, i64 18}
!20 = !{!10, !6, i64 40}


; 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_x509_validator_wipe(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %5, label %4

4:                                                ; preds = %1
  tail call void @X509_STORE_CTX_free(ptr noundef nonnull %3) #3
  store ptr null, ptr %2, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %4, %1
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load ptr, ptr %6, align 8, !tbaa !14
  tail call void @wipe_cert_chain(ptr noundef %7)
  store ptr null, ptr %6, align 8, !tbaa !14
  store ptr null, ptr %0, align 8, !tbaa !15
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  store i8 0, ptr %8, align 8, !tbaa !16
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 0, ptr %9, align 8, !tbaa !17
  %10 = getelementptr inbounds i8, ptr %0, i64 18
  store i16 0, ptr %10, align 2, !tbaa !18
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  %12 = load ptr, ptr %11, align 8, !tbaa !19
  %.not14 = icmp eq ptr %12, null
  br i1 %.not14, label %17, label %13

13:                                               ; preds = %5
  %14 = tail call i32 @s2n_array_free(ptr noundef nonnull %12) #3
  %15 = tail call zeroext i1 @s2n_result_is_ok(i32 %14)
  br i1 %15, label %16, label %17

16:                                               ; preds = %13
  store ptr null, ptr %11, align 8, !tbaa !19
  br label %17

17:                                               ; preds = %5, %16, %13
  %.0 = phi i32 [ -1, %13 ], [ 0, %16 ], [ 0, %5 ]
  ret i32 %.0
}

declare void @X509_STORE_CTX_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @wipe_cert_chain(ptr noundef) local_unnamed_addr #2

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

declare i32 @s2n_array_free(ptr noundef) local_unnamed_addr #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 = { "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 8}
!6 = !{!"s2n_x509_validator", !7, i64 0, !7, i64 8, !8, i64 16, !8, i64 17, !10, i64 18, !7, i64 24, !11, i64 32, !7, i64 40, !12, i64 48, !13, i64 52}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"s2n_cert_validation_info", !11, i64 0, !11, i64 0}
!13 = !{!"_Bool", !8, i64 0}
!14 = !{!6, !7, i64 24}
!15 = !{!6, !7, i64 0}
!16 = !{!6, !8, i64 16}
!17 = !{!6, !11, i64 32}
!18 = !{!6, !10, i64 18}
!19 = !{!6, !7, i64 40}


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