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

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

@PeSha1Hash = external dso_local global [20 x i8], align 16
@PeSha256Hash = external dso_local global [32 x i8], align 16
@AuthenticodeWithSha1 = external dso_local global [7240 x i8], align 16
@AuthenticodeWithSha256 = external dso_local global [3801 x i8], align 16
@TestRootCert1 = external dso_local global [1437 x i8], align 16
@TestRootCert2 = external dso_local global [1538 x i8], align 16
@HashOidValue = external dso_local global [49 x i8], align 16
@.str = external hidden unnamed_addr constant [64 x i32], align 4
@.str.1 = external hidden unnamed_addr constant [7 x i32], align 4
@.str.2 = external hidden unnamed_addr constant [7 x i32], align 4
@.str.3 = external hidden unnamed_addr constant [15 x i32], align 4
@.str.4 = external hidden unnamed_addr constant [64 x i32], align 4

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @VerifyAuthenticode() #0 {
  %1 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr %1) #3
  store i8 0, ptr %1, align 1, !tbaa !5
  %2 = call i64 (ptr, ...) @Print(ptr noundef @.str)
  %3 = call i64 @CompareMem(ptr noundef getelementptr inbounds (i8, ptr @AuthenticodeWithSha1, i64 32), ptr noundef getelementptr inbounds ([49 x i8], ptr @HashOidValue, i64 0, i64 8), i64 noundef 5)
  %4 = icmp eq i64 %3, 0
  br i1 %4, label %5, label %14

5:                                                ; preds = %0
  %6 = call zeroext i8 @AuthenticodeVerify(ptr noundef @AuthenticodeWithSha1, i64 noundef 7240, ptr noundef @TestRootCert1, i64 noundef 1437, ptr noundef @PeSha1Hash, i64 noundef 20)
  store i8 %6, ptr %1, align 1, !tbaa !5
  %7 = load i8, ptr %1, align 1, !tbaa !5
  %8 = icmp ne i8 %7, 0
  br i1 %8, label %9, label %11

9:                                                ; preds = %5
  %10 = call i64 (ptr, ...) @Print(ptr noundef @.str.1)
  br label %13

11:                                               ; preds = %5
  %12 = call i64 (ptr, ...) @Print(ptr noundef @.str.2)
  br label %13

13:                                               ; preds = %11, %9
  br label %16

14:                                               ; preds = %0
  %15 = call i64 (ptr, ...) @Print(ptr noundef @.str.3)
  br label %16

16:                                               ; preds = %14, %13
  %17 = call i64 (ptr, ...) @Print(ptr noundef @.str.4)
  %18 = call i64 @CompareMem(ptr noundef getelementptr inbounds (i8, ptr @AuthenticodeWithSha256, i64 32), ptr noundef getelementptr inbounds ([49 x i8], ptr @HashOidValue, i64 0, i64 22), i64 noundef 9)
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %20, label %29

20:                                               ; preds = %16
  %21 = call zeroext i8 @AuthenticodeVerify(ptr noundef @AuthenticodeWithSha256, i64 noundef 3801, ptr noundef @TestRootCert2, i64 noundef 1538, ptr noundef @PeSha256Hash, i64 noundef 32)
  store i8 %21, ptr %1, align 1, !tbaa !5
  %22 = load i8, ptr %1, align 1, !tbaa !5
  %23 = icmp ne i8 %22, 0
  br i1 %23, label %24, label %26

24:                                               ; preds = %20
  %25 = call i64 (ptr, ...) @Print(ptr noundef @.str.1)
  br label %28

26:                                               ; preds = %20
  %27 = call i64 (ptr, ...) @Print(ptr noundef @.str.2)
  br label %28

28:                                               ; preds = %26, %24
  br label %31

29:                                               ; preds = %16
  %30 = call i64 (ptr, ...) @Print(ptr noundef @.str.3)
  br label %31

31:                                               ; preds = %29, %28
  %32 = load i8, ptr %1, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %1) #3
  ret i8 %32
}

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

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

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 noundef) #2

declare zeroext i8 @AuthenticodeVerify(ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 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 }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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

@PeSha1Hash = external dso_local global [20 x i8], align 16
@PeSha256Hash = external dso_local global [32 x i8], align 16
@AuthenticodeWithSha1 = external dso_local global [7240 x i8], align 16
@AuthenticodeWithSha256 = external dso_local global [3801 x i8], align 16
@TestRootCert1 = external dso_local global [1437 x i8], align 16
@TestRootCert2 = external dso_local global [1538 x i8], align 16
@HashOidValue = external dso_local global [49 x i8], align 16
@.str = external hidden unnamed_addr constant [64 x i32], align 4
@.str.1 = external hidden unnamed_addr constant [7 x i32], align 4
@.str.2 = external hidden unnamed_addr constant [7 x i32], align 4
@.str.3 = external hidden unnamed_addr constant [15 x i32], align 4
@.str.4 = external hidden unnamed_addr constant [64 x i32], align 4

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @VerifyAuthenticode() local_unnamed_addr #0 {
  %1 = tail call i64 (ptr, ...) @Print(ptr noundef nonnull @.str) #2
  %2 = tail call i64 @CompareMem(ptr noundef nonnull getelementptr inbounds (i8, ptr @AuthenticodeWithSha1, i64 32), ptr noundef nonnull getelementptr inbounds (i8, ptr @HashOidValue, i64 8), i64 noundef 5) #2
  %3 = icmp eq i64 %2, 0
  br i1 %3, label %4, label %6

4:                                                ; preds = %0
  %5 = tail call zeroext i8 @AuthenticodeVerify(ptr noundef nonnull @AuthenticodeWithSha1, i64 noundef 7240, ptr noundef nonnull @TestRootCert1, i64 noundef 1437, ptr noundef nonnull @PeSha1Hash, i64 noundef 20) #2
  %.not = icmp eq i8 %5, 0
  %.str.2..str.1 = select i1 %.not, ptr @.str.2, ptr @.str.1
  br label %6

6:                                                ; preds = %0, %4
  %.str.1.sink = phi ptr [ %.str.2..str.1, %4 ], [ @.str.3, %0 ]
  %.0 = phi i8 [ %5, %4 ], [ 0, %0 ]
  %7 = tail call i64 (ptr, ...) @Print(ptr noundef nonnull %.str.1.sink) #2
  %8 = tail call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.4) #2
  %9 = tail call i64 @CompareMem(ptr noundef nonnull getelementptr inbounds (i8, ptr @AuthenticodeWithSha256, i64 32), ptr noundef nonnull getelementptr inbounds (i8, ptr @HashOidValue, i64 22), i64 noundef 9) #2
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %11, label %13

11:                                               ; preds = %6
  %12 = tail call zeroext i8 @AuthenticodeVerify(ptr noundef nonnull @AuthenticodeWithSha256, i64 noundef 3801, ptr noundef nonnull @TestRootCert2, i64 noundef 1538, ptr noundef nonnull @PeSha256Hash, i64 noundef 32) #2
  %.not7 = icmp eq i8 %12, 0
  %.str.2..str.19 = select i1 %.not7, ptr @.str.2, ptr @.str.1
  br label %13

13:                                               ; preds = %6, %11
  %.str.1.sink8 = phi ptr [ %.str.2..str.19, %11 ], [ @.str.3, %6 ]
  %.1 = phi i8 [ %12, %11 ], [ %.0, %6 ]
  %14 = tail call i64 (ptr, ...) @Print(ptr noundef nonnull %.str.1.sink8) #2
  ret i8 %.1
}

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

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare zeroext i8 @AuthenticodeVerify(ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 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 = { 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)"}


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