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

; 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._MTFTP4_SERVICE = type { i32, %struct._EFI_SERVICE_BINDING_PROTOCOL, i16, %struct._LIST_ENTRY, ptr, ptr, ptr, ptr, ptr }
%struct._EFI_SERVICE_BINDING_PROTOCOL = type { ptr, ptr }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct._MTFTP4_PROTOCOL = type { i32, %struct._LIST_ENTRY, %struct._EFI_MTFTP4_PROTOCOL, i64, i8, ptr, ptr, %struct.EFI_MTFTP4_CONFIG_DATA, ptr, %struct.MTFTP4_OPTION, i16, i16, i16, %struct._LIST_ENTRY, i32, i16, i16, i32, ptr, ptr, i32, i32, i32, i32, i32, i16, i8, ptr }
%struct._EFI_MTFTP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_MTFTP4_CONFIG_DATA = type { i8, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i16, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i16, i16, i16 }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }
%struct.MTFTP4_OPTION = type { i16, i8, i32, i32, i16, i8, i32 }
%struct._EFI_MTFTP4_TOKEN = type { i64, ptr, ptr, ptr, ptr, i32, ptr, i64, ptr, ptr, ptr, ptr, ptr }

@.str.6 = external hidden unnamed_addr constant [38 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

; 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 i64 @Mtftp4SendError(ptr noundef, i16 noundef zeroext, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @Mtftp4SetTimeout(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @Mtftp4Retransmit(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @Mtftp4OnTimerTick(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, 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
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %10, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._MTFTP4_SERVICE, ptr %11, i32 0, i32 3
  %13 = getelementptr inbounds %struct._LIST_ENTRY, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %14, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._LIST_ENTRY, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  store ptr %17, ptr %7, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %76, %2
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._MTFTP4_SERVICE, ptr %20, i32 0, i32 3
  %22 = icmp ne ptr %19, %21
  br i1 %22, label %23, label %81

23:                                               ; preds = %18
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = ptrtoint ptr %24 to i64
  %26 = sub i64 %25, ptrtoint (ptr getelementptr inbounds (%struct._MTFTP4_PROTOCOL, ptr null, i32 0, i32 1) to i64)
  %27 = inttoptr i64 %26 to ptr
  store ptr %27, ptr %8, align 8, !tbaa !5
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %28, i32 0, i32 20
  %30 = load i32, ptr %29, align 8, !tbaa !16
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %38, label %32

32:                                               ; preds = %23
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %33, i32 0, i32 20
  %35 = load i32, ptr %34, align 8, !tbaa !16
  %36 = add i32 %35, -1
  store i32 %36, ptr %34, align 8, !tbaa !16
  %37 = icmp ugt i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %32, %23
  br label %76

39:                                               ; preds = %32
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %40, i32 0, i32 8
  %42 = load ptr, ptr %41, align 8, !tbaa !23
  store ptr %42, ptr %9, align 8, !tbaa !5
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct._EFI_MTFTP4_TOKEN, ptr %43, i32 0, i32 11
  %45 = load ptr, ptr %44, align 8, !tbaa !24
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %60

47:                                               ; preds = %39
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct._EFI_MTFTP4_TOKEN, ptr %48, i32 0, i32 11
  %50 = load ptr, ptr %49, align 8, !tbaa !24
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = call i64 %50(ptr noundef %52, ptr noundef %53)
  %55 = icmp slt i64 %54, 0
  br i1 %55, label %56, label %60

56:                                               ; preds = %47
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = call i64 @Mtftp4SendError(ptr noundef %57, i16 noundef zeroext 8, ptr noundef @.str.6)
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  call void @Mtftp4CleanOperation(ptr noundef %59, i64 noundef -9223372036854775787)
  br label %76

60:                                               ; preds = %47, %39
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %61, i32 0, i32 21
  %63 = load i32, ptr %62, align 4, !tbaa !26
  %64 = add i32 %63, 1
  store i32 %64, ptr %62, align 4, !tbaa !26
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %65, i32 0, i32 22
  %67 = load i32, ptr %66, align 8, !tbaa !27
  %68 = icmp ult i32 %64, %67
  br i1 %68, label %69, label %73

69:                                               ; preds = %60
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = call i64 @Mtftp4Retransmit(ptr noundef %70)
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  call void @Mtftp4SetTimeout(ptr noundef %72)
  br label %75

73:                                               ; preds = %60
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  call void @Mtftp4CleanOperation(ptr noundef %74, i64 noundef -9223372036854775790)
  br label %76

75:                                               ; preds = %69
  br label %76

76:                                               ; preds = %75, %73, %56, %38
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %77, ptr %6, align 8, !tbaa !5
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct._LIST_ENTRY, ptr %78, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8, !tbaa !15
  store ptr %80, ptr %7, align 8, !tbaa !5
  br label %18, !llvm.loop !28

81:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

declare void @Mtftp4CleanOperation(ptr noundef, i64 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, !6, i64 32}
!10 = !{!"_MTFTP4_SERVICE", !11, i64 0, !12, i64 8, !13, i64 24, !14, i64 32, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !6, i64 0, !6, i64 8}
!13 = !{!"short", !7, i64 0}
!14 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!15 = !{!14, !6, i64 0}
!16 = !{!17, !11, i64 240}
!17 = !{!"_MTFTP4_PROTOCOL", !11, i64 0, !14, i64 8, !18, i64 24, !19, i64 88, !7, i64 96, !6, i64 104, !6, i64 112, !20, i64 120, !6, i64 152, !22, i64 160, !13, i64 180, !13, i64 182, !13, i64 184, !14, i64 192, !11, i64 208, !13, i64 212, !13, i64 214, !11, i64 216, !6, i64 224, !6, i64 232, !11, i64 240, !11, i64 244, !11, i64 248, !11, i64 252, !11, i64 256, !13, i64 260, !7, i64 262, !6, i64 264}
!18 = !{!"_EFI_MTFTP4_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}
!19 = !{!"long long", !7, i64 0}
!20 = !{!"", !7, i64 0, !21, i64 1, !21, i64 5, !13, i64 10, !21, i64 12, !21, i64 16, !13, i64 20, !13, i64 22, !13, i64 24}
!21 = !{!"", !7, i64 0}
!22 = !{!"", !13, i64 0, !7, i64 2, !11, i64 4, !11, i64 8, !13, i64 12, !7, i64 14, !11, i64 16}
!23 = !{!17, !6, i64 152}
!24 = !{!25, !6, i64 88}
!25 = !{!"_EFI_MTFTP4_TOKEN", !19, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !6, i64 48, !19, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96}
!26 = !{!17, !11, i64 244}
!27 = !{!17, !11, i64 248}
!28 = distinct !{!28, !29}
!29 = !{!"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"

@.str.6 = external hidden unnamed_addr constant [38 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local void @Mtftp4SetTimeout(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @Mtftp4Retransmit(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @Mtftp4OnTimerTick(ptr nocapture noundef readnone %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 32
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not28 = icmp eq ptr %4, %3
  br i1 %.not28, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %34
  %.029 = phi ptr [ %.02230, %34 ], [ %4, %2 ]
  %.02230 = load ptr, ptr %.029, align 8, !tbaa !14
  %5 = ptrtoint ptr %.029 to i64
  %6 = add i64 %5, -8
  %7 = inttoptr i64 %6 to ptr
  %8 = getelementptr inbounds i8, ptr %7, i64 240
  %9 = load i32, ptr %8, align 8, !tbaa !15
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %34, label %11

11:                                               ; preds = %.lr.ph
  %12 = add i32 %9, -1
  store i32 %12, ptr %8, align 8, !tbaa !15
  %.not25 = icmp eq i32 %12, 0
  br i1 %.not25, label %13, label %34

13:                                               ; preds = %11
  %14 = getelementptr inbounds i8, ptr %7, i64 152
  %15 = load ptr, ptr %14, align 8, !tbaa !22
  %16 = getelementptr inbounds i8, ptr %15, i64 88
  %17 = load ptr, ptr %16, align 8, !tbaa !23
  %.not26 = icmp eq ptr %17, null
  br i1 %.not26, label %24, label %18

18:                                               ; preds = %13
  %19 = getelementptr inbounds i8, ptr %7, i64 24
  %20 = tail call i64 %17(ptr noundef nonnull %19, ptr noundef nonnull %15) #2
  %21 = icmp slt i64 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %18
  %23 = tail call i64 @Mtftp4SendError(ptr noundef nonnull %7, i16 noundef zeroext 8, ptr noundef nonnull @.str.6)
  tail call void @Mtftp4CleanOperation(ptr noundef nonnull %7, i64 noundef -9223372036854775787) #2
  br label %34

24:                                               ; preds = %18, %13
  %25 = getelementptr inbounds i8, ptr %7, i64 244
  %26 = load i32, ptr %25, align 4, !tbaa !25
  %27 = add i32 %26, 1
  store i32 %27, ptr %25, align 4, !tbaa !25
  %28 = getelementptr inbounds i8, ptr %7, i64 248
  %29 = load i32, ptr %28, align 8, !tbaa !26
  %30 = icmp ult i32 %27, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %24
  %32 = tail call i64 @Mtftp4Retransmit(ptr noundef nonnull %7)
  tail call void @Mtftp4SetTimeout(ptr noundef nonnull %7)
  br label %34

33:                                               ; preds = %24
  tail call void @Mtftp4CleanOperation(ptr noundef nonnull %7, i64 noundef -9223372036854775790) #2
  br label %34

34:                                               ; preds = %.lr.ph, %11, %31, %33, %22
  %.not = icmp eq ptr %.02230, %3
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !27

._crit_edge:                                      ; preds = %34, %2
  ret void
}

declare void @Mtftp4CleanOperation(ptr noundef, i64 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 = { 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, !11, i64 32}
!6 = !{!"_MTFTP4_SERVICE", !7, i64 0, !10, i64 8, !12, i64 24, !13, i64 32, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!"_LIST_ENTRY", !11, i64 0, !11, i64 8}
!14 = !{!13, !11, i64 0}
!15 = !{!16, !7, i64 240}
!16 = !{!"_MTFTP4_PROTOCOL", !7, i64 0, !13, i64 8, !17, i64 24, !18, i64 88, !8, i64 96, !11, i64 104, !11, i64 112, !19, i64 120, !11, i64 152, !21, i64 160, !12, i64 180, !12, i64 182, !12, i64 184, !13, i64 192, !7, i64 208, !12, i64 212, !12, i64 214, !7, i64 216, !11, i64 224, !11, i64 232, !7, i64 240, !7, i64 244, !7, i64 248, !7, i64 252, !7, i64 256, !12, i64 260, !8, i64 262, !11, i64 264}
!17 = !{!"_EFI_MTFTP4_PROTOCOL", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56}
!18 = !{!"long long", !8, i64 0}
!19 = !{!"", !8, i64 0, !20, i64 1, !20, i64 5, !12, i64 10, !20, i64 12, !20, i64 16, !12, i64 20, !12, i64 22, !12, i64 24}
!20 = !{!"", !8, i64 0}
!21 = !{!"", !12, i64 0, !8, i64 2, !7, i64 4, !7, i64 8, !12, i64 12, !8, i64 14, !7, i64 16}
!22 = !{!16, !11, i64 152}
!23 = !{!24, !11, i64 88}
!24 = !{!"_EFI_MTFTP4_TOKEN", !18, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !7, i64 40, !11, i64 48, !18, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !11, i64 96}
!25 = !{!16, !7, i64 244}
!26 = !{!16, !7, i64 248}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass