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

; 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_PRIVATE_DATA = type { [223 x i16], %struct._LIST_ENTRY, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, %struct._LIST_ENTRY, [224 x i8], i64, ptr }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.ISCSI_NIC_INFO = type { %struct._LIST_ENTRY, i32, %struct.EFI_MAC_ADDRESS, i8, i16, i64, i64, i64 }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }

@mPrivate = external global ptr, align 8

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

; 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 ptr @IScsiGetNicInfoByIndex(i8 noundef zeroext %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store i8 %0, ptr %3, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %7 = load ptr, ptr @mPrivate, align 8, !tbaa !8
  %8 = getelementptr inbounds %struct.ISCSI_PRIVATE_DATA, ptr %7, i32 0, i32 1
  %9 = getelementptr inbounds %struct._LIST_ENTRY, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !10
  store ptr %10, ptr %4, align 8, !tbaa !8
  br label %11

11:                                               ; preds = %31, %1
  %12 = load ptr, ptr %4, align 8, !tbaa !8
  %13 = load ptr, ptr @mPrivate, align 8, !tbaa !8
  %14 = getelementptr inbounds %struct.ISCSI_PRIVATE_DATA, ptr %13, i32 0, i32 1
  %15 = icmp ne ptr %12, %14
  br i1 %15, label %16, label %35

16:                                               ; preds = %11
  %17 = load ptr, ptr %4, align 8, !tbaa !8
  %18 = ptrtoint ptr %17 to i64
  %19 = sub i64 %18, 0
  %20 = inttoptr i64 %19 to ptr
  store ptr %20, ptr %5, align 8, !tbaa !8
  %21 = load ptr, ptr %5, align 8, !tbaa !8
  %22 = getelementptr inbounds %struct.ISCSI_NIC_INFO, ptr %21, i32 0, i32 3
  %23 = load i8, ptr %22, align 4, !tbaa !14
  %24 = zext i8 %23 to i32
  %25 = load i8, ptr %3, align 1, !tbaa !5
  %26 = zext i8 %25 to i32
  %27 = icmp eq i32 %24, %26
  br i1 %27, label %28, label %30

28:                                               ; preds = %16
  %29 = load ptr, ptr %5, align 8, !tbaa !8
  store ptr %29, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %36

30:                                               ; preds = %16
  br label %31

31:                                               ; preds = %30
  %32 = load ptr, ptr %4, align 8, !tbaa !8
  %33 = getelementptr inbounds %struct._LIST_ENTRY, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !19
  store ptr %34, ptr %4, align 8, !tbaa !8
  br label %11, !llvm.loop !20

35:                                               ; preds = %11
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %36

36:                                               ; preds = %35, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %37 = load ptr, ptr %2, align 8
  ret ptr %37
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !9, i64 448}
!11 = !{!"", !6, i64 0, !12, i64 448, !6, i64 464, !6, i64 465, !6, i64 466, !6, i64 467, !6, i64 468, !6, i64 469, !6, i64 470, !6, i64 471, !6, i64 472, !6, i64 473, !6, i64 474, !6, i64 475, !12, i64 480, !6, i64 496, !13, i64 720, !9, i64 728}
!12 = !{!"_LIST_ENTRY", !9, i64 0, !9, i64 8}
!13 = !{!"long long", !6, i64 0}
!14 = !{!15, !6, i64 52}
!15 = !{!"", !12, i64 0, !16, i64 16, !17, i64 20, !6, i64 52, !18, i64 54, !13, i64 56, !13, i64 64, !13, i64 72}
!16 = !{!"int", !6, i64 0}
!17 = !{!"", !6, i64 0}
!18 = !{!"short", !6, i64 0}
!19 = !{!12, !9, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; 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"

@mPrivate = external local_unnamed_addr global ptr, align 8

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local ptr @IScsiGetNicInfoByIndex(i8 noundef zeroext %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @mPrivate, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 448
  br label %4

4:                                                ; preds = %5, %1
  %.06.in = phi ptr [ %3, %1 ], [ %.06, %5 ]
  %.06 = load ptr, ptr %.06.in, align 8, !tbaa !9
  %.not = icmp eq ptr %.06, %3
  br i1 %.not, label %9, label %5

5:                                                ; preds = %4
  %6 = getelementptr inbounds i8, ptr %.06, i64 52
  %7 = load i8, ptr %6, align 4, !tbaa !11
  %8 = icmp eq i8 %7, %0
  br i1 %8, label %9, label %4, !llvm.loop !17

9:                                                ; preds = %4, %5
  %.0 = phi ptr [ %.06, %5 ], [ null, %4 ]
  ret ptr %.0
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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" }

!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, !6, i64 0}
!10 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!11 = !{!12, !7, i64 52}
!12 = !{!"", !10, i64 0, !13, i64 16, !14, i64 20, !7, i64 52, !15, i64 54, !16, i64 56, !16, i64 64, !16, i64 72}
!13 = !{!"int", !7, i64 0}
!14 = !{!"", !7, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!"long long", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass