; LLVM IR from openssl/openssl :: fuzz (smime)

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

; Function Attrs: nounwind uwtable
define dso_local i32 @FuzzerTestOneInput(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = load i64, ptr %4, align 8, !tbaa !9
  %12 = trunc i64 %11 to i32
  %13 = call ptr @BIO_new_mem_buf(ptr noundef %10, i32 noundef %12)
  store ptr %13, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call ptr @SMIME_read_PKCS7(ptr noundef %14, ptr noundef null)
  store ptr %15, ptr %6, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %47

18:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = call ptr @PKCS7_get_signer_info(ptr noundef %19)
  store ptr %20, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %21

21:                                               ; preds = %42, %18
  %22 = load i32, ptr %8, align 4, !tbaa !11
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = call ptr @ossl_check_const_PKCS7_SIGNER_INFO_sk_type(ptr noundef %23)
  %25 = call i32 @OPENSSL_sk_num(ptr noundef %24)
  %26 = icmp slt i32 %22, %25
  br i1 %26, label %27, label %45

27:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = call ptr @ossl_check_const_PKCS7_SIGNER_INFO_sk_type(ptr noundef %29)
  %31 = load i32, ptr %8, align 4, !tbaa !11
  %32 = call ptr @OPENSSL_sk_value(ptr noundef %30, i32 noundef %31)
  %33 = call ptr @PKCS7_cert_from_signer_info(ptr noundef %28, ptr noundef %32)
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = call ptr @ossl_check_const_PKCS7_SIGNER_INFO_sk_type(ptr noundef %34)
  %36 = load i32, ptr %8, align 4, !tbaa !11
  %37 = call ptr @OPENSSL_sk_value(ptr noundef %35, i32 noundef %36)
  %38 = call ptr @PKCS7_get_smimecap(ptr noundef %37)
  store ptr %38, ptr %9, align 8, !tbaa !5
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = call ptr @ossl_check_X509_ALGOR_sk_type(ptr noundef %39)
  %41 = call ptr @ossl_check_X509_ALGOR_freefunc_type(ptr noundef @X509_ALGOR_free)
  call void @OPENSSL_sk_pop_free(ptr noundef %40, ptr noundef %41)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %42

42:                                               ; preds = %27
  %43 = load i32, ptr %8, align 4, !tbaa !11
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %8, align 4, !tbaa !11
  br label %21, !llvm.loop !13

45:                                               ; preds = %21
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  call void @PKCS7_free(ptr noundef %46)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %47

47:                                               ; preds = %45, %2
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = call i32 @BIO_free(ptr noundef %48)
  call void @ERR_clear_error()
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret i32 0
}

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

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

declare ptr @SMIME_read_PKCS7(ptr noundef, ptr noundef) #2

declare ptr @PKCS7_get_signer_info(ptr noundef) #2

declare i32 @OPENSSL_sk_num(ptr noundef) #2

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

declare ptr @PKCS7_cert_from_signer_info(ptr noundef, ptr noundef) #2

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

declare ptr @PKCS7_get_smimecap(ptr noundef) #2

declare void @OPENSSL_sk_pop_free(ptr noundef, ptr noundef) #2

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

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

declare void @X509_ALGOR_free(ptr noundef) #2

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

declare void @PKCS7_free(ptr noundef) #2

declare i32 @BIO_free(ptr noundef) #2

declare void @ERR_clear_error() #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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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 noundef i32 @FuzzerTestOneInput(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = trunc i64 %1 to i32
  %4 = tail call ptr @BIO_new_mem_buf(ptr noundef %0, i32 noundef %3) #3
  %5 = tail call ptr @SMIME_read_PKCS7(ptr noundef %4, ptr noundef null) #3
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %23, label %6

6:                                                ; preds = %2
  %7 = tail call ptr @PKCS7_get_signer_info(ptr noundef nonnull %5) #3
  %8 = tail call ptr @ossl_check_const_PKCS7_SIGNER_INFO_sk_type(ptr noundef %7)
  %9 = tail call i32 @OPENSSL_sk_num(ptr noundef %8) #3
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6, %.lr.ph
  %.016 = phi i32 [ %19, %.lr.ph ], [ 0, %6 ]
  %11 = tail call ptr @ossl_check_const_PKCS7_SIGNER_INFO_sk_type(ptr noundef %7)
  %12 = tail call ptr @OPENSSL_sk_value(ptr noundef %11, i32 noundef %.016) #3
  %13 = tail call ptr @PKCS7_cert_from_signer_info(ptr noundef nonnull %5, ptr noundef %12) #3
  %14 = tail call ptr @ossl_check_const_PKCS7_SIGNER_INFO_sk_type(ptr noundef %7)
  %15 = tail call ptr @OPENSSL_sk_value(ptr noundef %14, i32 noundef %.016) #3
  %16 = tail call ptr @PKCS7_get_smimecap(ptr noundef %15) #3
  %17 = tail call ptr @ossl_check_X509_ALGOR_sk_type(ptr noundef %16)
  %18 = tail call ptr @ossl_check_X509_ALGOR_freefunc_type(ptr noundef nonnull @X509_ALGOR_free)
  tail call void @OPENSSL_sk_pop_free(ptr noundef %17, ptr noundef %18) #3
  %19 = add nuw nsw i32 %.016, 1
  %20 = tail call ptr @ossl_check_const_PKCS7_SIGNER_INFO_sk_type(ptr noundef %7)
  %21 = tail call i32 @OPENSSL_sk_num(ptr noundef %20) #3
  %22 = icmp slt i32 %19, %21
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %6
  tail call void @PKCS7_free(ptr noundef nonnull %5) #3
  br label %23

23:                                               ; preds = %._crit_edge, %2
  %24 = tail call i32 @BIO_free(ptr noundef %4) #3
  tail call void @ERR_clear_error() #3
  ret i32 0
}

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

declare ptr @SMIME_read_PKCS7(ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @PKCS7_get_signer_info(ptr noundef) local_unnamed_addr #1

declare i32 @OPENSSL_sk_num(ptr noundef) local_unnamed_addr #1

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

declare ptr @PKCS7_cert_from_signer_info(ptr noundef, ptr noundef) local_unnamed_addr #1

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

declare ptr @PKCS7_get_smimecap(ptr noundef) local_unnamed_addr #1

declare void @OPENSSL_sk_pop_free(ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

declare void @X509_ALGOR_free(ptr noundef) #1

declare void @PKCS7_free(ptr noundef) local_unnamed_addr #1

declare i32 @BIO_free(ptr noundef) local_unnamed_addr #1

declare void @ERR_clear_error() 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass