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

; 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_DEVICE_PATH_PROTOCOL = type { i8, i8, [2 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._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 @IScsiExtScsiPassThruGetTargetLun(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %21, label %15

15:                                               ; preds = %4
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %21, label %18

18:                                               ; preds = %15
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %18, %15, %4
  store i64 -9223372036854775806, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %86

22:                                               ; preds = %18
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.EFI_DEVICE_PATH_PROTOCOL, ptr %23, i32 0, i32 0
  %25 = load i8, ptr %24, align 1, !tbaa !9
  %26 = zext i8 %25 to i32
  %27 = icmp ne i32 %26, 3
  br i1 %27, label %38, label %28

28:                                               ; preds = %22
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.EFI_DEVICE_PATH_PROTOCOL, ptr %29, i32 0, i32 1
  %31 = load i8, ptr %30, align 1, !tbaa !11
  %32 = zext i8 %31 to i32
  %33 = icmp ne i32 %32, 19
  br i1 %33, label %38, label %34

34:                                               ; preds = %28
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = call i64 @DevicePathNodeLength(ptr noundef %35)
  %37 = icmp ule i64 %36, 18
  br i1 %37, label %38, label %39

38:                                               ; preds = %34, %28, %22
  store i64 -9223372036854775805, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %86

39:                                               ; preds = %34
  %40 = call zeroext i8 @DebugAssertEnabled()
  %41 = zext i8 %40 to i32
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %53

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

51:                                               ; preds = %43
  call void @DebugAssert(ptr noundef @.str, i64 noundef 328, ptr noundef @.str.1)
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  br label %58

53:                                               ; preds = %43, %39
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = ptrtoint ptr %54 to i64
  %56 = sub i64 %55, ptrtoint (ptr getelementptr inbounds (%struct._ISCSI_DRIVER_DATA, ptr null, i32 0, i32 5) to i64)
  %57 = inttoptr i64 %56 to ptr
  br label %58

58:                                               ; preds = %53, %51
  %59 = phi ptr [ %52, %51 ], [ %57, %53 ]
  store ptr %59, ptr %10, align 8, !tbaa !5
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._ISCSI_DRIVER_DATA, ptr %60, i32 0, i32 10
  %62 = load ptr, ptr %61, align 8, !tbaa !18
  %63 = getelementptr inbounds %struct._ISCSI_SESSION, ptr %62, i32 0, i32 2
  %64 = load ptr, ptr %63, align 8, !tbaa !19
  %65 = getelementptr inbounds %struct._ISCSI_ATTEMPT_CONFIG_NVDATA, ptr %64, i32 0, i32 14
  store ptr %65, ptr %11, align 8, !tbaa !5
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = load ptr, ptr %66, align 8, !tbaa !5
  %68 = call ptr @SetMem(ptr noundef %67, i64 noundef 16, i8 noundef zeroext -1)
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = load ptr, ptr %69, align 8, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %70, i64 0
  store i8 0, ptr %71, align 1, !tbaa !23
  %72 = load ptr, ptr %11, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct._ISCSI_SESSION_CONFIG_NVDATA, ptr %72, i32 0, i32 8
  %74 = getelementptr inbounds [224 x i8], ptr %73, i64 0, i64 0
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = getelementptr inbounds i8, ptr %75, i64 18
  %77 = call i64 @AsciiStrCmp(ptr noundef %74, ptr noundef %76)
  %78 = icmp ne i64 %77, 0
  br i1 %78, label %79, label %80

79:                                               ; preds = %58
  store i64 -9223372036854775805, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %86

80:                                               ; preds = %58
  %81 = load ptr, ptr %9, align 8, !tbaa !5
  %82 = load ptr, ptr %11, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct._ISCSI_SESSION_CONFIG_NVDATA, ptr %82, i32 0, i32 11
  %84 = getelementptr inbounds [8 x i8], ptr %83, i64 0, i64 0
  %85 = call ptr @CopyMem(ptr noundef %81, ptr noundef %84, i64 noundef 8)
  store i64 0, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %86

86:                                               ; preds = %80, %79, %38, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %87 = load i64, ptr %5, align 8
  ret i64 %87
}

; 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 ptr @SetMem(ptr noundef, i64 noundef, i8 noundef zeroext) #2

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

declare i64 @DevicePathNodeLength(ptr noundef) #2

declare i64 @AsciiStrCmp(ptr noundef, ptr 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, !7, i64 0}
!10 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!11 = !{!10, !7, i64 1}
!12 = !{!13, !14, i64 0}
!13 = !{!"_ISCSI_DRIVER_DATA", !14, i64 0, !6, i64 8, !6, i64 16, !15, i64 24, !6, i64 32, !16, i64 40, !17, i64 104, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_ISCSI_PRIVATE_PROTOCOL", !14, i64 0}
!16 = !{!"_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}
!17 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8}
!18 = !{!13, !6, i64 144}
!19 = !{!20, !6, i64 16}
!20 = !{!"_ISCSI_SESSION", !14, i64 0, !6, i64 8, !6, i64 16, !7, i64 24, !7, i64 32, !7, i64 2120, !7, i64 2121, !21, i64 2128, !14, i64 2132, !14, i64 2136, !14, i64 2140, !14, i64 2144, !21, i64 2148, !22, i64 2152, !14, i64 2168, !22, i64 2176, !21, i64 2192, !14, i64 2196, !7, i64 2200, !7, i64 2201, !14, i64 2204, !14, i64 2208, !14, i64 2212, !14, i64 2216, !21, i64 2220, !7, i64 2222, !7, i64 2223, !7, i64 2224}
!21 = !{!"short", !7, i64 0}
!22 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!23 = !{!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 @IScsiExtScsiPassThruGetTargetLun(ptr noundef %0, ptr noundef %1, ptr noundef readonly %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %1, null
  %6 = icmp eq ptr %2, null
  %or.cond = or i1 %5, %6
  %7 = icmp eq ptr %3, null
  %or.cond3 = or i1 %or.cond, %7
  br i1 %or.cond3, label %35, label %8

8:                                                ; preds = %4
  %9 = load i8, ptr %1, align 1, !tbaa !5
  %.not = icmp eq i8 %9, 3
  br i1 %.not, label %10, label %35

10:                                               ; preds = %8
  %11 = getelementptr inbounds i8, ptr %1, i64 1
  %12 = load i8, ptr %11, align 1, !tbaa !9
  %.not22 = icmp eq i8 %12, 19
  br i1 %.not22, label %13, label %35

13:                                               ; preds = %10
  %14 = tail call i64 @DevicePathNodeLength(ptr noundef nonnull %1) #2
  %15 = icmp ult i64 %14, 19
  br i1 %15, label %35, label %16

16:                                               ; preds = %13
  %17 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not23 = icmp eq i8 %17, 0
  %.pre = ptrtoint ptr %0 to i64
  %.pre26 = add i64 %.pre, -40
  %.pre28 = inttoptr i64 %.pre26 to ptr
  br i1 %.not23, label %._crit_edge, label %18

18:                                               ; preds = %16
  %19 = load i32, ptr %.pre28, align 8, !tbaa !10
  %.not24 = icmp eq i32 %19, 1094996809
  br i1 %.not24, label %._crit_edge, label %20

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

._crit_edge:                                      ; preds = %16, %18, %20
  %21 = phi ptr [ %0, %20 ], [ %.pre28, %18 ], [ %.pre28, %16 ]
  %22 = getelementptr inbounds i8, ptr %21, i64 144
  %23 = load ptr, ptr %22, align 8, !tbaa !17
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  %25 = load ptr, ptr %24, align 8, !tbaa !18
  %26 = load ptr, ptr %2, align 8, !tbaa !22
  %27 = tail call ptr @SetMem(ptr noundef %26, i64 noundef 16, i8 noundef zeroext -1) #2
  %28 = load ptr, ptr %2, align 8, !tbaa !22
  store i8 0, ptr %28, align 1, !tbaa !23
  %29 = getelementptr inbounds i8, ptr %25, i64 308
  %30 = getelementptr inbounds i8, ptr %1, i64 18
  %31 = tail call i64 @AsciiStrCmp(ptr noundef nonnull %29, ptr noundef nonnull %30) #2
  %.not25 = icmp eq i64 %31, 0
  br i1 %.not25, label %32, label %35

32:                                               ; preds = %._crit_edge
  %33 = getelementptr inbounds i8, ptr %25, i64 549
  %34 = tail call ptr @CopyMem(ptr noundef nonnull %3, ptr noundef nonnull %33, i64 noundef 8) #2
  br label %35

35:                                               ; preds = %._crit_edge, %8, %10, %13, %4, %32
  %.0 = phi i64 [ 0, %32 ], [ -9223372036854775806, %4 ], [ -9223372036854775805, %13 ], [ -9223372036854775805, %10 ], [ -9223372036854775805, %8 ], [ -9223372036854775805, %._crit_edge ]
  ret i64 %.0
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

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

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

declare i64 @DevicePathNodeLength(ptr noundef) local_unnamed_addr #1

declare i64 @AsciiStrCmp(ptr noundef, 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!6, !7, i64 1}
!10 = !{!11, !12, i64 0}
!11 = !{!"_ISCSI_DRIVER_DATA", !12, i64 0, !13, i64 8, !13, i64 16, !14, i64 24, !13, i64 32, !15, i64 40, !16, i64 104, !13, i64 120, !13, i64 128, !13, i64 136, !13, i64 144}
!12 = !{!"int", !7, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"_ISCSI_PRIVATE_PROTOCOL", !12, i64 0}
!15 = !{!"_EFI_EXT_SCSI_PASS_THRU_PROTOCOL", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56}
!16 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8}
!17 = !{!11, !13, i64 144}
!18 = !{!19, !13, i64 16}
!19 = !{!"_ISCSI_SESSION", !12, i64 0, !13, i64 8, !13, i64 16, !7, i64 24, !7, i64 32, !7, i64 2120, !7, i64 2121, !20, i64 2128, !12, i64 2132, !12, i64 2136, !12, i64 2140, !12, i64 2144, !20, i64 2148, !21, i64 2152, !12, i64 2168, !21, i64 2176, !20, i64 2192, !12, i64 2196, !7, i64 2200, !7, i64 2201, !12, i64 2204, !12, i64 2208, !12, i64 2212, !12, i64 2216, !20, i64 2220, !7, i64 2222, !7, i64 2223, !7, i64 2224}
!20 = !{!"short", !7, i64 0}
!21 = !{!"_LIST_ENTRY", !13, i64 0, !13, i64 8}
!22 = !{!13, !13, i64 0}
!23 = !{!7, !7, i64 0}


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