; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/CryptoPkg/Application (ValidateCryptPkcs7)

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

@TestCert = external dso_local constant [634 x i8], align 16
@TestCACert = external dso_local constant [629 x i8], align 16
@TestKeyPem = external dso_local constant [962 x i8], align 16
@PemPass = external dso_local global ptr, align 8
@Payload = external dso_local global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [7 x i32], align 4
@.str.5 = external hidden unnamed_addr constant [7 x i32], align 4
@.str.13 = external hidden unnamed_addr constant [54 x i32], align 4
@.str.14 = external hidden unnamed_addr constant [32 x i32], align 4
@.str.15 = external hidden unnamed_addr constant [32 x i32], align 4
@.str.16 = external hidden unnamed_addr constant [2 x i32], align 4

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

declare i64 @Print(ptr noundef, ...) #1

declare void @FreePool(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
define dso_local i64 @ValidateCryptPkcs7() #2 {
  %1 = alloca i8, align 1
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store ptr null, ptr %2, align 8, !tbaa !5
  store ptr null, ptr %4, align 8, !tbaa !5
  %5 = call i64 (ptr, ...) @Print(ptr noundef @.str.13)
  %6 = call i64 (ptr, ...) @Print(ptr noundef @.str.14)
  %7 = call zeroext i8 @X509ConstructCertificate(ptr noundef @TestCert, i64 noundef 634, ptr noundef %4)
  store i8 %7, ptr %1, align 1, !tbaa !9
  %8 = load i8, ptr %1, align 1, !tbaa !9
  %9 = icmp ne i8 %8, 0
  br i1 %9, label %10, label %13

10:                                               ; preds = %0
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %15

13:                                               ; preds = %10, %0
  %14 = call i64 (ptr, ...) @Print(ptr noundef @.str.4)
  br label %48

15:                                               ; preds = %10
  %16 = call i64 (ptr, ...) @Print(ptr noundef @.str.5)
  br label %17

17:                                               ; preds = %15
  %18 = load ptr, ptr @PemPass, align 8, !tbaa !5
  %19 = load ptr, ptr @Payload, align 8, !tbaa !5
  %20 = load ptr, ptr @Payload, align 8, !tbaa !5
  %21 = call i64 @AsciiStrLen(ptr noundef %20)
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = call zeroext i8 @Pkcs7Sign(ptr noundef @TestKeyPem, i64 noundef 962, ptr noundef %18, ptr noundef %19, i64 noundef %21, ptr noundef %22, ptr noundef null, ptr noundef %2, ptr noundef %3)
  store i8 %23, ptr %1, align 1, !tbaa !9
  %24 = load i8, ptr %1, align 1, !tbaa !9
  %25 = icmp ne i8 %24, 0
  br i1 %25, label %26, label %29

26:                                               ; preds = %17
  %27 = load i64, ptr %3, align 8, !tbaa !10
  %28 = icmp eq i64 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %26, %17
  %30 = call i64 (ptr, ...) @Print(ptr noundef @.str.4)
  br label %48

31:                                               ; preds = %26
  %32 = call i64 (ptr, ...) @Print(ptr noundef @.str.5)
  br label %33

33:                                               ; preds = %31
  %34 = call i64 (ptr, ...) @Print(ptr noundef @.str.15)
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = load i64, ptr %3, align 8, !tbaa !10
  %37 = load ptr, ptr @Payload, align 8, !tbaa !5
  %38 = load ptr, ptr @Payload, align 8, !tbaa !5
  %39 = call i64 @AsciiStrLen(ptr noundef %38)
  %40 = call zeroext i8 @Pkcs7Verify(ptr noundef %35, i64 noundef %36, ptr noundef @TestCACert, i64 noundef 629, ptr noundef %37, i64 noundef %39)
  store i8 %40, ptr %1, align 1, !tbaa !9
  %41 = load i8, ptr %1, align 1, !tbaa !9
  %42 = icmp ne i8 %41, 0
  br i1 %42, label %45, label %43

43:                                               ; preds = %33
  %44 = call i64 (ptr, ...) @Print(ptr noundef @.str.4)
  br label %47

45:                                               ; preds = %33
  %46 = call i64 (ptr, ...) @Print(ptr noundef @.str.5)
  br label %47

47:                                               ; preds = %45, %43
  br label %48

48:                                               ; preds = %47, %29, %13
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %53

51:                                               ; preds = %48
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  call void @FreePool(ptr noundef %52)
  br label %53

53:                                               ; preds = %51, %48
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = icmp ne ptr %54, null
  br i1 %55, label %56, label %58

56:                                               ; preds = %53
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  call void @X509Free(ptr noundef %57)
  br label %58

58:                                               ; preds = %56, %53
  %59 = call i64 (ptr, ...) @Print(ptr noundef @.str.16)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %1) #3
  ret i64 0
}

declare zeroext i8 @X509ConstructCertificate(ptr noundef, i64 noundef, ptr noundef) #1

declare zeroext i8 @Pkcs7Sign(ptr noundef, i64 noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

declare i64 @AsciiStrLen(ptr noundef) #1

declare zeroext i8 @Pkcs7Verify(ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) #1

declare void @X509Free(ptr 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long 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"

@TestCert = external dso_local constant [634 x i8], align 16
@TestCACert = external dso_local constant [629 x i8], align 16
@TestKeyPem = external dso_local constant [962 x i8], align 16
@PemPass = external dso_local local_unnamed_addr global ptr, align 8
@Payload = external dso_local local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [7 x i32], align 4
@.str.5 = external hidden unnamed_addr constant [7 x i32], align 4
@.str.13 = external hidden unnamed_addr constant [54 x i32], align 4
@.str.14 = external hidden unnamed_addr constant [32 x i32], align 4
@.str.15 = external hidden unnamed_addr constant [32 x i32], align 4
@.str.16 = external hidden unnamed_addr constant [2 x i32], align 4

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

declare i64 @Print(ptr noundef, ...) local_unnamed_addr #1

declare void @FreePool(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
define dso_local noundef i64 @ValidateCryptPkcs7() local_unnamed_addr #2 {
  %1 = alloca ptr, align 8
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  store ptr null, ptr %1, align 8, !tbaa !5
  store ptr null, ptr %3, align 8, !tbaa !5
  %4 = tail call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.13) #3
  %5 = tail call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.14) #3
  %6 = call zeroext i8 @X509ConstructCertificate(ptr noundef nonnull @TestCert, i64 noundef 634, ptr noundef nonnull %3) #3
  %7 = icmp eq i8 %6, 0
  %8 = load ptr, ptr %3, align 8
  %9 = icmp eq ptr %8, null
  %or.cond = select i1 %7, i1 true, i1 %9
  br i1 %or.cond, label %28, label %10

10:                                               ; preds = %0
  %11 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.5) #3
  %12 = load ptr, ptr @PemPass, align 8, !tbaa !5
  %13 = load ptr, ptr @Payload, align 8, !tbaa !5
  %14 = call i64 @AsciiStrLen(ptr noundef %13) #3
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = call zeroext i8 @Pkcs7Sign(ptr noundef nonnull @TestKeyPem, i64 noundef 962, ptr noundef %12, ptr noundef %13, i64 noundef %14, ptr noundef %15, ptr noundef null, ptr noundef nonnull %1, ptr noundef nonnull %2) #3
  %17 = icmp eq i8 %16, 0
  %18 = load i64, ptr %2, align 8
  %19 = icmp eq i64 %18, 0
  %or.cond3 = select i1 %17, i1 true, i1 %19
  br i1 %or.cond3, label %28, label %20

20:                                               ; preds = %10
  %21 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.5) #3
  %22 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.15) #3
  %23 = load ptr, ptr %1, align 8, !tbaa !5
  %24 = load i64, ptr %2, align 8, !tbaa !9
  %25 = load ptr, ptr @Payload, align 8, !tbaa !5
  %26 = call i64 @AsciiStrLen(ptr noundef %25) #3
  %27 = call zeroext i8 @Pkcs7Verify(ptr noundef %23, i64 noundef %24, ptr noundef nonnull @TestCACert, i64 noundef 629, ptr noundef %25, i64 noundef %26) #3
  %.not = icmp eq i8 %27, 0
  %.str.4..str.5 = select i1 %.not, ptr @.str.4, ptr @.str.5
  br label %28

28:                                               ; preds = %20, %10, %0
  %.str.4.sink = phi ptr [ @.str.4, %0 ], [ @.str.4, %10 ], [ %.str.4..str.5, %20 ]
  %29 = call i64 (ptr, ...) @Print(ptr noundef nonnull %.str.4.sink) #3
  %30 = load ptr, ptr %1, align 8, !tbaa !5
  %.not7 = icmp eq ptr %30, null
  br i1 %.not7, label %32, label %31

31:                                               ; preds = %28
  call void @FreePool(ptr noundef nonnull %30) #3
  br label %32

32:                                               ; preds = %31, %28
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %.not8 = icmp eq ptr %33, null
  br i1 %.not8, label %35, label %34

34:                                               ; preds = %32
  call void @X509Free(ptr noundef nonnull %33) #3
  br label %35

35:                                               ; preds = %34, %32
  %36 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  ret i64 0
}

declare zeroext i8 @X509ConstructCertificate(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

declare zeroext i8 @Pkcs7Sign(ptr noundef, i64 noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i64 @AsciiStrLen(ptr noundef) local_unnamed_addr #1

declare zeroext i8 @Pkcs7Verify(ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare void @X509Free(ptr 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 = !{!"long long", !7, i64 0}


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