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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @IScsiExtScsiPassThruGetNextTargetLun(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %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 6) 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 135, 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 6) 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 = getelementptr inbounds %struct._ISCSI_SESSION, ptr %33, i32 0, i32 1
  %35 = getelementptr inbounds %struct._ISCSI_SESSION_CONFIG_DATA, ptr %34, i32 0, i32 0
  store ptr %35, ptr %9, align 8, !tbaa !5
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 0
  %39 = load i8, ptr %38, align 1, !tbaa !24
  %40 = zext i8 %39 to i32
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %42, label %50

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

49:                                               ; preds = %42
  store i64 -9223372036854775794, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %68

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

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

67:                                               ; preds = %50
  store i64 -9223372036854775806, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %68

68:                                               ; preds = %67, %58, %49
  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
  %69 = load i64, ptr %4, align 8
  ret i64 %69
}

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

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

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

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

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

; 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 #2 {
  %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, -48
  %.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 135, 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 = load ptr, ptr %1, align 8, !tbaa !23
  %11 = load i8, ptr %10, align 1, !tbaa !24
  %12 = icmp eq i8 %11, 0
  br i1 %12, label %13, label %17

13:                                               ; preds = %._crit_edge
  %14 = getelementptr inbounds i8, ptr %9, i64 393
  %15 = tail call i64 @CompareMem(ptr noundef %2, ptr noundef nonnull %14, i64 noundef 8) #3
  %16 = icmp eq i64 %15, 0
  br i1 %16, label %26, label %17

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

22:                                               ; preds = %17
  %23 = load ptr, ptr %1, align 8, !tbaa !23
  store i8 0, ptr %23, align 1, !tbaa !24
  %24 = getelementptr inbounds i8, ptr %9, i64 393
  %25 = call ptr @CopyMem(ptr noundef %2, ptr noundef nonnull %24, i64 noundef 8) #3
  br label %26

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

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

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


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