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

; 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_COMPONENT_NAME_PROTOCOL = type { ptr, ptr, ptr }
%struct.GUID = type { i32, i16, i16, [8 x i8] }
%struct.EFI_BOOT_SERVICES = type { %struct.EFI_TABLE_HEADER, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }

@gIScsiComponentName = external dso_local global %struct._EFI_COMPONENT_NAME_PROTOCOL, align 8
@gIScsiControllerNameTable = external dso_local global ptr, align 8
@gEfiTcp4ProtocolGuid = external global %struct.GUID, align 4
@gIScsiV4PrivateGuid = external global %struct.GUID, align 4
@gEfiTcp6ProtocolGuid = external global %struct.GUID, align 4
@gIScsiV6PrivateGuid = external global %struct.GUID, align 4
@gBS = external global ptr, align 8
@gEfiExtScsiPassThruProtocolGuid = external global %struct.GUID, align 4

; Function Attrs: nounwind uwtable
define dso_local i64 @IScsiComponentNameGetControllerName(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca i64, 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 i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i8, align 1
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %5
  store i64 -9223372036854775805, ptr %6, align 8
  store i32 1, ptr %18, align 4
  br label %102

22:                                               ; preds = %5
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = call ptr @NetLibGetNicHandle(ptr noundef %23, ptr noundef @gEfiTcp4ProtocolGuid)
  store ptr %24, ptr %13, align 8, !tbaa !5
  %25 = load ptr, ptr %13, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %28

27:                                               ; preds = %22
  store ptr @gIScsiV4PrivateGuid, ptr %15, align 8, !tbaa !5
  store i8 0, ptr %14, align 1, !tbaa !9
  br label %36

28:                                               ; preds = %22
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = call ptr @NetLibGetNicHandle(ptr noundef %29, ptr noundef @gEfiTcp6ProtocolGuid)
  store ptr %30, ptr %13, align 8, !tbaa !5
  %31 = load ptr, ptr %13, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %34

33:                                               ; preds = %28
  store ptr @gIScsiV6PrivateGuid, ptr %15, align 8, !tbaa !5
  store i8 1, ptr %14, align 1, !tbaa !9
  br label %35

34:                                               ; preds = %28
  store i64 -9223372036854775805, ptr %6, align 8
  store i32 1, ptr %18, align 4
  br label %102

35:                                               ; preds = %33
  br label %36

36:                                               ; preds = %35, %27
  %37 = load ptr, ptr @gBS, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %37, i32 0, i32 33
  %39 = load ptr, ptr %38, align 8, !tbaa !10
  %40 = load ptr, ptr %13, align 8, !tbaa !5
  %41 = load ptr, ptr %15, align 8, !tbaa !5
  %42 = call i64 %39(ptr noundef %40, ptr noundef %41, ptr noundef %16, ptr noundef null, ptr noundef null, i32 noundef 2)
  store i64 %42, ptr %12, align 8, !tbaa !15
  %43 = load i64, ptr %12, align 8, !tbaa !15
  %44 = icmp slt i64 %43, 0
  br i1 %44, label %45, label %47

45:                                               ; preds = %36
  %46 = load i64, ptr %12, align 8, !tbaa !15
  store i64 %46, ptr %6, align 8
  store i32 1, ptr %18, align 4
  br label %102

47:                                               ; preds = %36
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %90

50:                                               ; preds = %47
  %51 = load i8, ptr %14, align 1, !tbaa !9
  %52 = icmp ne i8 %51, 0
  br i1 %52, label %62, label %53

53:                                               ; preds = %50
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = call i64 @EfiTestChildHandle(ptr noundef %54, ptr noundef %55, ptr noundef @gEfiTcp4ProtocolGuid)
  store i64 %56, ptr %12, align 8, !tbaa !15
  %57 = load i64, ptr %12, align 8, !tbaa !15
  %58 = icmp slt i64 %57, 0
  br i1 %58, label %59, label %61

59:                                               ; preds = %53
  %60 = load i64, ptr %12, align 8, !tbaa !15
  store i64 %60, ptr %6, align 8
  store i32 1, ptr %18, align 4
  br label %102

61:                                               ; preds = %53
  br label %71

62:                                               ; preds = %50
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = call i64 @EfiTestChildHandle(ptr noundef %63, ptr noundef %64, ptr noundef @gEfiTcp6ProtocolGuid)
  store i64 %65, ptr %12, align 8, !tbaa !15
  %66 = load i64, ptr %12, align 8, !tbaa !15
  %67 = icmp slt i64 %66, 0
  br i1 %67, label %68, label %70

68:                                               ; preds = %62
  %69 = load i64, ptr %12, align 8, !tbaa !15
  store i64 %69, ptr %6, align 8
  store i32 1, ptr %18, align 4
  br label %102

70:                                               ; preds = %62
  br label %71

71:                                               ; preds = %70, %61
  %72 = load ptr, ptr @gBS, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %72, i32 0, i32 33
  %74 = load ptr, ptr %73, align 8, !tbaa !10
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  %76 = call i64 %74(ptr noundef %75, ptr noundef @gEfiExtScsiPassThruProtocolGuid, ptr noundef %17, ptr noundef null, ptr noundef null, i32 noundef 2)
  store i64 %76, ptr %12, align 8, !tbaa !15
  %77 = load i64, ptr %12, align 8, !tbaa !15
  %78 = icmp slt i64 %77, 0
  br i1 %78, label %79, label %81

79:                                               ; preds = %71
  %80 = load i64, ptr %12, align 8, !tbaa !15
  store i64 %80, ptr %6, align 8
  store i32 1, ptr %18, align 4
  br label %102

81:                                               ; preds = %71
  %82 = load ptr, ptr %17, align 8, !tbaa !5
  %83 = load i8, ptr %14, align 1, !tbaa !9
  %84 = call i64 @UpdateName(ptr noundef %82, i8 noundef zeroext %83)
  store i64 %84, ptr %12, align 8, !tbaa !15
  %85 = load i64, ptr %12, align 8, !tbaa !15
  %86 = icmp slt i64 %85, 0
  br i1 %86, label %87, label %89

87:                                               ; preds = %81
  %88 = load i64, ptr %12, align 8, !tbaa !15
  store i64 %88, ptr %6, align 8
  store i32 1, ptr %18, align 4
  br label %102

89:                                               ; preds = %81
  br label %90

90:                                               ; preds = %89, %47
  %91 = load ptr, ptr %10, align 8, !tbaa !5
  %92 = load ptr, ptr %7, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct._EFI_COMPONENT_NAME_PROTOCOL, ptr %92, i32 0, i32 2
  %94 = load ptr, ptr %93, align 8, !tbaa !16
  %95 = load ptr, ptr @gIScsiControllerNameTable, align 8, !tbaa !5
  %96 = load ptr, ptr %11, align 8, !tbaa !5
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  %98 = icmp eq ptr %97, @gIScsiComponentName
  %99 = zext i1 %98 to i32
  %100 = trunc i32 %99 to i8
  %101 = call i64 @LookupUnicodeString2(ptr noundef %91, ptr noundef %94, ptr noundef %95, ptr noundef %96, i8 noundef zeroext %100)
  store i64 %101, ptr %6, align 8
  store i32 1, ptr %18, align 4
  br label %102

102:                                              ; preds = %90, %87, %79, %68, %59, %45, %34, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %103 = load i64, ptr %6, align 8
  ret i64 %103
}

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @UpdateName(ptr noundef, i8 noundef zeroext) #0

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

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

declare ptr @NetLibGetNicHandle(ptr noundef, ptr noundef) #1

declare i64 @EfiTestChildHandle(ptr noundef, ptr noundef, ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 280}
!11 = !{!"", !12, i64 0, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}
!12 = !{!"", !13, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!13, !13, i64 0}
!16 = !{!17, !6, i64 16}
!17 = !{!"_EFI_COMPONENT_NAME_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16}


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

%struct._EFI_COMPONENT_NAME_PROTOCOL = type { ptr, ptr, ptr }
%struct.GUID = type { i32, i16, i16, [8 x i8] }

@gIScsiComponentName = external dso_local global %struct._EFI_COMPONENT_NAME_PROTOCOL, align 8
@gIScsiControllerNameTable = external dso_local local_unnamed_addr global ptr, align 8
@gEfiTcp4ProtocolGuid = external global %struct.GUID, align 4
@gIScsiV4PrivateGuid = external global %struct.GUID, align 4
@gEfiTcp6ProtocolGuid = external global %struct.GUID, align 4
@gIScsiV6PrivateGuid = external global %struct.GUID, align 4
@gBS = external local_unnamed_addr global ptr, align 8
@gEfiExtScsiPassThruProtocolGuid = external global %struct.GUID, align 4

; Function Attrs: nounwind uwtable
define dso_local i64 @IScsiComponentNameGetControllerName(ptr noundef readonly %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #3
  %8 = icmp eq ptr %1, null
  br i1 %8, label %44, label %9

9:                                                ; preds = %5
  %10 = tail call ptr @NetLibGetNicHandle(ptr noundef nonnull %1, ptr noundef nonnull @gEfiTcp4ProtocolGuid) #3
  %.not.not = icmp eq ptr %10, null
  br i1 %.not.not, label %11, label %13

11:                                               ; preds = %9
  %12 = tail call ptr @NetLibGetNicHandle(ptr noundef nonnull %1, ptr noundef nonnull @gEfiTcp6ProtocolGuid) #3
  %.not41 = icmp eq ptr %12, null
  br i1 %.not41, label %44, label %13

13:                                               ; preds = %11, %9
  %.030 = phi ptr [ %10, %9 ], [ %12, %11 ]
  %.029 = phi i8 [ 0, %9 ], [ 1, %11 ]
  %.0 = phi ptr [ @gIScsiV4PrivateGuid, %9 ], [ @gIScsiV6PrivateGuid, %11 ]
  %14 = load ptr, ptr @gBS, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 280
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = call i64 %16(ptr noundef nonnull %.030, ptr noundef nonnull %.0, ptr noundef nonnull %6, ptr noundef null, ptr noundef null, i32 noundef 2) #3
  %18 = icmp slt i64 %17, 0
  br i1 %18, label %44, label %19

19:                                               ; preds = %13
  %.not42 = icmp eq ptr %2, null
  br i1 %.not42, label %37, label %20

20:                                               ; preds = %19
  br i1 %.not.not, label %24, label %21

21:                                               ; preds = %20
  %22 = call i64 @EfiTestChildHandle(ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull @gEfiTcp4ProtocolGuid) #3
  %23 = icmp slt i64 %22, 0
  br i1 %23, label %44, label %27

24:                                               ; preds = %20
  %25 = call i64 @EfiTestChildHandle(ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull @gEfiTcp6ProtocolGuid) #3
  %26 = icmp slt i64 %25, 0
  br i1 %26, label %44, label %27

27:                                               ; preds = %24, %21
  %28 = load ptr, ptr @gBS, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 280
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  %31 = call i64 %30(ptr noundef nonnull %2, ptr noundef nonnull @gEfiExtScsiPassThruProtocolGuid, ptr noundef nonnull %7, ptr noundef null, ptr noundef null, i32 noundef 2) #3
  %32 = icmp slt i64 %31, 0
  br i1 %32, label %44, label %33

33:                                               ; preds = %27
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = call i64 @UpdateName(ptr noundef %34, i8 noundef zeroext %.029)
  %36 = icmp slt i64 %35, 0
  br i1 %36, label %44, label %37

37:                                               ; preds = %33, %19
  %38 = getelementptr inbounds i8, ptr %0, i64 16
  %39 = load ptr, ptr %38, align 8, !tbaa !14
  %40 = load ptr, ptr @gIScsiControllerNameTable, align 8, !tbaa !5
  %41 = icmp eq ptr %0, @gIScsiComponentName
  %42 = zext i1 %41 to i8
  %43 = call i64 @LookupUnicodeString2(ptr noundef %3, ptr noundef %39, ptr noundef %40, ptr noundef %4, i8 noundef zeroext %42) #3
  br label %44

44:                                               ; preds = %33, %27, %24, %21, %13, %11, %5, %37
  %.031 = phi i64 [ %43, %37 ], [ -9223372036854775805, %5 ], [ -9223372036854775805, %11 ], [ %17, %13 ], [ %22, %21 ], [ %25, %24 ], [ %31, %27 ], [ %35, %33 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  ret i64 %.031
}

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @UpdateName(ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

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

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

declare ptr @NetLibGetNicHandle(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i64 @EfiTestChildHandle(ptr noundef, 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 280}
!10 = !{!"", !11, i64 0, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}
!11 = !{!"", !12, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !6, i64 16}
!15 = !{!"_EFI_COMPONENT_NAME_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16}


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