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

; 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._IP6_PROTOCOL = type { i32, %struct._EFI_IP6_PROTOCOL, ptr, i64, ptr, %struct._LIST_ENTRY, i8, %struct.NET_MAP, %struct.NET_MAP, %struct._LIST_ENTRY, %struct._LIST_ENTRY, %struct.EFI_LOCK, ptr, %struct._LIST_ENTRY, ptr, i32, %struct.EFI_IP6_CONFIG_DATA, i8 }
%struct._EFI_IP6_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.NET_MAP = type { %struct._LIST_ENTRY, %struct._LIST_ENTRY, i64 }
%struct.EFI_LOCK = type { i64, i64, i32 }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.EFI_IP6_CONFIG_DATA = type { i8, i8, i8, i8, %struct.EFI_IPv6_ADDRESS, %struct.EFI_IPv6_ADDRESS, i8, i8, i32, i32, i32 }
%struct.EFI_IPv6_ADDRESS = type { [16 x i8] }

declare void @FreePool(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local i64 @Ip6CleanProtocol(ptr noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = call i64 @Ip6Cancel(ptr noundef %4, ptr noundef null)
  %6 = icmp slt i64 %5, 0
  br i1 %6, label %7, label %8

7:                                                ; preds = %1
  store i64 -9223372036854775801, ptr %2, align 8
  br label %52

8:                                                ; preds = %1
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call i64 @Ip6Groups(ptr noundef %9, i8 noundef zeroext 0, ptr noundef null)
  %11 = icmp slt i64 %10, 0
  br i1 %11, label %12, label %13

12:                                               ; preds = %8
  store i64 -9223372036854775801, ptr %2, align 8
  br label %52

13:                                               ; preds = %8
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %14, i32 0, i32 10
  %16 = call zeroext i8 @IsListEmpty(ptr noundef %15)
  %17 = icmp ne i8 %16, 0
  br i1 %17, label %19, label %18

18:                                               ; preds = %13
  br label %19

19:                                               ; preds = %18, %13
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %20, i32 0, i32 12
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %34

24:                                               ; preds = %19
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %25, i32 0, i32 13
  %27 = call ptr @RemoveEntryList(ptr noundef %26)
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %28, i32 0, i32 12
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  call void @Ip6CleanInterface(ptr noundef %30, ptr noundef %31)
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %32, i32 0, i32 12
  store ptr null, ptr %33, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %24, %19
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %35, i32 0, i32 14
  %37 = load ptr, ptr %36, align 8, !tbaa !19
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %47

39:                                               ; preds = %34
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %40, i32 0, i32 14
  %42 = load ptr, ptr %41, align 8, !tbaa !19
  call void @FreePool(ptr noundef %42)
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %43, i32 0, i32 14
  store ptr null, ptr %44, align 8, !tbaa !19
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %45, i32 0, i32 15
  store i32 0, ptr %46, align 8, !tbaa !20
  br label %47

47:                                               ; preds = %39, %34
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %48, i32 0, i32 8
  call void @NetMapClean(ptr noundef %49)
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %50, i32 0, i32 7
  call void @NetMapClean(ptr noundef %51)
  store i64 0, ptr %2, align 8
  br label %52

52:                                               ; preds = %47, %12, %7
  %53 = load i64, ptr %2, align 8
  ret i64 %53
}

declare i64 @Ip6Groups(ptr noundef, i8 noundef zeroext, ptr noundef) #0

declare zeroext i8 @IsListEmpty(ptr noundef) #0

declare ptr @RemoveEntryList(ptr noundef) #0

declare void @Ip6CleanInterface(ptr noundef, ptr noundef) #0

declare void @NetMapClean(ptr noundef) #0

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

!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 264}
!10 = !{!"_IP6_PROTOCOL", !11, i64 0, !12, i64 8, !6, i64 80, !13, i64 88, !6, i64 96, !14, i64 104, !7, i64 120, !15, i64 128, !15, i64 168, !14, i64 208, !14, i64 224, !16, i64 240, !6, i64 264, !14, i64 272, !6, i64 288, !11, i64 296, !17, i64 300, !7, i64 352}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_EFI_IP6_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, !6, i64 64}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!15 = !{!"", !14, i64 0, !14, i64 16, !13, i64 32}
!16 = !{!"", !13, i64 0, !13, i64 8, !11, i64 16}
!17 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !18, i64 4, !18, i64 20, !7, i64 36, !7, i64 37, !11, i64 40, !11, i64 44, !11, i64 48}
!18 = !{!"", !7, i64 0}
!19 = !{!10, !6, i64 288}
!20 = !{!10, !11, i64 296}


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

declare void @FreePool(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775801, 1) i64 @Ip6CleanProtocol(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call i64 @Ip6Cancel(ptr noundef %0, ptr noundef null)
  %3 = icmp slt i64 %2, 0
  br i1 %3, label %24, label %4

4:                                                ; preds = %1
  %5 = tail call i64 @Ip6Groups(ptr noundef %0, i8 noundef zeroext 0, ptr noundef null) #2
  %6 = icmp slt i64 %5, 0
  br i1 %6, label %24, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 224
  %9 = tail call zeroext i8 @IsListEmpty(ptr noundef nonnull %8) #2
  %10 = getelementptr inbounds i8, ptr %0, i64 264
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %16, label %12

12:                                               ; preds = %7
  %13 = getelementptr inbounds i8, ptr %0, i64 272
  %14 = tail call ptr @RemoveEntryList(ptr noundef nonnull %13) #2
  %15 = load ptr, ptr %10, align 8, !tbaa !5
  tail call void @Ip6CleanInterface(ptr noundef %15, ptr noundef nonnull %0) #2
  store ptr null, ptr %10, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %12, %7
  %17 = getelementptr inbounds i8, ptr %0, i64 288
  %18 = load ptr, ptr %17, align 8, !tbaa !18
  %.not15 = icmp eq ptr %18, null
  br i1 %.not15, label %21, label %19

19:                                               ; preds = %16
  tail call void @FreePool(ptr noundef nonnull %18) #2
  store ptr null, ptr %17, align 8, !tbaa !18
  %20 = getelementptr inbounds i8, ptr %0, i64 296
  store i32 0, ptr %20, align 8, !tbaa !19
  br label %21

21:                                               ; preds = %19, %16
  %22 = getelementptr inbounds i8, ptr %0, i64 168
  tail call void @NetMapClean(ptr noundef nonnull %22) #2
  %23 = getelementptr inbounds i8, ptr %0, i64 128
  tail call void @NetMapClean(ptr noundef nonnull %23) #2
  br label %24

24:                                               ; preds = %4, %1, %21
  %.0 = phi i64 [ 0, %21 ], [ -9223372036854775801, %1 ], [ -9223372036854775801, %4 ]
  ret i64 %.0
}

declare i64 @Ip6Groups(ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #0

declare zeroext i8 @IsListEmpty(ptr noundef) local_unnamed_addr #0

declare ptr @RemoveEntryList(ptr noundef) local_unnamed_addr #0

declare void @Ip6CleanInterface(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @NetMapClean(ptr noundef) local_unnamed_addr #0

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 = { 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 264}
!6 = !{!"_IP6_PROTOCOL", !7, i64 0, !10, i64 8, !11, i64 80, !12, i64 88, !11, i64 96, !13, i64 104, !8, i64 120, !14, i64 128, !14, i64 168, !13, i64 208, !13, i64 224, !15, i64 240, !11, i64 264, !13, i64 272, !11, i64 288, !7, i64 296, !16, i64 300, !8, i64 352}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_EFI_IP6_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, !11, i64 64}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"long long", !8, i64 0}
!13 = !{!"_LIST_ENTRY", !11, i64 0, !11, i64 8}
!14 = !{!"", !13, i64 0, !13, i64 16, !12, i64 32}
!15 = !{!"", !12, i64 0, !12, i64 8, !7, i64 16}
!16 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !17, i64 4, !17, i64 20, !8, i64 36, !8, i64 37, !7, i64 40, !7, i64 44, !7, i64 48}
!17 = !{!"", !8, i64 0}
!18 = !{!6, !11, i64 288}
!19 = !{!6, !7, i64 296}


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