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

; 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_ROUTE_TABLE = type { i64, i32, [129 x %struct._LIST_ENTRY], %struct.IP6_ROUTE_CACHE }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.IP6_ROUTE_CACHE = type { [31 x %struct._LIST_ENTRY], [31 x i8] }
%struct.IP6_ROUTE_ENTRY = type { %struct._LIST_ENTRY, i64, i32, i8, %struct.EFI_IPv6_ADDRESS, %struct.EFI_IPv6_ADDRESS }
%struct.EFI_IPv6_ADDRESS = type { [16 x i8] }

; 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 ptr @Ip6CreateRouteEntry(ptr noundef, i8 noundef zeroext, ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @Ip6AddRoute(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, ptr noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i8 %2, ptr %8, align 1, !tbaa !9
  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
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct._IP6_ROUTE_TABLE, ptr %14, i32 0, i32 2
  %16 = load i8, ptr %8, align 1, !tbaa !9
  %17 = zext i8 %16 to i64
  %18 = getelementptr inbounds [129 x %struct._LIST_ENTRY], ptr %15, i64 0, i64 %17
  store ptr %18, ptr %10, align 8, !tbaa !5
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._LIST_ENTRY, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !10
  store ptr %21, ptr %11, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %46, %4
  %23 = load ptr, ptr %11, align 8, !tbaa !5
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = icmp ne ptr %23, %24
  br i1 %25, label %26, label %50

26:                                               ; preds = %22
  %27 = load ptr, ptr %11, align 8, !tbaa !5
  %28 = ptrtoint ptr %27 to i64
  %29 = sub i64 %28, 0
  %30 = inttoptr i64 %29 to ptr
  store ptr %30, ptr %12, align 8, !tbaa !5
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = load ptr, ptr %12, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.IP6_ROUTE_ENTRY, ptr %32, i32 0, i32 4
  %34 = load i8, ptr %8, align 1, !tbaa !9
  %35 = call zeroext i8 @NetIp6IsNetEqual(ptr noundef %31, ptr noundef %33, i8 noundef zeroext %34)
  %36 = zext i8 %35 to i32
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %45

38:                                               ; preds = %26
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = load ptr, ptr %12, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.IP6_ROUTE_ENTRY, ptr %40, i32 0, i32 5
  %42 = call i64 @CompareMem(ptr noundef %39, ptr noundef %41, i64 noundef 16)
  %43 = icmp eq i64 %42, 0
  br i1 %43, label %44, label %45

44:                                               ; preds = %38
  store i64 -9223372036854775793, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %74

45:                                               ; preds = %38, %26
  br label %46

46:                                               ; preds = %45
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._LIST_ENTRY, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !10
  store ptr %49, ptr %11, align 8, !tbaa !5
  br label %22, !llvm.loop !12

50:                                               ; preds = %22
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = load i8, ptr %8, align 1, !tbaa !9
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = call ptr @Ip6CreateRouteEntry(ptr noundef %51, i8 noundef zeroext %52, ptr noundef %53)
  store ptr %54, ptr %12, align 8, !tbaa !5
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = icmp eq ptr %55, null
  br i1 %56, label %57, label %58

57:                                               ; preds = %50
  store i64 -9223372036854775799, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %74

58:                                               ; preds = %50
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = call zeroext i8 @NetIp6IsUnspecifiedAddr(ptr noundef %59)
  %61 = icmp ne i8 %60, 0
  br i1 %61, label %62, label %65

62:                                               ; preds = %58
  %63 = load ptr, ptr %12, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.IP6_ROUTE_ENTRY, ptr %63, i32 0, i32 2
  store i32 1, ptr %64, align 8, !tbaa !14
  br label %65

65:                                               ; preds = %62, %58
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = load ptr, ptr %12, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.IP6_ROUTE_ENTRY, ptr %67, i32 0, i32 0
  %69 = call ptr @InsertHeadList(ptr noundef %66, ptr noundef %68)
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct._IP6_ROUTE_TABLE, ptr %70, i32 0, i32 1
  %72 = load i32, ptr %71, align 8, !tbaa !19
  %73 = add i32 %72, 1
  store i32 %73, ptr %71, align 8, !tbaa !19
  store i64 0, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %74

74:                                               ; preds = %65, %57, %44
  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
  %75 = load i64, ptr %5, align 8
  ret i64 %75
}

declare zeroext i8 @NetIp6IsUnspecifiedAddr(ptr noundef) #2

declare ptr @InsertHeadList(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 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 0}
!11 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !17, i64 24}
!15 = !{!"", !11, i64 0, !16, i64 16, !17, i64 24, !7, i64 28, !18, i64 29, !18, i64 45}
!16 = !{!"long long", !7, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!"", !7, i64 0}
!19 = !{!20, !17, i64 8}
!20 = !{!"_IP6_ROUTE_TABLE", !16, i64 0, !17, i64 8, !7, i64 16, !21, i64 2080}
!21 = !{!"", !7, i64 0, !7, i64 496}


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

; Function Attrs: nounwind uwtable
declare dso_local ptr @Ip6CreateRouteEntry(ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #0

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

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775799, 1) i64 @Ip6AddRoute(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = zext i8 %2 to i64
  %7 = getelementptr inbounds [129 x %struct._LIST_ENTRY], ptr %5, i64 0, i64 %6
  %.026 = load ptr, ptr %7, align 8, !tbaa !5
  %.not27 = icmp eq ptr %.026, %7
  br i1 %.not27, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %14
  %.028 = phi ptr [ %.0, %14 ], [ %.026, %4 ]
  %8 = getelementptr inbounds i8, ptr %.028, i64 29
  %9 = tail call zeroext i8 @NetIp6IsNetEqual(ptr noundef %1, ptr noundef nonnull %8, i8 noundef zeroext %2) #2
  %.not25 = icmp eq i8 %9, 0
  br i1 %.not25, label %14, label %10

10:                                               ; preds = %.lr.ph
  %11 = getelementptr inbounds i8, ptr %.028, i64 45
  %12 = tail call i64 @CompareMem(ptr noundef %3, ptr noundef nonnull %11, i64 noundef 16) #2
  %13 = icmp eq i64 %12, 0
  br i1 %13, label %.loopexit, label %14

14:                                               ; preds = %.lr.ph, %10
  %.0 = load ptr, ptr %.028, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, %7
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %14, %4
  %15 = tail call ptr @Ip6CreateRouteEntry(ptr noundef %1, i8 noundef zeroext %2, ptr noundef %3)
  %16 = icmp eq ptr %15, null
  br i1 %16, label %.loopexit, label %17

17:                                               ; preds = %._crit_edge
  %18 = tail call zeroext i8 @NetIp6IsUnspecifiedAddr(ptr noundef %3) #2
  %.not24 = icmp eq i8 %18, 0
  br i1 %.not24, label %21, label %19

19:                                               ; preds = %17
  %20 = getelementptr inbounds i8, ptr %15, i64 24
  store i32 1, ptr %20, align 8, !tbaa !12
  br label %21

21:                                               ; preds = %19, %17
  %22 = tail call ptr @InsertHeadList(ptr noundef nonnull %7, ptr noundef nonnull %15) #2
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  %24 = load i32, ptr %23, align 8, !tbaa !17
  %25 = add i32 %24, 1
  store i32 %25, ptr %23, align 8, !tbaa !17
  br label %.loopexit

.loopexit:                                        ; preds = %10, %._crit_edge, %21
  %.021 = phi i64 [ 0, %21 ], [ -9223372036854775799, %._crit_edge ], [ -9223372036854775793, %10 ]
  ret i64 %.021
}

declare zeroext i8 @NetIp6IsUnspecifiedAddr(ptr noundef) local_unnamed_addr #1

declare ptr @InsertHeadList(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 = !{!13, !15, i64 24}
!13 = !{!"", !6, i64 0, !14, i64 16, !15, i64 24, !8, i64 28, !16, i64 29, !16, i64 45}
!14 = !{!"long long", !8, i64 0}
!15 = !{!"int", !8, i64 0}
!16 = !{!"", !8, i64 0}
!17 = !{!18, !15, i64 8}
!18 = !{!"_IP6_ROUTE_TABLE", !14, i64 0, !15, i64 8, !8, i64 16, !19, i64 2080}
!19 = !{!"", !8, i64 0, !8, i64 496}


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