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

; 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._LIST_ENTRY = type { ptr, ptr }

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

18:                                               ; preds = %4
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %18, %4
  store i64 -9223372036854775806, ptr %5, align 8
  store i32 1, ptr %15, align 4
  br label %99

22:                                               ; preds = %18
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %88, %22
  %24 = load i64, ptr %13, align 8, !tbaa !9
  store i64 %24, ptr %10, align 8, !tbaa !9
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = call ptr @GetFirstNode(ptr noundef %25)
  store ptr %26, ptr %11, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %71, %23
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load ptr, ptr %11, align 8, !tbaa !5
  %30 = call zeroext i8 @IsNull(ptr noundef %28, ptr noundef %29)
  %31 = icmp ne i8 %30, 0
  %32 = xor i1 %31, true
  br i1 %32, label %33, label %72

33:                                               ; preds = %27
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = call i64 %34(ptr noundef %35, ptr noundef %36)
  store i64 %37, ptr %14, align 8, !tbaa !9
  %38 = load i64, ptr %14, align 8, !tbaa !9
  %39 = icmp slt i64 %38, 0
  br i1 %39, label %40, label %42

40:                                               ; preds = %33
  %41 = load i64, ptr %14, align 8, !tbaa !9
  store i64 %41, ptr %5, align 8
  store i32 1, ptr %15, align 4
  br label %99

42:                                               ; preds = %33
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct._LIST_ENTRY, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  store ptr %45, ptr %12, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %56, %42
  %47 = load ptr, ptr %12, align 8, !tbaa !5
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = icmp ne ptr %47, %48
  br i1 %49, label %50, label %60

50:                                               ; preds = %46
  %51 = load ptr, ptr %12, align 8, !tbaa !5
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  %53 = icmp eq ptr %51, %52
  br i1 %53, label %54, label %55

54:                                               ; preds = %50
  br label %60

55:                                               ; preds = %50
  br label %56

56:                                               ; preds = %55
  %57 = load ptr, ptr %12, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct._LIST_ENTRY, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !11
  store ptr %59, ptr %12, align 8, !tbaa !5
  br label %46, !llvm.loop !13

60:                                               ; preds = %54, %46
  %61 = load ptr, ptr %12, align 8, !tbaa !5
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = icmp eq ptr %61, %62
  br i1 %63, label %64, label %68

64:                                               ; preds = %60
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = call ptr @GetNextNode(ptr noundef %65, ptr noundef %66)
  store ptr %67, ptr %11, align 8, !tbaa !5
  br label %71

68:                                               ; preds = %60
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = call ptr @GetFirstNode(ptr noundef %69)
  store ptr %70, ptr %11, align 8, !tbaa !5
  br label %71

71:                                               ; preds = %68, %64
  br label %27, !llvm.loop !15

72:                                               ; preds = %27
  store i64 0, ptr %13, align 8, !tbaa !9
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct._LIST_ENTRY, ptr %73, i32 0, i32 0
  %75 = load ptr, ptr %74, align 8, !tbaa !11
  store ptr %75, ptr %12, align 8, !tbaa !5
  br label %76

76:                                               ; preds = %81, %72
  %77 = load ptr, ptr %12, align 8, !tbaa !5
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = icmp ne ptr %77, %78
  br i1 %79, label %80, label %87

80:                                               ; preds = %76
  br label %81

81:                                               ; preds = %80
  %82 = load i64, ptr %13, align 8, !tbaa !9
  %83 = add i64 %82, 1
  store i64 %83, ptr %13, align 8, !tbaa !9
  %84 = load ptr, ptr %12, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct._LIST_ENTRY, ptr %84, i32 0, i32 0
  %86 = load ptr, ptr %85, align 8, !tbaa !11
  store ptr %86, ptr %12, align 8, !tbaa !5
  br label %76, !llvm.loop !16

87:                                               ; preds = %76
  br label %88

88:                                               ; preds = %87
  %89 = load i64, ptr %13, align 8, !tbaa !9
  %90 = load i64, ptr %10, align 8, !tbaa !9
  %91 = icmp ne i64 %89, %90
  br i1 %91, label %23, label %92, !llvm.loop !17

92:                                               ; preds = %88
  %93 = load ptr, ptr %9, align 8, !tbaa !5
  %94 = icmp ne ptr %93, null
  br i1 %94, label %95, label %98

95:                                               ; preds = %92
  %96 = load i64, ptr %13, align 8, !tbaa !9
  %97 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %96, ptr %97, align 8, !tbaa !9
  br label %98

98:                                               ; preds = %95, %92
  store i64 0, ptr %5, align 8
  store i32 1, ptr %15, align 4
  br label %99

99:                                               ; preds = %98, %40, %21
  call void @llvm.lifetime.end.p0(i64 8, 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
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %100 = load i64, ptr %5, align 8
  ret i64 %100
}

declare ptr @GetFirstNode(ptr noundef) #2

declare zeroext i8 @IsNull(ptr noundef, ptr noundef) #2

declare ptr @GetNextNode(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, !6, i64 0}
!12 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}


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

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775808, 1) i64 @NetDestroyLinkList(ptr noundef %0, ptr noundef readonly %1, ptr noundef %2, ptr noundef writeonly %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %0, null
  %6 = icmp eq ptr %1, null
  %or.cond = or i1 %5, %6
  br i1 %or.cond, label %.loopexit, label %.preheader48

.preheader48:                                     ; preds = %4, %20
  %.033 = phi i64 [ %.1, %20 ], [ 0, %4 ]
  %7 = tail call ptr @GetFirstNode(ptr noundef %0) #2
  %8 = tail call zeroext i8 @IsNull(ptr noundef %0, ptr noundef %7) #2
  %.not50 = icmp eq i8 %8, 0
  br i1 %.not50, label %.lr.ph, label %.preheader47.preheader

.lr.ph:                                           ; preds = %.preheader48, %17
  %.03651 = phi ptr [ %.137, %17 ], [ %7, %.preheader48 ]
  %9 = tail call i64 %1(ptr noundef %.03651, ptr noundef %2) #2
  %10 = icmp slt i64 %9, 0
  br i1 %10, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %.preheader
  %.034.in = phi ptr [ %.034, %.preheader ], [ %0, %.lr.ph ]
  %.034 = load ptr, ptr %.034.in, align 8, !tbaa !5
  %.not45 = icmp eq ptr %.034, %0
  %11 = icmp eq ptr %.034, %.03651
  %or.cond46 = or i1 %.not45, %11
  br i1 %or.cond46, label %12, label %.preheader, !llvm.loop !10

12:                                               ; preds = %.preheader
  br i1 %11, label %13, label %15

13:                                               ; preds = %12
  %14 = tail call ptr @GetNextNode(ptr noundef %0, ptr noundef %.03651) #2
  br label %17

15:                                               ; preds = %12
  %16 = tail call ptr @GetFirstNode(ptr noundef %0) #2
  br label %17

17:                                               ; preds = %15, %13
  %.137 = phi ptr [ %14, %13 ], [ %16, %15 ]
  %18 = tail call zeroext i8 @IsNull(ptr noundef %0, ptr noundef %.137) #2
  %.not = icmp eq i8 %18, 0
  br i1 %.not, label %.lr.ph, label %.preheader47.preheader, !llvm.loop !12

.preheader47.preheader:                           ; preds = %17, %.preheader48
  br label %.preheader47

.preheader47:                                     ; preds = %.preheader47.preheader, %.preheader47
  %.135.in = phi ptr [ %.135, %.preheader47 ], [ %0, %.preheader47.preheader ]
  %.1 = phi i64 [ %19, %.preheader47 ], [ 0, %.preheader47.preheader ]
  %.135 = load ptr, ptr %.135.in, align 8, !tbaa !5
  %.not42 = icmp eq ptr %.135, %0
  %19 = add i64 %.1, 1
  br i1 %.not42, label %20, label %.preheader47, !llvm.loop !13

20:                                               ; preds = %.preheader47
  %.not43 = icmp eq i64 %.1, %.033
  br i1 %.not43, label %21, label %.preheader48, !llvm.loop !14

21:                                               ; preds = %20
  %.not44 = icmp eq ptr %3, null
  br i1 %.not44, label %.loopexit, label %22

22:                                               ; preds = %21
  store i64 %.033, ptr %3, align 8, !tbaa !15
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %21, %22, %4
  %.0 = phi i64 [ -9223372036854775806, %4 ], [ 0, %22 ], [ 0, %21 ], [ %9, %.lr.ph ]
  ret i64 %.0
}

declare ptr @GetFirstNode(ptr noundef) local_unnamed_addr #1

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

declare ptr @GetNextNode(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 = { 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 = !{!"_LIST_ENTRY", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !11}
!15 = !{!16, !16, i64 0}
!16 = !{!"long long", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass