; LLVM IR from openanolis/openssl :: demos/cms (cms_sign)

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

@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@stderr = external global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [20 x i8], align 1

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

19:                                               ; preds = %2
  br label %70

20:                                               ; preds = %2
  %21 = load ptr, ptr %8, align 8, !tbaa !9
  %22 = call ptr @PEM_read_bio_X509(ptr noundef %21, ptr noundef null, ptr noundef null, ptr noundef null)
  store ptr %22, ptr %9, align 8, !tbaa !9
  %23 = load ptr, ptr %8, align 8, !tbaa !9
  %24 = call i64 @BIO_ctrl(ptr noundef %23, i32 noundef 1, i64 noundef 0, ptr noundef null)
  %25 = trunc i64 %24 to i32
  %26 = load ptr, ptr %8, align 8, !tbaa !9
  %27 = call ptr @PEM_read_bio_PrivateKey(ptr noundef %26, ptr noundef null, ptr noundef null, ptr noundef null)
  store ptr %27, ptr %10, align 8, !tbaa !9
  %28 = load ptr, ptr %9, align 8, !tbaa !9
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %33

30:                                               ; preds = %20
  %31 = load ptr, ptr %10, align 8, !tbaa !9
  %32 = icmp ne ptr %31, null
  br i1 %32, label %34, label %33

33:                                               ; preds = %30, %20
  br label %70

34:                                               ; preds = %30
  %35 = call ptr @BIO_new_file(ptr noundef @.str.2, ptr noundef @.str.1)
  store ptr %35, ptr %6, align 8, !tbaa !9
  %36 = load ptr, ptr %6, align 8, !tbaa !9
  %37 = icmp ne ptr %36, null
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  br label %70

39:                                               ; preds = %34
  %40 = load ptr, ptr %9, align 8, !tbaa !9
  %41 = load ptr, ptr %10, align 8, !tbaa !9
  %42 = load ptr, ptr %6, align 8, !tbaa !9
  %43 = load i32, ptr %13, align 4, !tbaa !5
  %44 = call ptr @CMS_sign(ptr noundef %40, ptr noundef %41, ptr noundef null, ptr noundef %42, i32 noundef %43)
  store ptr %44, ptr %11, align 8, !tbaa !9
  %45 = load ptr, ptr %11, align 8, !tbaa !9
  %46 = icmp ne ptr %45, null
  br i1 %46, label %48, label %47

47:                                               ; preds = %39
  br label %70

48:                                               ; preds = %39
  %49 = call ptr @BIO_new_file(ptr noundef @.str.3, ptr noundef @.str.4)
  store ptr %49, ptr %7, align 8, !tbaa !9
  %50 = load ptr, ptr %7, align 8, !tbaa !9
  %51 = icmp ne ptr %50, null
  br i1 %51, label %53, label %52

52:                                               ; preds = %48
  br label %70

53:                                               ; preds = %48
  %54 = load i32, ptr %13, align 4, !tbaa !5
  %55 = and i32 %54, 4096
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %61, label %57

57:                                               ; preds = %53
  %58 = load ptr, ptr %6, align 8, !tbaa !9
  %59 = call i64 @BIO_ctrl(ptr noundef %58, i32 noundef 1, i64 noundef 0, ptr noundef null)
  %60 = trunc i64 %59 to i32
  br label %61

61:                                               ; preds = %57, %53
  %62 = load ptr, ptr %7, align 8, !tbaa !9
  %63 = load ptr, ptr %11, align 8, !tbaa !9
  %64 = load ptr, ptr %6, align 8, !tbaa !9
  %65 = load i32, ptr %13, align 4, !tbaa !5
  %66 = call i32 @SMIME_write_CMS(ptr noundef %62, ptr noundef %63, ptr noundef %64, i32 noundef %65)
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %69, label %68

68:                                               ; preds = %61
  br label %70

69:                                               ; preds = %61
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %70

70:                                               ; preds = %69, %68, %52, %47, %38, %33, %19
  %71 = load i32, ptr %12, align 4, !tbaa !5
  %72 = icmp ne i32 %71, 0
  br i1 %72, label %73, label %77

73:                                               ; preds = %70
  %74 = load ptr, ptr @stderr, align 8, !tbaa !9
  %75 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %74, ptr noundef @.str.5) #4
  %76 = load ptr, ptr @stderr, align 8, !tbaa !9
  call void @ERR_print_errors_fp(ptr noundef %76)
  br label %77

77:                                               ; preds = %73, %70
  %78 = load ptr, ptr %11, align 8, !tbaa !9
  call void @CMS_ContentInfo_free(ptr noundef %78)
  %79 = load ptr, ptr %9, align 8, !tbaa !9
  call void @X509_free(ptr noundef %79)
  %80 = load ptr, ptr %10, align 8, !tbaa !9
  call void @EVP_PKEY_free(ptr noundef %80)
  %81 = load ptr, ptr %6, align 8, !tbaa !9
  %82 = call i32 @BIO_free(ptr noundef %81)
  %83 = load ptr, ptr %7, align 8, !tbaa !9
  %84 = call i32 @BIO_free(ptr noundef %83)
  %85 = load ptr, ptr %8, align 8, !tbaa !9
  %86 = call i32 @BIO_free(ptr noundef %85)
  %87 = load i32, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  ret i32 %87
}

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

declare i32 @OPENSSL_init_crypto(i64 noundef, ptr noundef) #2

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

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

declare i64 @BIO_ctrl(ptr noundef, i32 noundef, i64 noundef, ptr noundef) #2

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

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

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

declare void @ERR_print_errors_fp(ptr noundef) #2

declare void @CMS_ContentInfo_free(ptr noundef) #2

declare void @X509_free(ptr noundef) #2

declare void @EVP_PKEY_free(ptr noundef) #2

declare i32 @BIO_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

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 = { nounwind "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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"

@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = tail call i32 @OPENSSL_init_crypto(i64 noundef 12, ptr noundef null) #3
  %4 = tail call i32 @OPENSSL_init_crypto(i64 noundef 2, ptr noundef null) #3
  %5 = tail call ptr @BIO_new_file(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1) #3
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %.thread, label %6

6:                                                ; preds = %2
  %7 = tail call ptr @PEM_read_bio_X509(ptr noundef nonnull %5, ptr noundef null, ptr noundef null, ptr noundef null) #3
  %8 = tail call i64 @BIO_ctrl(ptr noundef nonnull %5, i32 noundef 1, i64 noundef 0, ptr noundef null) #3
  %9 = tail call ptr @PEM_read_bio_PrivateKey(ptr noundef nonnull %5, ptr noundef null, ptr noundef null, ptr noundef null) #3
  %10 = icmp ne ptr %7, null
  %11 = icmp ne ptr %9, null
  %or.cond = select i1 %10, i1 %11, i1 false
  br i1 %or.cond, label %12, label %.thread

12:                                               ; preds = %6
  %13 = tail call ptr @BIO_new_file(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1) #3
  %.not40 = icmp eq ptr %13, null
  br i1 %.not40, label %.thread, label %14

14:                                               ; preds = %12
  %15 = tail call ptr @CMS_sign(ptr noundef nonnull %7, ptr noundef nonnull %9, ptr noundef null, ptr noundef nonnull %13, i32 noundef 4160) #3
  %.not41 = icmp eq ptr %15, null
  br i1 %.not41, label %.thread, label %16

16:                                               ; preds = %14
  %17 = tail call ptr @BIO_new_file(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4) #3
  %.not42 = icmp eq ptr %17, null
  br i1 %.not42, label %.thread, label %18

18:                                               ; preds = %16
  %19 = tail call i32 @SMIME_write_CMS(ptr noundef nonnull %17, ptr noundef nonnull %15, ptr noundef nonnull %13, i32 noundef 4160) #3
  %.not43.not = icmp eq i32 %19, 0
  br i1 %.not43.not, label %.thread, label %23

.thread:                                          ; preds = %2, %6, %12, %14, %16, %18
  %.063 = phi ptr [ %13, %18 ], [ null, %2 ], [ null, %6 ], [ null, %12 ], [ %13, %14 ], [ %13, %16 ]
  %.02859 = phi ptr [ %15, %18 ], [ null, %2 ], [ null, %6 ], [ null, %12 ], [ null, %14 ], [ %15, %16 ]
  %.02957 = phi ptr [ %9, %18 ], [ null, %2 ], [ %9, %6 ], [ %9, %12 ], [ %9, %14 ], [ %9, %16 ]
  %.03055 = phi ptr [ %7, %18 ], [ null, %2 ], [ %7, %6 ], [ %7, %12 ], [ %7, %14 ], [ %7, %16 ]
  %.03153 = phi ptr [ %17, %18 ], [ null, %2 ], [ null, %6 ], [ null, %12 ], [ null, %14 ], [ null, %16 ]
  %20 = load ptr, ptr @stderr, align 8, !tbaa !5
  %21 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef nonnull @.str.5) #4
  %22 = load ptr, ptr @stderr, align 8, !tbaa !5
  tail call void @ERR_print_errors_fp(ptr noundef %22) #3
  br label %23

23:                                               ; preds = %.thread, %18
  %.064 = phi ptr [ %.063, %.thread ], [ %13, %18 ]
  %.02762 = phi i32 [ 1, %.thread ], [ 0, %18 ]
  %.02860 = phi ptr [ %.02859, %.thread ], [ %15, %18 ]
  %.02958 = phi ptr [ %.02957, %.thread ], [ %9, %18 ]
  %.03056 = phi ptr [ %.03055, %.thread ], [ %7, %18 ]
  %.03154 = phi ptr [ %.03153, %.thread ], [ %17, %18 ]
  tail call void @CMS_ContentInfo_free(ptr noundef %.02860) #3
  tail call void @X509_free(ptr noundef %.03056) #3
  tail call void @EVP_PKEY_free(ptr noundef %.02958) #3
  %24 = tail call i32 @BIO_free(ptr noundef %.064) #3
  %25 = tail call i32 @BIO_free(ptr noundef %.03154) #3
  %26 = tail call i32 @BIO_free(ptr noundef %5) #3
  ret i32 %.02762
}

declare i32 @OPENSSL_init_crypto(i64 noundef, ptr noundef) local_unnamed_addr #1

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

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

declare i64 @BIO_ctrl(ptr noundef, i32 noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

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

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

declare void @ERR_print_errors_fp(ptr noundef) local_unnamed_addr #1

declare void @CMS_ContentInfo_free(ptr noundef) local_unnamed_addr #1

declare void @X509_free(ptr noundef) local_unnamed_addr #1

declare void @EVP_PKEY_free(ptr noundef) local_unnamed_addr #1

declare i32 @BIO_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 = { nofree nounwind "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 }
attributes #4 = { cold 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"}


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