; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal (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, ptr, %struct._EFI_EXT_SCSI_PASS_THRU_PROTOCOL, %struct.EFI_EXT_SCSI_PASS_THRU_MODE, ptr, ptr, %struct._ISCSI_SESSION }
%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._ISCSI_SESSION = type { i32, %struct._ISCSI_SESSION_CONFIG_DATA, %struct._ISCSI_CHAP_AUTH_DATA, [224 x i8], i64, i8, [6 x i8], i16, i32, i32, i32, i32, i16, %struct._LIST_ENTRY, i32, %struct._LIST_ENTRY, i16, i32, i8, i8, i32, i32, i32, i32, i16, i8, i8, i8 }
%struct._ISCSI_SESSION_CONFIG_DATA = type { %struct.ISCSI_SESSION_CONFIG_NVDATA, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS }
%struct.ISCSI_SESSION_CONFIG_NVDATA = type <{ i8, i8, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i8, [224 x i8], %struct.EFI_IPv4_ADDRESS, i16, [8 x i8], [6 x i8] }>
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }
%struct._ISCSI_CHAP_AUTH_DATA = type { %struct._ISCSI_CHAP_AUTH_CONFIG_NVDATA, i32, [1024 x i8], i32, [16 x i8], i32, [1024 x i8], i32 }
%struct._ISCSI_CHAP_AUTH_CONFIG_NVDATA = type { i8, [127 x i8], [17 x i8], [127 x i8], [17 x i8] }
%struct._LIST_ENTRY = type { ptr, ptr }
%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 }

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

declare void @FreePool(ptr noundef) #0

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

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

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

26:                                               ; preds = %21
  %27 = load ptr, ptr @gBS, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %27, i32 0, i32 16
  %29 = load ptr, ptr %28, align 8, !tbaa !24
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._ISCSI_DRIVER_DATA, ptr %30, i32 0, i32 8
  %32 = load ptr, ptr %31, align 8, !tbaa !27
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._ISCSI_DRIVER_DATA, ptr %33, i32 0, i32 6
  %35 = call i64 %29(ptr noundef %32, ptr noundef @gEfiExtScsiPassThruProtocolGuid, ptr noundef %34)
  br label %36

36:                                               ; preds = %26, %21
  %37 = load ptr, ptr @gBS, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %37, i32 0, i32 12
  %39 = load ptr, ptr %38, align 8, !tbaa !28
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._ISCSI_DRIVER_DATA, ptr %40, i32 0, i32 5
  %42 = load ptr, ptr %41, align 8, !tbaa !29
  %43 = call i64 %39(ptr noundef %42)
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  call void @FreePool(ptr noundef %44)
  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" }

!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 136}
!10 = !{!"_ISCSI_DRIVER_DATA", !11, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !6, i64 32, !6, i64 40, !13, i64 48, !14, i64 112, !6, i64 128, !6, i64 136, !15, 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 = !{!"_ISCSI_SESSION", !11, i64 0, !16, i64 4, !20, i64 276, !7, i64 2648, !22, i64 2872, !7, i64 2880, !7, i64 2881, !19, i64 2888, !11, i64 2892, !11, i64 2896, !11, i64 2900, !11, i64 2904, !19, i64 2908, !23, i64 2912, !11, i64 2928, !23, i64 2936, !19, i64 2952, !11, i64 2956, !7, i64 2960, !7, i64 2961, !11, i64 2964, !11, i64 2968, !11, i64 2972, !11, i64 2976, !19, i64 2980, !7, i64 2982, !7, i64 2983, !7, i64 2984}
!16 = !{!"_ISCSI_SESSION_CONFIG_DATA", !17, i64 0, !18, i64 259, !18, i64 263, !18, i64 267}
!17 = !{!"", !7, i64 0, !7, i64 1, !18, i64 2, !18, i64 6, !18, i64 10, !7, i64 14, !7, i64 15, !18, i64 239, !19, i64 243, !7, i64 245, !7, i64 253}
!18 = !{!"", !7, i64 0}
!19 = !{!"short", !7, i64 0}
!20 = !{!"_ISCSI_CHAP_AUTH_DATA", !21, i64 0, !11, i64 292, !7, i64 296, !11, i64 1320, !7, i64 1324, !11, i64 1340, !7, i64 1344, !11, i64 2368}
!21 = !{!"_ISCSI_CHAP_AUTH_CONFIG_NVDATA", !7, i64 0, !7, i64 1, !7, i64 128, !7, i64 145, !7, i64 272}
!22 = !{!"long long", !7, i64 0}
!23 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!24 = !{!25, !6, i64 144}
!25 = !{!"", !26, 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}
!26 = !{!"", !22, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!27 = !{!10, !6, i64 128}
!28 = !{!25, !6, i64 112}
!29 = !{!10, !6, i64 40}


; 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] }

@gBS = external local_unnamed_addr global ptr, align 8
@gEfiExtScsiPassThruProtocolGuid = external global %struct.GUID, align 4
@gEfiDevicePathProtocolGuid = 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 136
  %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 !23
  %6 = getelementptr inbounds i8, ptr %5, i64 144
  %7 = load ptr, ptr %6, align 8, !tbaa !24
  %8 = getelementptr inbounds i8, ptr %0, i64 128
  %9 = load ptr, ptr %8, align 8, !tbaa !27
  %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 128
  %14 = load ptr, ptr %13, align 8, !tbaa !27
  %.not10 = icmp eq ptr %14, null
  br i1 %.not10, label %21, label %15

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

21:                                               ; preds = %15, %12
  %22 = load ptr, ptr @gBS, align 8, !tbaa !23
  %23 = getelementptr inbounds i8, ptr %22, i64 112
  %24 = load ptr, ptr %23, align 8, !tbaa !28
  %25 = getelementptr inbounds i8, ptr %0, i64 40
  %26 = load ptr, ptr %25, align 8, !tbaa !29
  %27 = tail call i64 %24(ptr noundef %26) #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 136}
!6 = !{!"_ISCSI_DRIVER_DATA", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !10, i64 32, !10, i64 40, !12, i64 48, !13, i64 112, !10, i64 128, !10, i64 136, !14, 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 = !{!"_ISCSI_SESSION", !7, i64 0, !15, i64 4, !19, i64 276, !8, i64 2648, !21, i64 2872, !8, i64 2880, !8, i64 2881, !18, i64 2888, !7, i64 2892, !7, i64 2896, !7, i64 2900, !7, i64 2904, !18, i64 2908, !22, i64 2912, !7, i64 2928, !22, i64 2936, !18, i64 2952, !7, i64 2956, !8, i64 2960, !8, i64 2961, !7, i64 2964, !7, i64 2968, !7, i64 2972, !7, i64 2976, !18, i64 2980, !8, i64 2982, !8, i64 2983, !8, i64 2984}
!15 = !{!"_ISCSI_SESSION_CONFIG_DATA", !16, i64 0, !17, i64 259, !17, i64 263, !17, i64 267}
!16 = !{!"", !8, i64 0, !8, i64 1, !17, i64 2, !17, i64 6, !17, i64 10, !8, i64 14, !8, i64 15, !17, i64 239, !18, i64 243, !8, i64 245, !8, i64 253}
!17 = !{!"", !8, i64 0}
!18 = !{!"short", !8, i64 0}
!19 = !{!"_ISCSI_CHAP_AUTH_DATA", !20, i64 0, !7, i64 292, !8, i64 296, !7, i64 1320, !8, i64 1324, !7, i64 1340, !8, i64 1344, !7, i64 2368}
!20 = !{!"_ISCSI_CHAP_AUTH_CONFIG_NVDATA", !8, i64 0, !8, i64 1, !8, i64 128, !8, i64 145, !8, i64 272}
!21 = !{!"long long", !8, i64 0}
!22 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!23 = !{!10, !10, i64 0}
!24 = !{!25, !10, i64 144}
!25 = !{!"", !26, 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}
!26 = !{!"", !21, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!27 = !{!6, !10, i64 128}
!28 = !{!25, !10, i64 112}
!29 = !{!6, !10, i64 40}


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