; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal (IScsiExtScsiPassThruFunction)

; 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._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_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET = type { i64, ptr, ptr, ptr, ptr, i32, i32, i8, i8, i8, i8, i8 }

@.str = external hidden unnamed_addr constant [164 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @IScsiExtScsiPassThruFunction(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %16 = call zeroext i8 @DebugAssertEnabled()
  %17 = zext i8 %16 to i32
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %29

19:                                               ; preds = %5
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = ptrtoint ptr %20 to i64
  %22 = sub i64 %21, ptrtoint (ptr getelementptr inbounds (%struct._ISCSI_DRIVER_DATA, ptr null, i32 0, i32 6) to i64)
  %23 = inttoptr i64 %22 to ptr
  %24 = getelementptr inbounds %struct._ISCSI_DRIVER_DATA, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !11
  %26 = icmp ne i32 %25, 1094996809
  br i1 %26, label %27, label %29

27:                                               ; preds = %19
  call void @DebugAssert(ptr noundef @.str, i64 noundef 72, ptr noundef @.str.1)
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  br label %34

29:                                               ; preds = %19, %5
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = ptrtoint ptr %30 to i64
  %32 = sub i64 %31, ptrtoint (ptr getelementptr inbounds (%struct._ISCSI_DRIVER_DATA, ptr null, i32 0, i32 6) to i64)
  %33 = inttoptr i64 %32 to ptr
  br label %34

34:                                               ; preds = %29, %27
  %35 = phi ptr [ %28, %27 ], [ %33, %29 ]
  store ptr %35, ptr %12, align 8, !tbaa !5
  %36 = load ptr, ptr %12, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._ISCSI_DRIVER_DATA, ptr %36, i32 0, i32 10
  %38 = getelementptr inbounds %struct._ISCSI_SESSION, ptr %37, i32 0, i32 1
  %39 = getelementptr inbounds %struct._ISCSI_SESSION_CONFIG_DATA, ptr %38, i32 0, i32 0
  store ptr %39, ptr %13, align 8, !tbaa !5
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i64 0
  %42 = load i8, ptr %41, align 1, !tbaa !25
  %43 = zext i8 %42 to i32
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %51, label %45

45:                                               ; preds = %34
  %46 = load ptr, ptr %13, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.ISCSI_SESSION_CONFIG_NVDATA, ptr %46, i32 0, i32 9
  %48 = getelementptr inbounds [8 x i8], ptr %47, i64 0, i64 0
  %49 = call i64 @CompareMem(ptr noundef %9, ptr noundef %48, i64 noundef 8)
  %50 = icmp ne i64 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %45, %34
  store i64 -9223372036854775806, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %85

52:                                               ; preds = %45
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = icmp eq ptr %53, null
  br i1 %54, label %60, label %55

55:                                               ; preds = %52
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET, ptr %56, i32 0, i32 4
  %58 = load ptr, ptr %57, align 8, !tbaa !26
  %59 = icmp eq ptr %58, null
  br i1 %59, label %60, label %61

60:                                               ; preds = %55, %52
  store i64 -9223372036854775806, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %85

61:                                               ; preds = %55
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = load i64, ptr %9, align 8, !tbaa !9
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = call i64 @IScsiExecuteScsiCommand(ptr noundef %62, ptr noundef %63, i64 noundef %64, ptr noundef %65)
  store i64 %66, ptr %14, align 8, !tbaa !9
  %67 = load i64, ptr %14, align 8, !tbaa !9
  %68 = icmp ne i64 %67, 0
  br i1 %68, label %69, label %83

69:                                               ; preds = %61
  %70 = load i64, ptr %14, align 8, !tbaa !9
  %71 = icmp ne i64 %70, -9223372036854775802
  br i1 %71, label %72, label %83

72:                                               ; preds = %69
  %73 = load ptr, ptr %12, align 8, !tbaa !5
  %74 = call i64 @IScsiSessionReinstatement(ptr noundef %73)
  %75 = icmp slt i64 %74, 0
  br i1 %75, label %76, label %77

76:                                               ; preds = %72
  store i64 -9223372036854775801, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %85

77:                                               ; preds = %72
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = load ptr, ptr %8, align 8, !tbaa !5
  %80 = load i64, ptr %9, align 8, !tbaa !9
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = call i64 @IScsiExecuteScsiCommand(ptr noundef %78, ptr noundef %79, i64 noundef %80, ptr noundef %81)
  store i64 %82, ptr %14, align 8, !tbaa !9
  br label %83

83:                                               ; preds = %77, %69, %61
  %84 = load i64, ptr %14, align 8, !tbaa !9
  store i64 %84, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %85

85:                                               ; preds = %83, %76, %60, %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %86 = load i64, ptr %6, align 8
  ret i64 %86
}

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

declare zeroext i8 @DebugAssertEnabled() #2

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #2

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

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

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


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

@.str = external hidden unnamed_addr constant [164 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @IScsiExtScsiPassThruFunction(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr nocapture noundef readnone %4) local_unnamed_addr #0 {
  %6 = alloca i64, align 8
  store i64 %2, ptr %6, align 8, !tbaa !5
  %7 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %7, 0
  %.pre = ptrtoint ptr %0 to i64
  %.pre24 = add i64 %.pre, -48
  %.pre26 = inttoptr i64 %.pre24 to ptr
  br i1 %.not, label %._crit_edge, label %8

8:                                                ; preds = %5
  %9 = load i32, ptr %.pre26, align 8, !tbaa !9
  %.not21 = icmp eq i32 %9, 1094996809
  br i1 %.not21, label %._crit_edge, label %10

10:                                               ; preds = %8
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 72, ptr noundef nonnull @.str.1) #2
  br label %._crit_edge

._crit_edge:                                      ; preds = %5, %8, %10
  %11 = phi ptr [ %0, %10 ], [ %.pre26, %8 ], [ %.pre26, %5 ]
  %12 = load i8, ptr %1, align 1, !tbaa !24
  %.not22 = icmp eq i8 %12, 0
  br i1 %.not22, label %13, label %30

13:                                               ; preds = %._crit_edge
  %14 = getelementptr inbounds i8, ptr %11, i64 393
  %15 = call i64 @CompareMem(ptr noundef nonnull %6, ptr noundef nonnull %14, i64 noundef 8) #2
  %.not23 = icmp ne i64 %15, 0
  %16 = icmp eq ptr %3, null
  %or.cond = or i1 %16, %.not23
  br i1 %or.cond, label %30, label %17

17:                                               ; preds = %13
  %18 = getelementptr inbounds i8, ptr %3, i64 32
  %19 = load ptr, ptr %18, align 8, !tbaa !25
  %20 = icmp eq ptr %19, null
  br i1 %20, label %30, label %21

21:                                               ; preds = %17
  %22 = load i64, ptr %6, align 8, !tbaa !5
  %23 = call i64 @IScsiExecuteScsiCommand(ptr noundef %0, ptr noundef nonnull %1, i64 noundef %22, ptr noundef nonnull %3) #2
  switch i64 %23, label %24 [
    i64 -9223372036854775802, label %30
    i64 0, label %30
  ]

24:                                               ; preds = %21
  %25 = call i64 @IScsiSessionReinstatement(ptr noundef %11) #2
  %26 = icmp slt i64 %25, 0
  br i1 %26, label %30, label %27

27:                                               ; preds = %24
  %28 = load i64, ptr %6, align 8, !tbaa !5
  %29 = call i64 @IScsiExecuteScsiCommand(ptr noundef %0, ptr noundef nonnull %1, i64 noundef %28, ptr noundef nonnull %3) #2
  br label %30

30:                                               ; preds = %27, %21, %21, %24, %17, %._crit_edge, %13
  %.019 = phi i64 [ -9223372036854775806, %13 ], [ -9223372036854775806, %._crit_edge ], [ -9223372036854775806, %17 ], [ -9223372036854775801, %24 ], [ %29, %27 ], [ %23, %21 ], [ %23, %21 ]
  ret i64 %.019
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

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

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

declare i64 @IScsiSessionReinstatement(ptr 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ISCSI_DRIVER_DATA", !11, i64 0, !12, i64 8, !12, i64 16, !13, i64 24, !12, i64 32, !12, i64 40, !14, i64 48, !15, i64 112, !12, i64 128, !12, i64 136, !16, i64 144}
!11 = !{!"int", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"_ISCSI_PRIVATE_PROTOCOL", !11, i64 0}
!14 = !{!"_EFI_EXT_SCSI_PASS_THRU_PROTOCOL", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56}
!15 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8}
!16 = !{!"_ISCSI_SESSION", !11, i64 0, !17, i64 4, !21, i64 276, !7, i64 2648, !6, i64 2872, !7, i64 2880, !7, i64 2881, !20, i64 2888, !11, i64 2892, !11, i64 2896, !11, i64 2900, !11, i64 2904, !20, i64 2908, !23, i64 2912, !11, i64 2928, !23, i64 2936, !20, i64 2952, !11, i64 2956, !7, i64 2960, !7, i64 2961, !11, i64 2964, !11, i64 2968, !11, i64 2972, !11, i64 2976, !20, i64 2980, !7, i64 2982, !7, i64 2983, !7, i64 2984}
!17 = !{!"_ISCSI_SESSION_CONFIG_DATA", !18, i64 0, !19, i64 259, !19, i64 263, !19, i64 267}
!18 = !{!"", !7, i64 0, !7, i64 1, !19, i64 2, !19, i64 6, !19, i64 10, !7, i64 14, !7, i64 15, !19, i64 239, !20, i64 243, !7, i64 245, !7, i64 253}
!19 = !{!"", !7, i64 0}
!20 = !{!"short", !7, i64 0}
!21 = !{!"_ISCSI_CHAP_AUTH_DATA", !22, i64 0, !11, i64 292, !7, i64 296, !11, i64 1320, !7, i64 1324, !11, i64 1340, !7, i64 1344, !11, i64 2368}
!22 = !{!"_ISCSI_CHAP_AUTH_CONFIG_NVDATA", !7, i64 0, !7, i64 1, !7, i64 128, !7, i64 145, !7, i64 272}
!23 = !{!"_LIST_ENTRY", !12, i64 0, !12, i64 8}
!24 = !{!7, !7, i64 0}
!25 = !{!26, !12, i64 32}
!26 = !{!"", !6, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !11, i64 40, !11, i64 44, !7, i64 48, !7, i64 49, !7, i64 50, !7, i64 51, !7, i64 52}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass