; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal (IScsiDhcpIsConfigured)

; 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.GUID = type { i32, i16, i16, [8 x i8] }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }
%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] }

@gEfiIScsiInitiatorNameProtocolGuid = external global %struct.GUID, align 4

; 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
declare dso_local void @IScsiMacAddrToStr(ptr noundef, i32 noundef, i16 noundef zeroext, ptr noundef) #1

declare void @FreePool(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @IScsiDhcpIsConfigured(ptr noundef %0) #1 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca %struct.EFI_MAC_ADDRESS, align 1
  %6 = alloca i64, align 8
  %7 = alloca i16, align 2
  %8 = alloca [70 x i16], align 16
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 140, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = call i64 @NetLibGetMacAddress(ptr noundef %11, ptr noundef %5, ptr noundef %6)
  store i64 %12, ptr %4, align 8, !tbaa !9
  %13 = load i64, ptr %4, align 8, !tbaa !9
  %14 = icmp slt i64 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %1
  store i8 0, ptr %2, align 1
  store i32 1, ptr %10, align 4
  br label %47

16:                                               ; preds = %1
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = call zeroext i16 @NetLibGetVlanId(ptr noundef %17)
  store i16 %18, ptr %7, align 2, !tbaa !11
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = trunc i64 %19 to i32
  %21 = load i16, ptr %7, align 2, !tbaa !11
  %22 = getelementptr inbounds [70 x i16], ptr %8, i64 0, i64 0
  call void @IScsiMacAddrToStr(ptr noundef %5, i32 noundef %20, i16 noundef zeroext %21, ptr noundef %22)
  %23 = getelementptr inbounds [70 x i16], ptr %8, i64 0, i64 0
  %24 = call i64 @GetVariable2(ptr noundef %23, ptr noundef @gEfiIScsiInitiatorNameProtocolGuid, ptr noundef %9, ptr noundef null)
  store i64 %24, ptr %4, align 8, !tbaa !9
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %30, label %27

27:                                               ; preds = %16
  %28 = load i64, ptr %4, align 8, !tbaa !9
  %29 = icmp slt i64 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %27, %16
  store i8 0, ptr %2, align 1
  store i32 1, ptr %10, align 4
  br label %47

31:                                               ; preds = %27
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.ISCSI_SESSION_CONFIG_NVDATA, ptr %32, i32 0, i32 0
  %34 = load i8, ptr %33, align 1, !tbaa !13
  %35 = zext i8 %34 to i32
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %45

37:                                               ; preds = %31
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ISCSI_SESSION_CONFIG_NVDATA, ptr %38, i32 0, i32 1
  %40 = load i8, ptr %39, align 1, !tbaa !16
  %41 = zext i8 %40 to i32
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %45

43:                                               ; preds = %37
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  call void @FreePool(ptr noundef %44)
  store i8 1, ptr %2, align 1
  store i32 1, ptr %10, align 4
  br label %47

45:                                               ; preds = %37, %31
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  call void @FreePool(ptr noundef %46)
  store i8 0, ptr %2, align 1
  store i32 1, ptr %10, align 4
  br label %47

47:                                               ; preds = %45, %43, %30, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 140, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %48 = load i8, ptr %2, align 1
  ret i8 %48
}

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

declare zeroext i16 @NetLibGetVlanId(ptr noundef) #2

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

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 = { "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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !7, i64 0}
!14 = !{!"", !7, i64 0, !7, i64 1, !15, i64 2, !15, i64 6, !15, i64 10, !7, i64 14, !7, i64 15, !15, i64 239, !12, i64 243, !7, i64 245, !7, i64 253}
!15 = !{!"", !7, i64 0}
!16 = !{!14, !7, i64 1}


; 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.GUID = type { i32, i16, i16, [8 x i8] }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }

@gEfiIScsiInitiatorNameProtocolGuid = external global %struct.GUID, align 4

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

; 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
declare dso_local void @IScsiMacAddrToStr(ptr noundef, i32 noundef, i16 noundef zeroext, ptr noundef) local_unnamed_addr #1

declare void @FreePool(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @IScsiDhcpIsConfigured(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca %struct.EFI_MAC_ADDRESS, align 1
  %3 = alloca i64, align 8
  %4 = alloca [70 x i16], align 16
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 140, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %6 = call i64 @NetLibGetMacAddress(ptr noundef %0, ptr noundef nonnull %2, ptr noundef nonnull %3) #3
  %7 = icmp slt i64 %6, 0
  br i1 %7, label %22, label %8

8:                                                ; preds = %1
  %9 = call zeroext i16 @NetLibGetVlanId(ptr noundef %0) #3
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = trunc i64 %10 to i32
  call void @IScsiMacAddrToStr(ptr noundef nonnull %2, i32 noundef %11, i16 noundef zeroext %9, ptr noundef nonnull %4)
  %12 = call i64 @GetVariable2(ptr noundef nonnull %4, ptr noundef nonnull @gEfiIScsiInitiatorNameProtocolGuid, ptr noundef nonnull %5, ptr noundef null) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !9
  %14 = icmp eq ptr %13, null
  %15 = icmp slt i64 %12, 0
  %or.cond = select i1 %14, i1 true, i1 %15
  br i1 %or.cond, label %22, label %16

16:                                               ; preds = %8
  %17 = load i8, ptr %13, align 1, !tbaa !11
  %.not = icmp eq i8 %17, 0
  br i1 %.not, label %21, label %18

18:                                               ; preds = %16
  %19 = getelementptr inbounds i8, ptr %13, i64 1
  %20 = load i8, ptr %19, align 1, !tbaa !15
  %.not7 = icmp eq i8 %20, 0
  br i1 %.not7, label %21, label %.sink.split

21:                                               ; preds = %18, %16
  br label %.sink.split

.sink.split:                                      ; preds = %18, %21
  %.0.ph = phi i8 [ 0, %21 ], [ 1, %18 ]
  call void @FreePool(ptr noundef nonnull %13) #3
  br label %22

22:                                               ; preds = %.sink.split, %8, %1
  %.0 = phi i8 [ 0, %1 ], [ 0, %8 ], [ %.0.ph, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 140, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #3
  ret i8 %.0
}

declare i64 @NetLibGetMacAddress(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare zeroext i16 @NetLibGetVlanId(ptr noundef) local_unnamed_addr #2

declare i64 @GetVariable2(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { "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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"", !7, i64 0, !7, i64 1, !13, i64 2, !13, i64 6, !13, i64 10, !7, i64 14, !7, i64 15, !13, i64 239, !14, i64 243, !7, i64 245, !7, i64 253}
!13 = !{!"", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!12, !7, i64 1}


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