; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/NetworkPkg/IScsiDxe (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.EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET = type { i64, ptr, ptr, ptr, ptr, i32, i32, i8, i8, i8, i8, 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 }

@.str = external hidden unnamed_addr constant [144 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 i64, align 8
  %13 = alloca ptr, align 8
  %14 = 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
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 0
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %18 = zext i8 %17 to i32
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %5
  store i64 -9223372036854775806, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %76

21:                                               ; preds = %5
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = icmp eq ptr %22, null
  br i1 %23, label %29, label %24

24:                                               ; preds = %21
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET, ptr %25, i32 0, i32 4
  %27 = load ptr, ptr %26, align 8, !tbaa !12
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %30

29:                                               ; preds = %24, %21
  store i64 -9223372036854775806, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %76

30:                                               ; preds = %24
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = load i64, ptr %9, align 8, !tbaa !9
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = call i64 @IScsiExecuteScsiCommand(ptr noundef %31, ptr noundef %32, i64 noundef %33, ptr noundef %34)
  store i64 %35, ptr %12, align 8, !tbaa !9
  %36 = load i64, ptr %12, align 8, !tbaa !9
  %37 = icmp ne i64 %36, 0
  br i1 %37, label %38, label %74

38:                                               ; preds = %30
  %39 = load i64, ptr %12, align 8, !tbaa !9
  %40 = icmp ne i64 %39, -9223372036854775802
  br i1 %40, label %41, label %74

41:                                               ; preds = %38
  %42 = call zeroext i8 @DebugAssertEnabled()
  %43 = zext i8 %42 to i32
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %55

45:                                               ; preds = %41
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = ptrtoint ptr %46 to i64
  %48 = sub i64 %47, ptrtoint (ptr getelementptr inbounds (%struct._ISCSI_DRIVER_DATA, ptr null, i32 0, i32 5) to i64)
  %49 = inttoptr i64 %48 to ptr
  %50 = getelementptr inbounds %struct._ISCSI_DRIVER_DATA, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 8, !tbaa !15
  %52 = icmp ne i32 %51, 1094996809
  br i1 %52, label %53, label %55

53:                                               ; preds = %45
  call void @DebugAssert(ptr noundef @.str, i64 noundef 105, ptr noundef @.str.1)
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  br label %60

55:                                               ; preds = %45, %41
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = ptrtoint ptr %56 to i64
  %58 = sub i64 %57, ptrtoint (ptr getelementptr inbounds (%struct._ISCSI_DRIVER_DATA, ptr null, i32 0, i32 5) to i64)
  %59 = inttoptr i64 %58 to ptr
  br label %60

60:                                               ; preds = %55, %53
  %61 = phi ptr [ %54, %53 ], [ %59, %55 ]
  store ptr %61, ptr %13, align 8, !tbaa !5
  %62 = load ptr, ptr %13, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._ISCSI_DRIVER_DATA, ptr %62, i32 0, i32 10
  %64 = load ptr, ptr %63, align 8, !tbaa !20
  %65 = call i64 @IScsiSessionReinstatement(ptr noundef %64)
  %66 = icmp slt i64 %65, 0
  br i1 %66, label %67, label %68

67:                                               ; preds = %60
  store i64 -9223372036854775801, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %76

68:                                               ; preds = %60
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = load i64, ptr %9, align 8, !tbaa !9
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = call i64 @IScsiExecuteScsiCommand(ptr noundef %69, ptr noundef %70, i64 noundef %71, ptr noundef %72)
  store i64 %73, ptr %12, align 8, !tbaa !9
  br label %74

74:                                               ; preds = %68, %38, %30
  %75 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %75, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %76

76:                                               ; preds = %74, %67, %29, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %77 = load i64, ptr %6, align 8
  ret i64 %77
}

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

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

declare zeroext i8 @DebugAssertEnabled() #2

declare void @DebugAssert(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 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 32}
!13 = !{!"", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !14, i64 40, !14, i64 44, !7, i64 48, !7, i64 49, !7, i64 50, !7, i64 51, !7, i64 52}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !14, i64 0}
!16 = !{!"_ISCSI_DRIVER_DATA", !14, i64 0, !6, i64 8, !6, i64 16, !17, i64 24, !6, i64 32, !18, i64 40, !19, i64 104, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144}
!17 = !{!"_ISCSI_PRIVATE_PROTOCOL", !14, i64 0}
!18 = !{!"_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}
!19 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8}
!20 = !{!16, !6, i64 144}


; 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 [144 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 = load i8, ptr %1, align 1, !tbaa !5
  %.not = icmp ne i8 %6, 0
  %7 = icmp eq ptr %3, null
  %or.cond = or i1 %7, %.not
  br i1 %or.cond, label %26, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %3, i64 32
  %10 = load ptr, ptr %9, align 8, !tbaa !8
  %11 = icmp eq ptr %10, null
  br i1 %11, label %26, label %12

12:                                               ; preds = %8
  %13 = tail call i64 @IScsiExecuteScsiCommand(ptr noundef %0, ptr noundef nonnull %1, i64 noundef %2, ptr noundef nonnull %3) #2
  switch i64 %13, label %14 [
    i64 -9223372036854775802, label %26
    i64 0, label %26
  ]

14:                                               ; preds = %12
  %15 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not21 = icmp eq i8 %15, 0
  %.pre = ptrtoint ptr %0 to i64
  %.pre23 = add i64 %.pre, -40
  %.pre25 = inttoptr i64 %.pre23 to ptr
  br i1 %.not21, label %._crit_edge, label %16

16:                                               ; preds = %14
  %17 = load i32, ptr %.pre25, align 8, !tbaa !13
  %.not22 = icmp eq i32 %17, 1094996809
  br i1 %.not22, label %._crit_edge, label %18

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

._crit_edge:                                      ; preds = %14, %16, %18
  %19 = phi ptr [ %0, %18 ], [ %.pre25, %16 ], [ %.pre25, %14 ]
  %20 = getelementptr inbounds i8, ptr %19, i64 144
  %21 = load ptr, ptr %20, align 8, !tbaa !18
  %22 = tail call i64 @IScsiSessionReinstatement(ptr noundef %21) #2
  %23 = icmp slt i64 %22, 0
  br i1 %23, label %26, label %24

24:                                               ; preds = %._crit_edge
  %25 = tail call i64 @IScsiExecuteScsiCommand(ptr noundef %0, ptr noundef nonnull %1, i64 noundef %2, ptr noundef nonnull %3) #2
  br label %26

26:                                               ; preds = %24, %12, %12, %._crit_edge, %8, %5
  %.0 = phi i64 [ -9223372036854775806, %5 ], [ -9223372036854775806, %8 ], [ -9223372036854775801, %._crit_edge ], [ %25, %24 ], [ %13, %12 ], [ %13, %12 ]
  ret i64 %.0
}

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

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

declare void @DebugAssert(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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !11, i64 32}
!9 = !{!"", !10, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !12, i64 40, !12, i64 44, !6, i64 48, !6, i64 49, !6, i64 50, !6, i64 51, !6, i64 52}
!10 = !{!"long long", !6, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!"int", !6, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"_ISCSI_DRIVER_DATA", !12, i64 0, !11, i64 8, !11, i64 16, !15, i64 24, !11, i64 32, !16, i64 40, !17, i64 104, !11, i64 120, !11, i64 128, !11, i64 136, !11, i64 144}
!15 = !{!"_ISCSI_PRIVATE_PROTOCOL", !12, i64 0}
!16 = !{!"_EFI_EXT_SCSI_PASS_THRU_PROTOCOL", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56}
!17 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8}
!18 = !{!14, !11, i64 144}


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