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

; 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, %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._ISCSI_SESSION = type { i32, ptr, ptr, i8, %union.anon, 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 }
%union.anon = type { %struct._ISCSI_CHAP_AUTH_DATA }
%struct._ISCSI_CHAP_AUTH_DATA = type { ptr, i32, [1024 x i8], i32, [16 x i8], i32, [1024 x i8], i32 }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct._ISCSI_ATTEMPT_CONFIG_NVDATA = type <{ %struct._LIST_ENTRY, i8, i8, i8, i8, i8, i8, i16, i16, [96 x i8], [96 x i8], %union.EFI_IP_ADDRESS, %union.EFI_IP_ADDRESS, %union.EFI_IP_ADDRESS, %struct._ISCSI_SESSION_CONFIG_NVDATA, i8, %union.anon.0 }>
%union.EFI_IP_ADDRESS = type { [4 x i32] }
%struct._ISCSI_SESSION_CONFIG_NVDATA = type <{ i16, i8, i8, %union.EFI_IP_ADDRESS, %struct.EFI_IPv4_ADDRESS, %union.EFI_IP_ADDRESS, i8, i8, [224 x i8], %union.EFI_IP_ADDRESS, i8, [8 x i8], i16, i8, [6 x i8] }>
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }
%union.anon.0 = type { %struct._ISCSI_CHAP_AUTH_CONFIG_NVDATA }
%struct._ISCSI_CHAP_AUTH_CONFIG_NVDATA = type { i8, [127 x i8], [17 x i8], [127 x i8], [17 x i8] }

@.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 @IScsiExtScsiPassThruGetNextTargetLun(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca [16 x i8], align 16
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #3
  %12 = call zeroext i8 @DebugAssertEnabled()
  %13 = zext i8 %12 to i32
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %25

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = ptrtoint ptr %16 to i64
  %18 = sub i64 %17, ptrtoint (ptr getelementptr inbounds (%struct._ISCSI_DRIVER_DATA, ptr null, i32 0, i32 5) to i64)
  %19 = inttoptr i64 %18 to ptr
  %20 = getelementptr inbounds %struct._ISCSI_DRIVER_DATA, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !9
  %22 = icmp ne i32 %21, 1094996809
  br i1 %22, label %23, label %25

23:                                               ; preds = %15
  call void @DebugAssert(ptr noundef @.str, i64 noundef 158, ptr noundef @.str.1)
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  br label %30

25:                                               ; preds = %15, %3
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = ptrtoint ptr %26 to i64
  %28 = sub i64 %27, ptrtoint (ptr getelementptr inbounds (%struct._ISCSI_DRIVER_DATA, ptr null, i32 0, i32 5) to i64)
  %29 = inttoptr i64 %28 to ptr
  br label %30

30:                                               ; preds = %25, %23
  %31 = phi ptr [ %24, %23 ], [ %29, %25 ]
  store ptr %31, ptr %8, align 8, !tbaa !5
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._ISCSI_DRIVER_DATA, ptr %32, i32 0, i32 10
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = getelementptr inbounds %struct._ISCSI_SESSION, ptr %34, i32 0, i32 2
  %36 = load ptr, ptr %35, align 8, !tbaa !16
  %37 = getelementptr inbounds %struct._ISCSI_ATTEMPT_CONFIG_NVDATA, ptr %36, i32 0, i32 14
  store ptr %37, ptr %9, align 8, !tbaa !5
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i64 0
  %41 = load i8, ptr %40, align 1, !tbaa !20
  %42 = zext i8 %41 to i32
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %44, label %52

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

51:                                               ; preds = %44
  store i64 -9223372036854775794, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %70

52:                                               ; preds = %44, %30
  %53 = getelementptr inbounds [16 x i8], ptr %10, i64 0, i64 0
  %54 = call ptr @SetMem(ptr noundef %53, i64 noundef 16, i8 noundef zeroext -1)
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  %57 = getelementptr inbounds [16 x i8], ptr %10, i64 0, i64 0
  %58 = call i64 @CompareMem(ptr noundef %56, ptr noundef %57, i64 noundef 16)
  %59 = icmp eq i64 %58, 0
  br i1 %59, label %60, label %69

60:                                               ; preds = %52
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = load ptr, ptr %61, align 8, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %62, i64 0
  store i8 0, ptr %63, align 1, !tbaa !20
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct._ISCSI_SESSION_CONFIG_NVDATA, ptr %65, i32 0, i32 11
  %67 = getelementptr inbounds [8 x i8], ptr %66, i64 0, i64 0
  %68 = call ptr @CopyMem(ptr noundef %64, ptr noundef %67, i64 noundef 8)
  store i64 0, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %70

69:                                               ; preds = %52
  store i64 -9223372036854775806, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %70

70:                                               ; preds = %69, %60, %51
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %71 = load i64, ptr %4, align 8
  ret i64 %71
}

; 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

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

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

declare ptr @SetMem(ptr noundef, i64 noundef, i8 noundef zeroext) #2

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

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, !11, i64 0}
!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 = !{!10, !6, i64 144}
!16 = !{!17, !6, i64 16}
!17 = !{!"_ISCSI_SESSION", !11, i64 0, !6, i64 8, !6, i64 16, !7, i64 24, !7, i64 32, !7, i64 2120, !7, i64 2121, !18, i64 2128, !11, i64 2132, !11, i64 2136, !11, i64 2140, !11, i64 2144, !18, i64 2148, !19, i64 2152, !11, i64 2168, !19, i64 2176, !18, i64 2192, !11, i64 2196, !7, i64 2200, !7, i64 2201, !11, i64 2204, !11, i64 2208, !11, i64 2212, !11, i64 2216, !18, i64 2220, !7, i64 2222, !7, i64 2223, !7, i64 2224}
!18 = !{!"short", !7, i64 0}
!19 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!20 = !{!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"

@.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 range(i64 -9223372036854775806, 1) i64 @IScsiExtScsiPassThruGetNextTargetLun(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #3
  %5 = tail call zeroext i8 @DebugAssertEnabled() #3
  %.not = icmp eq i8 %5, 0
  %.pre = ptrtoint ptr %0 to i64
  %.pre12 = add i64 %.pre, -40
  %.pre14 = inttoptr i64 %.pre12 to ptr
  br i1 %.not, label %._crit_edge, label %6

6:                                                ; preds = %3
  %7 = load i32, ptr %.pre14, align 8, !tbaa !5
  %.not11 = icmp eq i32 %7, 1094996809
  br i1 %.not11, label %._crit_edge, label %8

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

._crit_edge:                                      ; preds = %3, %6, %8
  %9 = phi ptr [ %0, %8 ], [ %.pre14, %6 ], [ %.pre14, %3 ]
  %10 = getelementptr inbounds i8, ptr %9, i64 144
  %11 = load ptr, ptr %10, align 8, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !15
  %14 = load ptr, ptr %1, align 8, !tbaa !19
  %15 = load i8, ptr %14, align 1, !tbaa !20
  %16 = icmp eq i8 %15, 0
  br i1 %16, label %17, label %21

17:                                               ; preds = %._crit_edge
  %18 = getelementptr inbounds i8, ptr %13, i64 549
  %19 = tail call i64 @CompareMem(ptr noundef %2, ptr noundef nonnull %18, i64 noundef 8) #3
  %20 = icmp eq i64 %19, 0
  br i1 %20, label %30, label %21

21:                                               ; preds = %17, %._crit_edge
  %22 = call ptr @SetMem(ptr noundef nonnull %4, i64 noundef 16, i8 noundef zeroext -1) #3
  %23 = load ptr, ptr %1, align 8, !tbaa !19
  %24 = call i64 @CompareMem(ptr noundef %23, ptr noundef nonnull %4, i64 noundef 16) #3
  %25 = icmp eq i64 %24, 0
  br i1 %25, label %26, label %30

26:                                               ; preds = %21
  %27 = load ptr, ptr %1, align 8, !tbaa !19
  store i8 0, ptr %27, align 1, !tbaa !20
  %28 = getelementptr inbounds i8, ptr %13, i64 549
  %29 = call ptr @CopyMem(ptr noundef %2, ptr noundef nonnull %28, i64 noundef 8) #3
  br label %30

30:                                               ; preds = %21, %17, %26
  %.0 = phi i64 [ 0, %26 ], [ -9223372036854775794, %17 ], [ -9223372036854775806, %21 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #3
  ret i64 %.0
}

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

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #2

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

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

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

declare ptr @SetMem(ptr noundef, i64 noundef, i8 noundef zeroext) local_unnamed_addr #2

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

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 = { mustprogress 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, !7, i64 0}
!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 = !{!6, !10, i64 144}
!15 = !{!16, !10, i64 16}
!16 = !{!"_ISCSI_SESSION", !7, i64 0, !10, i64 8, !10, i64 16, !8, i64 24, !8, i64 32, !8, i64 2120, !8, i64 2121, !17, i64 2128, !7, i64 2132, !7, i64 2136, !7, i64 2140, !7, i64 2144, !17, i64 2148, !18, i64 2152, !7, i64 2168, !18, i64 2176, !17, i64 2192, !7, i64 2196, !8, i64 2200, !8, i64 2201, !7, i64 2204, !7, i64 2208, !7, i64 2212, !7, i64 2216, !17, i64 2220, !8, i64 2222, !8, i64 2223, !8, i64 2224}
!17 = !{!"short", !8, i64 0}
!18 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!19 = !{!10, !10, i64 0}
!20 = !{!8, !8, i64 0}


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