; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal (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, 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 }

@.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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare zeroext i8 @DebugAssertEnabled() #1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @IScsiExtScsiPassThruGetTargetLun(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %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 %84

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 %84

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 6) 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 295, 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 6) 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 = getelementptr inbounds %struct._ISCSI_SESSION, ptr %61, i32 0, i32 1
  %63 = getelementptr inbounds %struct._ISCSI_SESSION_CONFIG_DATA, ptr %62, i32 0, i32 0
  store ptr %63, ptr %11, align 8, !tbaa !5
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = load ptr, ptr %64, align 8, !tbaa !5
  %66 = call ptr @SetMem(ptr noundef %65, i64 noundef 16, i8 noundef zeroext -1)
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = load ptr, ptr %67, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %68, i64 0
  store i8 0, ptr %69, align 1, !tbaa !27
  %70 = load ptr, ptr %11, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.ISCSI_SESSION_CONFIG_NVDATA, ptr %70, i32 0, i32 6
  %72 = getelementptr inbounds [224 x i8], ptr %71, i64 0, i64 0
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = getelementptr inbounds i8, ptr %73, i64 18
  %75 = call i64 @AsciiStrCmp(ptr noundef %72, ptr noundef %74)
  %76 = icmp ne i64 %75, 0
  br i1 %76, label %77, label %78

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

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

84:                                               ; preds = %78, %77, %38, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %85 = load i64, ptr %5, align 8
  ret i64 %85
}

declare i64 @DevicePathNodeLength(ptr noundef) #1

declare i64 @AsciiStrCmp(ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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, !6, i64 40, !16, i64 48, !17, i64 112, !6, i64 128, !6, i64 136, !18, 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 = !{!"_ISCSI_SESSION", !14, i64 0, !19, i64 4, !23, i64 276, !7, i64 2648, !25, i64 2872, !7, i64 2880, !7, i64 2881, !22, i64 2888, !14, i64 2892, !14, i64 2896, !14, i64 2900, !14, i64 2904, !22, i64 2908, !26, i64 2912, !14, i64 2928, !26, i64 2936, !22, i64 2952, !14, i64 2956, !7, i64 2960, !7, i64 2961, !14, i64 2964, !14, i64 2968, !14, i64 2972, !14, i64 2976, !22, i64 2980, !7, i64 2982, !7, i64 2983, !7, i64 2984}
!19 = !{!"_ISCSI_SESSION_CONFIG_DATA", !20, i64 0, !21, i64 259, !21, i64 263, !21, i64 267}
!20 = !{!"", !7, i64 0, !7, i64 1, !21, i64 2, !21, i64 6, !21, i64 10, !7, i64 14, !7, i64 15, !21, i64 239, !22, i64 243, !7, i64 245, !7, i64 253}
!21 = !{!"", !7, i64 0}
!22 = !{!"short", !7, i64 0}
!23 = !{!"_ISCSI_CHAP_AUTH_DATA", !24, i64 0, !14, i64 292, !7, i64 296, !14, i64 1320, !7, i64 1324, !14, i64 1340, !7, i64 1344, !14, i64 2368}
!24 = !{!"_ISCSI_CHAP_AUTH_CONFIG_NVDATA", !7, i64 0, !7, i64 1, !7, i64 128, !7, i64 145, !7, i64 272}
!25 = !{!"long long", !7, i64 0}
!26 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!27 = !{!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 [164 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

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

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

; 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 #1 {
  %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 %31, 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 %31

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 %31

13:                                               ; preds = %10
  %14 = tail call i64 @DevicePathNodeLength(ptr noundef nonnull %1) #2
  %15 = icmp ult i64 %14, 19
  br i1 %15, label %31, 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, -48
  %.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 295, 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 = load ptr, ptr %2, align 8, !tbaa !26
  %23 = tail call ptr @SetMem(ptr noundef %22, i64 noundef 16, i8 noundef zeroext -1) #2
  %24 = load ptr, ptr %2, align 8, !tbaa !26
  store i8 0, ptr %24, align 1, !tbaa !27
  %25 = getelementptr inbounds i8, ptr %21, i64 163
  %26 = getelementptr inbounds i8, ptr %1, i64 18
  %27 = tail call i64 @AsciiStrCmp(ptr noundef nonnull %25, ptr noundef nonnull %26) #2
  %.not25 = icmp eq i64 %27, 0
  br i1 %.not25, label %28, label %31

28:                                               ; preds = %._crit_edge
  %29 = getelementptr inbounds i8, ptr %21, i64 393
  %30 = tail call ptr @CopyMem(ptr noundef nonnull %3, ptr noundef nonnull %29, i64 noundef 8) #2
  br label %31

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

declare i64 @DevicePathNodeLength(ptr noundef) local_unnamed_addr #0

declare i64 @AsciiStrCmp(ptr noundef, ptr noundef) local_unnamed_addr #0

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, !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, !13, i64 40, !15, i64 48, !16, i64 112, !13, i64 128, !13, i64 136, !17, 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 = !{!"_ISCSI_SESSION", !12, i64 0, !18, i64 4, !22, i64 276, !7, i64 2648, !24, i64 2872, !7, i64 2880, !7, i64 2881, !21, i64 2888, !12, i64 2892, !12, i64 2896, !12, i64 2900, !12, i64 2904, !21, i64 2908, !25, i64 2912, !12, i64 2928, !25, i64 2936, !21, i64 2952, !12, i64 2956, !7, i64 2960, !7, i64 2961, !12, i64 2964, !12, i64 2968, !12, i64 2972, !12, 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, !12, i64 292, !7, i64 296, !12, i64 1320, !7, i64 1324, !12, i64 1340, !7, i64 1344, !12, i64 2368}
!23 = !{!"_ISCSI_CHAP_AUTH_CONFIG_NVDATA", !7, i64 0, !7, i64 1, !7, i64 128, !7, i64 145, !7, i64 272}
!24 = !{!"long long", !7, i64 0}
!25 = !{!"_LIST_ENTRY", !13, i64 0, !13, i64 8}
!26 = !{!13, !13, i64 0}
!27 = !{!7, !7, i64 0}


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