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

; 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.GUID = type { i32, i16, i16, [8 x i8] }
%struct._ISCSI_DRIVER_DATA = type { i32, ptr, ptr, %struct._ISCSI_PRIVATE_PROTOCOL, ptr, %struct._EFI_EXT_SCSI_PASS_THRU_PROTOCOL, %struct.EFI_EXT_SCSI_PASS_THRU_MODE, ptr, ptr, ptr, ptr }
%struct._ISCSI_PRIVATE_PROTOCOL = type { i32 }
%struct._EFI_EXT_SCSI_PASS_THRU_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_EXT_SCSI_PASS_THRU_MODE = type { i32, i32, i32 }
%struct.EFI_BOOT_SERVICES = type { %struct.EFI_TABLE_HEADER, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }
%struct.ISCSI_PRIVATE_DATA = type { [223 x i16], %struct._LIST_ENTRY, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, %struct._LIST_ENTRY, [224 x i8], i64, ptr }
%struct._LIST_ENTRY = type { ptr, ptr }

@mPrivate = external global ptr, align 8
@gBS = external global ptr, align 8
@gEfiDevicePathProtocolGuid = external global %struct.GUID, align 4
@gEfiExtScsiPassThruProtocolGuid = external global %struct.GUID, align 4

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

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

declare void @FreePool(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @IScsiCleanDriverData(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct._ISCSI_DRIVER_DATA, ptr %4, i32 0, i32 8
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %22

8:                                                ; preds = %1
  %9 = load ptr, ptr @gBS, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %9, i32 0, i32 16
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._ISCSI_DRIVER_DATA, ptr %12, i32 0, i32 7
  %14 = load ptr, ptr %13, align 8, !tbaa !19
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._ISCSI_DRIVER_DATA, ptr %15, i32 0, i32 8
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = call i64 %11(ptr noundef %14, ptr noundef @gEfiDevicePathProtocolGuid, ptr noundef %17)
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._ISCSI_DRIVER_DATA, ptr %19, i32 0, i32 8
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  call void @FreePool(ptr noundef %21)
  br label %22

22:                                               ; preds = %8, %1
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._ISCSI_DRIVER_DATA, ptr %23, i32 0, i32 7
  %25 = load ptr, ptr %24, align 8, !tbaa !19
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %43

27:                                               ; preds = %22
  %28 = load ptr, ptr @gBS, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %28, i32 0, i32 16
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._ISCSI_DRIVER_DATA, ptr %31, i32 0, i32 7
  %33 = load ptr, ptr %32, align 8, !tbaa !19
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._ISCSI_DRIVER_DATA, ptr %34, i32 0, i32 5
  %36 = call i64 %30(ptr noundef %33, ptr noundef @gEfiExtScsiPassThruProtocolGuid, ptr noundef %35)
  store i64 %36, ptr %3, align 8, !tbaa !20
  %37 = load i64, ptr %3, align 8, !tbaa !20
  %38 = icmp slt i64 %37, 0
  br i1 %38, label %42, label %39

39:                                               ; preds = %27
  %40 = load ptr, ptr @mPrivate, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ISCSI_PRIVATE_DATA, ptr %40, i32 0, i32 6
  store i8 0, ptr %41, align 4, !tbaa !21
  br label %42

42:                                               ; preds = %39, %27
  br label %43

43:                                               ; preds = %42, %22
  %44 = load ptr, ptr @gBS, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %44, i32 0, i32 12
  %46 = load ptr, ptr %45, align 8, !tbaa !24
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._ISCSI_DRIVER_DATA, ptr %47, i32 0, i32 4
  %49 = load ptr, ptr %48, align 8, !tbaa !25
  %50 = call i64 %46(ptr noundef %49)
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  call void @FreePool(ptr noundef %51)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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, !6, i64 128}
!10 = !{!"_ISCSI_DRIVER_DATA", !11, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !6, i64 32, !13, i64 40, !14, i64 104, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ISCSI_PRIVATE_PROTOCOL", !11, i64 0}
!13 = !{!"_EFI_EXT_SCSI_PASS_THRU_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!14 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8}
!15 = !{!16, !6, i64 144}
!16 = !{!"", !17, i64 0, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}
!17 = !{!"", !18, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!18 = !{!"long long", !7, i64 0}
!19 = !{!10, !6, i64 120}
!20 = !{!18, !18, i64 0}
!21 = !{!22, !7, i64 468}
!22 = !{!"", !7, i64 0, !23, i64 448, !7, i64 464, !7, i64 465, !7, i64 466, !7, i64 467, !7, i64 468, !7, i64 469, !7, i64 470, !7, i64 471, !7, i64 472, !7, i64 473, !7, i64 474, !7, i64 475, !23, i64 480, !7, i64 496, !18, i64 720, !6, i64 728}
!23 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!24 = !{!16, !6, i64 112}
!25 = !{!10, !6, i64 32}


; 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.GUID = type { i32, i16, i16, [8 x i8] }

@mPrivate = external local_unnamed_addr global ptr, align 8
@gBS = external local_unnamed_addr global ptr, align 8
@gEfiDevicePathProtocolGuid = external global %struct.GUID, align 4
@gEfiExtScsiPassThruProtocolGuid = external global %struct.GUID, align 4

declare void @FreePool(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @IScsiCleanDriverData(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 128
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %12, label %4

4:                                                ; preds = %1
  %5 = load ptr, ptr @gBS, align 8, !tbaa !14
  %6 = getelementptr inbounds i8, ptr %5, i64 144
  %7 = load ptr, ptr %6, align 8, !tbaa !15
  %8 = getelementptr inbounds i8, ptr %0, i64 120
  %9 = load ptr, ptr %8, align 8, !tbaa !19
  %10 = tail call i64 %7(ptr noundef %9, ptr noundef nonnull @gEfiDevicePathProtocolGuid, ptr noundef nonnull %3) #2
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  tail call void @FreePool(ptr noundef %11) #2
  br label %12

12:                                               ; preds = %4, %1
  %13 = getelementptr inbounds i8, ptr %0, i64 120
  %14 = load ptr, ptr %13, align 8, !tbaa !19
  %.not10 = icmp eq ptr %14, null
  br i1 %.not10, label %25, label %15

15:                                               ; preds = %12
  %16 = load ptr, ptr @gBS, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %16, i64 144
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %19 = getelementptr inbounds i8, ptr %0, i64 40
  %20 = tail call i64 %18(ptr noundef nonnull %14, ptr noundef nonnull @gEfiExtScsiPassThruProtocolGuid, ptr noundef nonnull %19) #2
  %21 = icmp slt i64 %20, 0
  br i1 %21, label %25, label %22

22:                                               ; preds = %15
  %23 = load ptr, ptr @mPrivate, align 8, !tbaa !14
  %24 = getelementptr inbounds i8, ptr %23, i64 468
  store i8 0, ptr %24, align 4, !tbaa !20
  br label %25

25:                                               ; preds = %15, %22, %12
  %26 = load ptr, ptr @gBS, align 8, !tbaa !14
  %27 = getelementptr inbounds i8, ptr %26, i64 112
  %28 = load ptr, ptr %27, align 8, !tbaa !23
  %29 = getelementptr inbounds i8, ptr %0, i64 32
  %30 = load ptr, ptr %29, align 8, !tbaa !24
  %31 = tail call i64 %28(ptr noundef %30) #2
  tail call void @FreePool(ptr noundef nonnull %0) #2
  ret void
}

attributes #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 = { 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 #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)"}
!5 = !{!6, !10, i64 128}
!6 = !{!"_ISCSI_DRIVER_DATA", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !10, i64 32, !12, i64 40, !13, i64 104, !10, i64 120, !10, i64 128, !10, i64 136, !10, i64 144}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_ISCSI_PRIVATE_PROTOCOL", !7, i64 0}
!12 = !{!"_EFI_EXT_SCSI_PASS_THRU_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56}
!13 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8}
!14 = !{!10, !10, i64 0}
!15 = !{!16, !10, i64 144}
!16 = !{!"", !17, i64 0, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128, !10, i64 136, !10, i64 144, !10, i64 152, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !10, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !10, i64 224, !10, i64 232, !10, i64 240, !10, i64 248, !10, i64 256, !10, i64 264, !10, i64 272, !10, i64 280, !10, i64 288, !10, i64 296, !10, i64 304, !10, i64 312, !10, i64 320, !10, i64 328, !10, i64 336, !10, i64 344, !10, i64 352, !10, i64 360, !10, i64 368}
!17 = !{!"", !18, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!18 = !{!"long long", !8, i64 0}
!19 = !{!6, !10, i64 120}
!20 = !{!21, !8, i64 468}
!21 = !{!"", !8, i64 0, !22, i64 448, !8, i64 464, !8, i64 465, !8, i64 466, !8, i64 467, !8, i64 468, !8, i64 469, !8, i64 470, !8, i64 471, !8, i64 472, !8, i64 473, !8, i64 474, !8, i64 475, !22, i64 480, !8, i64 496, !18, i64 720, !10, i64 728}
!22 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!23 = !{!16, !10, i64 112}
!24 = !{!6, !10, i64 32}


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