; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/NetworkPkg/IpSecDxe (IpSecEspAuthVerifyPayload)

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

%struct.HASH_DATA_FRAGMENT = type { i64, ptr }
%struct._IPSEC_SAD_ENTRY = type { ptr, ptr, %struct._LIST_ENTRY, %struct._LIST_ENTRY }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct._IPSEC_SAD_DATA = type { i32, i64, i8, [4 x i64], %union.EFI_IPSEC_ALGO_INFO, %struct._EFI_IPSEC_SA_LIFETIME, i32, ptr, ptr, i8, i8, %union.EFI_IP_ADDRESS, %union.EFI_IP_ADDRESS }
%union.EFI_IPSEC_ALGO_INFO = type { %struct._EFI_IPSEC_ESP_ALGO_INFO }
%struct._EFI_IPSEC_ESP_ALGO_INFO = type { i8, i64, ptr, i8, i64, ptr }
%struct._EFI_IPSEC_SA_LIFETIME = type { i64, i64, i64 }
%union.EFI_IP_ADDRESS = type { [4 x i32] }

@.str.2 = external hidden unnamed_addr constant [27 x i8], align 1

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

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 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 @IpSecEspAuthVerifyPayload(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #2 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca [12 x i8], align 1
  %13 = alloca [1 x %struct.HASH_DATA_FRAGMENT], align 16
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 12, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #3
  %15 = load i64, ptr %7, align 8, !tbaa !9
  %16 = load i64, ptr %9, align 8, !tbaa !9
  %17 = sub i64 %15, %16
  store i64 %17, ptr %11, align 8, !tbaa !9
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds [1 x %struct.HASH_DATA_FRAGMENT], ptr %13, i64 0, i64 0
  %20 = getelementptr inbounds %struct.HASH_DATA_FRAGMENT, ptr %19, i32 0, i32 1
  store ptr %18, ptr %20, align 8, !tbaa !11
  %21 = load i64, ptr %11, align 8, !tbaa !9
  %22 = getelementptr inbounds [1 x %struct.HASH_DATA_FRAGMENT], ptr %13, i64 0, i64 0
  %23 = getelementptr inbounds %struct.HASH_DATA_FRAGMENT, ptr %22, i32 0, i32 0
  store i64 %21, ptr %23, align 16, !tbaa !13
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._IPSEC_SAD_ENTRY, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = getelementptr inbounds %struct._IPSEC_SAD_DATA, ptr %26, i32 0, i32 4
  %28 = getelementptr inbounds %struct._EFI_IPSEC_ESP_ALGO_INFO, ptr %27, i32 0, i32 3
  %29 = load i8, ptr %28, align 8, !tbaa !17
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._IPSEC_SAD_ENTRY, ptr %30, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = getelementptr inbounds %struct._IPSEC_SAD_DATA, ptr %32, i32 0, i32 4
  %34 = getelementptr inbounds %struct._EFI_IPSEC_ESP_ALGO_INFO, ptr %33, i32 0, i32 5
  %35 = load ptr, ptr %34, align 8, !tbaa !17
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._IPSEC_SAD_ENTRY, ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !14
  %39 = getelementptr inbounds %struct._IPSEC_SAD_DATA, ptr %38, i32 0, i32 4
  %40 = getelementptr inbounds %struct._EFI_IPSEC_ESP_ALGO_INFO, ptr %39, i32 0, i32 4
  %41 = load i64, ptr %40, align 8, !tbaa !17
  %42 = getelementptr inbounds [1 x %struct.HASH_DATA_FRAGMENT], ptr %13, i64 0, i64 0
  %43 = getelementptr inbounds [12 x i8], ptr %12, i64 0, i64 0
  %44 = load i64, ptr %9, align 8, !tbaa !9
  %45 = call i64 @IpSecCryptoIoHmac(i8 noundef zeroext %29, ptr noundef %35, i64 noundef %41, ptr noundef %42, i64 noundef 1, ptr noundef %43, i64 noundef %44)
  store i64 %45, ptr %10, align 8, !tbaa !9
  %46 = load i64, ptr %10, align 8, !tbaa !9
  %47 = icmp slt i64 %46, 0
  br i1 %47, label %48, label %50

48:                                               ; preds = %4
  %49 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %49, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %74

50:                                               ; preds = %4
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load i64, ptr %11, align 8, !tbaa !9
  %53 = getelementptr inbounds i8, ptr %51, i64 %52
  %54 = getelementptr inbounds [12 x i8], ptr %12, i64 0, i64 0
  %55 = load i64, ptr %9, align 8, !tbaa !9
  %56 = call i64 @CompareMem(ptr noundef %53, ptr noundef %54, i64 noundef %55)
  %57 = icmp eq i64 %56, 0
  br i1 %57, label %58, label %59

58:                                               ; preds = %50
  store i64 0, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %74

59:                                               ; preds = %50
  br label %60

60:                                               ; preds = %59
  %61 = call zeroext i8 @DebugPrintEnabled()
  %62 = icmp ne i8 %61, 0
  br i1 %62, label %63, label %71

63:                                               ; preds = %60
  br label %64

64:                                               ; preds = %63
  %65 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %66 = icmp ne i8 %65, 0
  br i1 %66, label %67, label %68

67:                                               ; preds = %64
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.2)
  br label %68

68:                                               ; preds = %67, %64
  br label %69

69:                                               ; preds = %68
  br label %70

70:                                               ; preds = %69
  br label %71

71:                                               ; preds = %70, %60
  br label %72

72:                                               ; preds = %71
  br label %73

73:                                               ; preds = %72
  store i64 -9223372036854775793, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %74

74:                                               ; preds = %73, %58, %48
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 12, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %75 = load i64, ptr %5, align 8
  ret i64 %75
}

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

declare zeroext i8 @DebugPrintEnabled() #1

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #1

declare void @DebugPrint(i64 noundef, 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"", !10, i64 0, !6, i64 8}
!13 = !{!12, !10, i64 0}
!14 = !{!15, !6, i64 8}
!15 = !{!"_IPSEC_SAD_ENTRY", !6, i64 0, !6, i64 8, !16, i64 16, !16, i64 32}
!16 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!17 = !{!7, !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"

%struct.HASH_DATA_FRAGMENT = type { i64, ptr }

@.str.2 = external hidden unnamed_addr constant [27 x i8], align 1

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

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 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 range(i64 -9223372036854775808, 1) i64 @IpSecEspAuthVerifyPayload(ptr noundef %0, i64 noundef %1, ptr nocapture noundef readonly %2, i64 noundef %3) local_unnamed_addr #2 {
  %5 = alloca [12 x i8], align 1
  %6 = alloca [1 x %struct.HASH_DATA_FRAGMENT], align 16
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #3
  %7 = sub i64 %1, %3
  %8 = getelementptr inbounds i8, ptr %6, i64 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i64 %7, ptr %6, align 16, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %2, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %10, i64 80
  %12 = load i8, ptr %11, align 8, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %10, i64 96
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %15 = getelementptr inbounds i8, ptr %10, i64 88
  %16 = load i64, ptr %15, align 8, !tbaa !15
  %17 = call i64 @IpSecCryptoIoHmac(i8 noundef zeroext %12, ptr noundef %14, i64 noundef %16, ptr noundef nonnull %6, i64 noundef 1, ptr noundef nonnull %5, i64 noundef %3) #3
  %18 = icmp slt i64 %17, 0
  br i1 %18, label %28, label %19

19:                                               ; preds = %4
  %20 = getelementptr inbounds i8, ptr %0, i64 %7
  %21 = call i64 @CompareMem(ptr noundef %20, ptr noundef nonnull %5, i64 noundef %3) #3
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %28, label %23

23:                                               ; preds = %19
  %24 = call zeroext i8 @DebugPrintEnabled() #3
  %.not = icmp eq i8 %24, 0
  br i1 %.not, label %28, label %25

25:                                               ; preds = %23
  %26 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #3
  %.not14 = icmp eq i8 %26, 0
  br i1 %.not14, label %28, label %27

27:                                               ; preds = %25
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.2) #3
  br label %28

28:                                               ; preds = %23, %27, %25, %19, %4
  %.0 = phi i64 [ %17, %4 ], [ 0, %19 ], [ -9223372036854775793, %25 ], [ -9223372036854775793, %27 ], [ -9223372036854775793, %23 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %5) #3
  ret i64 %.0
}

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

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #1

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) local_unnamed_addr #1

declare void @DebugPrint(i64 noundef, 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, !10, i64 8}
!6 = !{!"", !7, i64 0, !10, i64 8}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!13, !10, i64 8}
!13 = !{!"_IPSEC_SAD_ENTRY", !10, i64 0, !10, i64 8, !14, i64 16, !14, i64 32}
!14 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!15 = !{!8, !8, i64 0}


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