; LLVM IR from VivyTeam/krypt-ios :: Krypt/Source (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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare i32 @BIO_free(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @get_pkcs7(ptr noundef, ptr noundef) #2

declare ptr @BIO_new(ptr noundef) #1

declare ptr @BIO_s_mem() #1

declare void @PKCS7_free(ptr noundef) #1

declare ptr @str_from_BIO(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @store_with_trusted_certs(ptr noundef, i32 noundef) #2

declare void @X509_STORE_free(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @pkcs7_signature_contains_email(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @smime_verify(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5) #2 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca i64, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i32 %3, ptr %11, align 4, !tbaa !9
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  store ptr null, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = call ptr @get_pkcs7(ptr noundef %23, ptr noundef %14)
  store ptr %24, ptr %15, align 8, !tbaa !5
  %25 = load ptr, ptr %15, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %32, label %27

27:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %28 = call i64 @ERR_get_error()
  store i64 %28, ptr %16, align 8, !tbaa !11
  %29 = load i64, ptr %16, align 8, !tbaa !11
  %30 = trunc i64 %29 to i32
  %31 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 %30, ptr %31, align 4, !tbaa !9
  store i32 0, ptr %7, align 4
  store i32 1, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  br label %91

32:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = load i32, ptr %11, align 4, !tbaa !9
  %35 = call ptr @store_with_trusted_certs(ptr noundef %33, i32 noundef %34)
  store ptr %35, ptr %18, align 8, !tbaa !5
  %36 = load ptr, ptr %18, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %40, label %38

38:                                               ; preds = %32
  %39 = load ptr, ptr %15, align 8, !tbaa !5
  call void @PKCS7_free(ptr noundef %39)
  store i32 0, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %90

40:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  %41 = call ptr @BIO_s_mem()
  %42 = call ptr @BIO_new(ptr noundef %41)
  store ptr %42, ptr %19, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  store i32 0, ptr %20, align 4, !tbaa !9
  %43 = load ptr, ptr %14, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %48

45:                                               ; preds = %40
  %46 = load i32, ptr %20, align 4, !tbaa !9
  %47 = or i32 %46, 64
  store i32 %47, ptr %20, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %45, %40
  %49 = load i32, ptr %20, align 4, !tbaa !9
  %50 = or i32 %49, 8
  store i32 %50, ptr %20, align 4, !tbaa !9
  %51 = load ptr, ptr %15, align 8, !tbaa !5
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = call i32 @pkcs7_signature_contains_email(ptr noundef %51, ptr noundef %52)
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %57, label %55

55:                                               ; preds = %48
  %56 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 218972366, ptr %56, align 4, !tbaa !9
  store i32 0, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %89

57:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #3
  %58 = load ptr, ptr %15, align 8, !tbaa !5
  %59 = load ptr, ptr %18, align 8, !tbaa !5
  %60 = load ptr, ptr %14, align 8, !tbaa !5
  %61 = load ptr, ptr %19, align 8, !tbaa !5
  %62 = load i32, ptr %20, align 4, !tbaa !9
  %63 = call i32 @PKCS7_verify(ptr noundef %58, ptr noundef null, ptr noundef %59, ptr noundef %60, ptr noundef %61, i32 noundef %62)
  store i32 %63, ptr %21, align 4, !tbaa !9
  %64 = load i32, ptr %21, align 4, !tbaa !9
  %65 = icmp eq i32 %64, 0
  br i1 %65, label %66, label %71

66:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #3
  %67 = call i64 @ERR_get_error()
  store i64 %67, ptr %22, align 8, !tbaa !11
  %68 = load i64, ptr %22, align 8, !tbaa !11
  %69 = trunc i64 %68 to i32
  %70 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 %69, ptr %70, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #3
  br label %71

71:                                               ; preds = %66, %57
  %72 = load ptr, ptr %15, align 8, !tbaa !5
  call void @PKCS7_free(ptr noundef %72)
  %73 = load ptr, ptr %18, align 8, !tbaa !5
  call void @X509_STORE_free(ptr noundef %73)
  %74 = load ptr, ptr %14, align 8, !tbaa !5
  %75 = call i32 @BIO_free(ptr noundef %74)
  %76 = load i32, ptr %21, align 4, !tbaa !9
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %78, label %85

78:                                               ; preds = %71
  %79 = load ptr, ptr %12, align 8, !tbaa !5
  %80 = icmp ne ptr %79, null
  br i1 %80, label %81, label %85

81:                                               ; preds = %78
  %82 = load ptr, ptr %19, align 8, !tbaa !5
  %83 = call ptr @str_from_BIO(ptr noundef %82)
  %84 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %83, ptr %84, align 8, !tbaa !5
  br label %85

85:                                               ; preds = %81, %78, %71
  %86 = load ptr, ptr %19, align 8, !tbaa !5
  %87 = call i32 @BIO_free(ptr noundef %86)
  %88 = load i32, ptr %21, align 4, !tbaa !9
  store i32 %88, ptr %7, align 4
  store i32 1, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #3
  br label %89

89:                                               ; preds = %85, %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  br label %90

90:                                               ; preds = %89, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  br label %91

91:                                               ; preds = %90, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  %92 = load i32, ptr %7, align 4
  ret i32 %92
}

declare i64 @ERR_get_error() #1

declare i32 @PKCS7_verify(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare i32 @BIO_free(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @get_pkcs7(ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @BIO_new(ptr noundef) local_unnamed_addr #1

declare ptr @BIO_s_mem() local_unnamed_addr #1

declare void @PKCS7_free(ptr noundef) local_unnamed_addr #1

declare ptr @str_from_BIO(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @store_with_trusted_certs(ptr noundef, i32 noundef) local_unnamed_addr #2

declare void @X509_STORE_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @pkcs7_signature_contains_email(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @smime_verify(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef writeonly %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #2 {
  %7 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #3
  store ptr null, ptr %7, align 8, !tbaa !5
  %8 = call ptr @get_pkcs7(ptr noundef %0, ptr noundef nonnull %7)
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %9, label %12

9:                                                ; preds = %6
  %10 = call i64 @ERR_get_error() #3
  %11 = trunc i64 %10 to i32
  store i32 %11, ptr %5, align 4, !tbaa !9
  br label %37

12:                                               ; preds = %6
  %13 = call ptr @store_with_trusted_certs(ptr noundef %2, i32 noundef %3)
  %.not33 = icmp eq ptr %13, null
  br i1 %.not33, label %14, label %15

14:                                               ; preds = %12
  call void @PKCS7_free(ptr noundef nonnull %8) #3
  br label %37

15:                                               ; preds = %12
  %16 = call ptr @BIO_s_mem() #3
  %17 = call ptr @BIO_new(ptr noundef %16) #3
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = call i32 @pkcs7_signature_contains_email(ptr noundef nonnull %8, ptr noundef %1)
  %.not35 = icmp eq i32 %19, 0
  br i1 %.not35, label %20, label %21

20:                                               ; preds = %15
  store i32 218972366, ptr %5, align 4, !tbaa !9
  br label %37

21:                                               ; preds = %15
  %.not34 = icmp eq ptr %18, null
  %spec.select = select i1 %.not34, i32 8, i32 72
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = call i32 @PKCS7_verify(ptr noundef nonnull %8, ptr noundef null, ptr noundef nonnull %13, ptr noundef %22, ptr noundef %17, i32 noundef %spec.select) #3
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %28

25:                                               ; preds = %21
  %26 = call i64 @ERR_get_error() #3
  %27 = trunc i64 %26 to i32
  store i32 %27, ptr %5, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %25, %21
  call void @PKCS7_free(ptr noundef nonnull %8) #3
  call void @X509_STORE_free(ptr noundef nonnull %13) #3
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = call i32 @BIO_free(ptr noundef %29) #3
  %31 = icmp ne i32 %23, 0
  %32 = icmp ne ptr %4, null
  %or.cond = and i1 %32, %31
  br i1 %or.cond, label %33, label %35

33:                                               ; preds = %28
  %34 = call ptr @str_from_BIO(ptr noundef %17) #3
  store ptr %34, ptr %4, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %33, %28
  %36 = call i32 @BIO_free(ptr noundef %17) #3
  br label %37

37:                                               ; preds = %14, %35, %20, %9
  %.2 = phi i32 [ 0, %9 ], [ 0, %14 ], [ %23, %35 ], [ 0, %20 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #3
  ret i32 %.2
}

declare i64 @ERR_get_error() local_unnamed_addr #1

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !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 = !{!"int", !7, i64 0}


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