; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg (PxeUndiResetNic)

; 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.PXENV_UNDI_OPEN_T = type { i16, i16, i16, %struct.PXENV_UNDI_MCAST_ADDR_T }
%struct.PXENV_UNDI_MCAST_ADDR_T = type { i16, [8 x [16 x i8]] }
%struct.PXENV_UNDI_CLOSE_T = type { i16 }
%struct.PXENV_UNDI_RESET_T = type { i16, %struct.PXENV_UNDI_MCAST_ADDR_T }

declare i64 @MakePxeCall(ptr noundef, ptr noundef, i64 noundef, i16 noundef zeroext) #0

; Function Attrs: nounwind uwtable
define dso_local i64 @PxeUndiResetNic(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i16, align 2
  %8 = alloca %struct.PXENV_UNDI_OPEN_T, align 1
  %9 = alloca %struct.PXENV_UNDI_CLOSE_T, align 1
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i16 %2, ptr %7, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 136, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = call i64 @MakePxeCall(ptr noundef %12, ptr noundef %13, i64 noundef 132, i16 noundef zeroext 4)
  store i64 %14, ptr %10, align 8, !tbaa !11
  %15 = load i64, ptr %10, align 8, !tbaa !11
  %16 = icmp slt i64 %15, 0
  br i1 %16, label %19, label %17

17:                                               ; preds = %3
  %18 = load i64, ptr %10, align 8, !tbaa !11
  store i64 %18, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %48

19:                                               ; preds = %3
  %20 = getelementptr inbounds %struct.PXENV_UNDI_CLOSE_T, ptr %9, i32 0, i32 0
  store i16 0, ptr %20, align 1, !tbaa !13
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = call i64 @MakePxeCall(ptr noundef %21, ptr noundef %9, i64 noundef 2, i16 noundef zeroext 7)
  store i64 %22, ptr %10, align 8, !tbaa !11
  %23 = load i64, ptr %10, align 8, !tbaa !11
  %24 = icmp slt i64 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %19
  store i64 -9223372036854775801, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %48

26:                                               ; preds = %19
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = call i64 @MakePxeCall(ptr noundef %27, ptr noundef %28, i64 noundef 132, i16 noundef zeroext 4)
  store i64 %29, ptr %10, align 8, !tbaa !11
  %30 = load i64, ptr %10, align 8, !tbaa !11
  %31 = icmp slt i64 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %26
  store i64 -9223372036854775801, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %48

33:                                               ; preds = %26
  %34 = getelementptr inbounds %struct.PXENV_UNDI_OPEN_T, ptr %8, i32 0, i32 0
  store i16 0, ptr %34, align 1, !tbaa !15
  %35 = getelementptr inbounds %struct.PXENV_UNDI_OPEN_T, ptr %8, i32 0, i32 1
  store i16 0, ptr %35, align 1, !tbaa !18
  %36 = load i16, ptr %7, align 2, !tbaa !9
  %37 = getelementptr inbounds %struct.PXENV_UNDI_OPEN_T, ptr %8, i32 0, i32 2
  store i16 %36, ptr %37, align 1, !tbaa !19
  %38 = getelementptr inbounds %struct.PXENV_UNDI_OPEN_T, ptr %8, i32 0, i32 3
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.PXENV_UNDI_RESET_T, ptr %39, i32 0, i32 1
  %41 = call ptr @CopyMem(ptr noundef %38, ptr noundef %40, i64 noundef 130)
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = call i64 @MakePxeCall(ptr noundef %42, ptr noundef %8, i64 noundef 136, i16 noundef zeroext 6)
  store i64 %43, ptr %10, align 8, !tbaa !11
  %44 = load i64, ptr %10, align 8, !tbaa !11
  %45 = icmp slt i64 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %33
  store i64 -9223372036854775801, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %48

47:                                               ; preds = %33
  store i64 0, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %48

48:                                               ; preds = %47, %46, %32, %25, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 136, ptr %8) #3
  %49 = load i64, ptr %4, align 8
  ret i64 %49
}

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

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

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

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 = { 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, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"", !10, i64 0}
!15 = !{!16, !10, i64 0}
!16 = !{!"", !10, i64 0, !10, i64 2, !10, i64 4, !17, i64 6}
!17 = !{!"", !10, i64 0, !7, i64 2}
!18 = !{!16, !10, i64 2}
!19 = !{!16, !10, i64 4}


; 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.PXENV_UNDI_OPEN_T = type { i16, i16, i16, %struct.PXENV_UNDI_MCAST_ADDR_T }
%struct.PXENV_UNDI_MCAST_ADDR_T = type { i16, [8 x [16 x i8]] }
%struct.PXENV_UNDI_CLOSE_T = type { i16 }

declare i64 @MakePxeCall(ptr noundef, ptr noundef, i64 noundef, i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775801, -9223372036854775808) i64 @PxeUndiResetNic(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2) local_unnamed_addr #1 {
  %4 = alloca %struct.PXENV_UNDI_OPEN_T, align 2
  %5 = alloca %struct.PXENV_UNDI_CLOSE_T, align 2
  call void @llvm.lifetime.start.p0(i64 136, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %5) #3
  %6 = tail call i64 @MakePxeCall(ptr noundef %0, ptr noundef %1, i64 noundef 132, i16 noundef zeroext 4) #3
  %7 = icmp slt i64 %6, 0
  br i1 %7, label %8, label %22

8:                                                ; preds = %3
  store i16 0, ptr %5, align 2, !tbaa !5
  %9 = call i64 @MakePxeCall(ptr noundef %0, ptr noundef nonnull %5, i64 noundef 2, i16 noundef zeroext 7) #3
  %10 = icmp slt i64 %9, 0
  br i1 %10, label %22, label %11

11:                                               ; preds = %8
  %12 = call i64 @MakePxeCall(ptr noundef %0, ptr noundef %1, i64 noundef 132, i16 noundef zeroext 4) #3
  %13 = icmp slt i64 %12, 0
  br i1 %13, label %22, label %14

14:                                               ; preds = %11
  store i16 0, ptr %4, align 2, !tbaa !10
  %15 = getelementptr inbounds i8, ptr %4, i64 2
  store i16 0, ptr %15, align 2, !tbaa !13
  %16 = getelementptr inbounds i8, ptr %4, i64 4
  store i16 %2, ptr %16, align 2, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %4, i64 6
  %18 = getelementptr inbounds i8, ptr %1, i64 2
  %19 = call ptr @CopyMem(ptr noundef nonnull %17, ptr noundef nonnull %18, i64 noundef 130) #3
  %20 = call i64 @MakePxeCall(ptr noundef %0, ptr noundef nonnull %4, i64 noundef 136, i16 noundef zeroext 6) #3
  %21 = icmp slt i64 %20, 0
  %. = select i1 %21, i64 -9223372036854775801, i64 0
  br label %22

22:                                               ; preds = %14, %11, %8, %3
  %.0 = phi i64 [ %6, %3 ], [ -9223372036854775801, %8 ], [ -9223372036854775801, %11 ], [ %., %14 ]
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 136, ptr nonnull %4) #3
  ret i64 %.0
}

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

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

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

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 = { 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, !7, i64 0}
!6 = !{!"", !7, i64 0}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 0}
!11 = !{!"", !7, i64 0, !7, i64 2, !7, i64 4, !12, i64 6}
!12 = !{!"", !7, i64 0, !8, i64 2}
!13 = !{!11, !7, i64 2}
!14 = !{!11, !7, i64 4}


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