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

; 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] }

; 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

declare ptr @AllocatePool(i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @Ip6CreateRouteTable() #2 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %5 = call ptr @AllocatePool(i64 noundef 2608)
  store ptr %5, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %0
  store ptr null, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %50

9:                                                ; preds = %0
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct._IP6_ROUTE_TABLE, ptr %10, i32 0, i32 0
  store i64 1, ptr %11, align 8, !tbaa !9
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._IP6_ROUTE_TABLE, ptr %12, i32 0, i32 1
  store i32 0, ptr %13, align 8, !tbaa !14
  store i32 0, ptr %3, align 4, !tbaa !15
  br label %14

14:                                               ; preds = %24, %9
  %15 = load i32, ptr %3, align 4, !tbaa !15
  %16 = icmp ult i32 %15, 129
  br i1 %16, label %17, label %27

17:                                               ; preds = %14
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._IP6_ROUTE_TABLE, ptr %18, i32 0, i32 2
  %20 = load i32, ptr %3, align 4, !tbaa !15
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds [129 x %struct._LIST_ENTRY], ptr %19, i64 0, i64 %21
  %23 = call ptr @InitializeListHead(ptr noundef %22)
  br label %24

24:                                               ; preds = %17
  %25 = load i32, ptr %3, align 4, !tbaa !15
  %26 = add i32 %25, 1
  store i32 %26, ptr %3, align 4, !tbaa !15
  br label %14, !llvm.loop !16

27:                                               ; preds = %14
  store i32 0, ptr %3, align 4, !tbaa !15
  br label %28

28:                                               ; preds = %45, %27
  %29 = load i32, ptr %3, align 4, !tbaa !15
  %30 = icmp ult i32 %29, 31
  br i1 %30, label %31, label %48

31:                                               ; preds = %28
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._IP6_ROUTE_TABLE, ptr %32, i32 0, i32 3
  %34 = getelementptr inbounds %struct.IP6_ROUTE_CACHE, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %3, align 4, !tbaa !15
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds [31 x %struct._LIST_ENTRY], ptr %34, i64 0, i64 %36
  %38 = call ptr @InitializeListHead(ptr noundef %37)
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._IP6_ROUTE_TABLE, ptr %39, i32 0, i32 3
  %41 = getelementptr inbounds %struct.IP6_ROUTE_CACHE, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %3, align 4, !tbaa !15
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds [31 x i8], ptr %41, i64 0, i64 %43
  store i8 0, ptr %44, align 1, !tbaa !18
  br label %45

45:                                               ; preds = %31
  %46 = load i32, ptr %3, align 4, !tbaa !15
  %47 = add i32 %46, 1
  store i32 %47, ptr %3, align 4, !tbaa !15
  br label %28, !llvm.loop !19

48:                                               ; preds = %28
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %49, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %50

50:                                               ; preds = %48, %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %51 = load ptr, ptr %1, align 8
  ret ptr %51
}

declare ptr @InitializeListHead(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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, !11, i64 0}
!10 = !{!"_IP6_ROUTE_TABLE", !11, i64 0, !12, i64 8, !7, i64 16, !13, i64 2080}
!11 = !{!"long long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"", !7, i64 0, !7, i64 496}
!14 = !{!10, !12, i64 8}
!15 = !{!12, !12, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !17}


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

declare ptr @AllocatePool(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @Ip6CreateRouteTable() local_unnamed_addr #1 {
  %1 = tail call ptr @AllocatePool(i64 noundef 2608) #2
  %2 = icmp eq ptr %1, null
  br i1 %2, label %.loopexit, label %3

3:                                                ; preds = %0
  store i64 1, ptr %1, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  store i32 0, ptr %4, align 8, !tbaa !12
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  br label %99

.preheader:                                       ; preds = %99
  %6 = getelementptr inbounds i8, ptr %1, i64 2080
  %7 = getelementptr inbounds i8, ptr %1, i64 2576
  %8 = tail call ptr @InitializeListHead(ptr noundef nonnull %6) #2
  store i8 0, ptr %7, align 1, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %1, i64 2096
  %10 = tail call ptr @InitializeListHead(ptr noundef nonnull %9) #2
  %11 = getelementptr inbounds i8, ptr %1, i64 2577
  store i8 0, ptr %11, align 1, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %1, i64 2112
  %13 = tail call ptr @InitializeListHead(ptr noundef nonnull %12) #2
  %14 = getelementptr inbounds i8, ptr %1, i64 2578
  store i8 0, ptr %14, align 1, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %1, i64 2128
  %16 = tail call ptr @InitializeListHead(ptr noundef nonnull %15) #2
  %17 = getelementptr inbounds i8, ptr %1, i64 2579
  store i8 0, ptr %17, align 1, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %1, i64 2144
  %19 = tail call ptr @InitializeListHead(ptr noundef nonnull %18) #2
  %20 = getelementptr inbounds i8, ptr %1, i64 2580
  store i8 0, ptr %20, align 1, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %1, i64 2160
  %22 = tail call ptr @InitializeListHead(ptr noundef nonnull %21) #2
  %23 = getelementptr inbounds i8, ptr %1, i64 2581
  store i8 0, ptr %23, align 1, !tbaa !13
  %24 = getelementptr inbounds i8, ptr %1, i64 2176
  %25 = tail call ptr @InitializeListHead(ptr noundef nonnull %24) #2
  %26 = getelementptr inbounds i8, ptr %1, i64 2582
  store i8 0, ptr %26, align 1, !tbaa !13
  %27 = getelementptr inbounds i8, ptr %1, i64 2192
  %28 = tail call ptr @InitializeListHead(ptr noundef nonnull %27) #2
  %29 = getelementptr inbounds i8, ptr %1, i64 2583
  store i8 0, ptr %29, align 1, !tbaa !13
  %30 = getelementptr inbounds i8, ptr %1, i64 2208
  %31 = tail call ptr @InitializeListHead(ptr noundef nonnull %30) #2
  %32 = getelementptr inbounds i8, ptr %1, i64 2584
  store i8 0, ptr %32, align 1, !tbaa !13
  %33 = getelementptr inbounds i8, ptr %1, i64 2224
  %34 = tail call ptr @InitializeListHead(ptr noundef nonnull %33) #2
  %35 = getelementptr inbounds i8, ptr %1, i64 2585
  store i8 0, ptr %35, align 1, !tbaa !13
  %36 = getelementptr inbounds i8, ptr %1, i64 2240
  %37 = tail call ptr @InitializeListHead(ptr noundef nonnull %36) #2
  %38 = getelementptr inbounds i8, ptr %1, i64 2586
  store i8 0, ptr %38, align 1, !tbaa !13
  %39 = getelementptr inbounds i8, ptr %1, i64 2256
  %40 = tail call ptr @InitializeListHead(ptr noundef nonnull %39) #2
  %41 = getelementptr inbounds i8, ptr %1, i64 2587
  store i8 0, ptr %41, align 1, !tbaa !13
  %42 = getelementptr inbounds i8, ptr %1, i64 2272
  %43 = tail call ptr @InitializeListHead(ptr noundef nonnull %42) #2
  %44 = getelementptr inbounds i8, ptr %1, i64 2588
  store i8 0, ptr %44, align 1, !tbaa !13
  %45 = getelementptr inbounds i8, ptr %1, i64 2288
  %46 = tail call ptr @InitializeListHead(ptr noundef nonnull %45) #2
  %47 = getelementptr inbounds i8, ptr %1, i64 2589
  store i8 0, ptr %47, align 1, !tbaa !13
  %48 = getelementptr inbounds i8, ptr %1, i64 2304
  %49 = tail call ptr @InitializeListHead(ptr noundef nonnull %48) #2
  %50 = getelementptr inbounds i8, ptr %1, i64 2590
  store i8 0, ptr %50, align 1, !tbaa !13
  %51 = getelementptr inbounds i8, ptr %1, i64 2320
  %52 = tail call ptr @InitializeListHead(ptr noundef nonnull %51) #2
  %53 = getelementptr inbounds i8, ptr %1, i64 2591
  store i8 0, ptr %53, align 1, !tbaa !13
  %54 = getelementptr inbounds i8, ptr %1, i64 2336
  %55 = tail call ptr @InitializeListHead(ptr noundef nonnull %54) #2
  %56 = getelementptr inbounds i8, ptr %1, i64 2592
  store i8 0, ptr %56, align 1, !tbaa !13
  %57 = getelementptr inbounds i8, ptr %1, i64 2352
  %58 = tail call ptr @InitializeListHead(ptr noundef nonnull %57) #2
  %59 = getelementptr inbounds i8, ptr %1, i64 2593
  store i8 0, ptr %59, align 1, !tbaa !13
  %60 = getelementptr inbounds i8, ptr %1, i64 2368
  %61 = tail call ptr @InitializeListHead(ptr noundef nonnull %60) #2
  %62 = getelementptr inbounds i8, ptr %1, i64 2594
  store i8 0, ptr %62, align 1, !tbaa !13
  %63 = getelementptr inbounds i8, ptr %1, i64 2384
  %64 = tail call ptr @InitializeListHead(ptr noundef nonnull %63) #2
  %65 = getelementptr inbounds i8, ptr %1, i64 2595
  store i8 0, ptr %65, align 1, !tbaa !13
  %66 = getelementptr inbounds i8, ptr %1, i64 2400
  %67 = tail call ptr @InitializeListHead(ptr noundef nonnull %66) #2
  %68 = getelementptr inbounds i8, ptr %1, i64 2596
  store i8 0, ptr %68, align 1, !tbaa !13
  %69 = getelementptr inbounds i8, ptr %1, i64 2416
  %70 = tail call ptr @InitializeListHead(ptr noundef nonnull %69) #2
  %71 = getelementptr inbounds i8, ptr %1, i64 2597
  store i8 0, ptr %71, align 1, !tbaa !13
  %72 = getelementptr inbounds i8, ptr %1, i64 2432
  %73 = tail call ptr @InitializeListHead(ptr noundef nonnull %72) #2
  %74 = getelementptr inbounds i8, ptr %1, i64 2598
  store i8 0, ptr %74, align 1, !tbaa !13
  %75 = getelementptr inbounds i8, ptr %1, i64 2448
  %76 = tail call ptr @InitializeListHead(ptr noundef nonnull %75) #2
  %77 = getelementptr inbounds i8, ptr %1, i64 2599
  store i8 0, ptr %77, align 1, !tbaa !13
  %78 = getelementptr inbounds i8, ptr %1, i64 2464
  %79 = tail call ptr @InitializeListHead(ptr noundef nonnull %78) #2
  %80 = getelementptr inbounds i8, ptr %1, i64 2600
  store i8 0, ptr %80, align 1, !tbaa !13
  %81 = getelementptr inbounds i8, ptr %1, i64 2480
  %82 = tail call ptr @InitializeListHead(ptr noundef nonnull %81) #2
  %83 = getelementptr inbounds i8, ptr %1, i64 2601
  store i8 0, ptr %83, align 1, !tbaa !13
  %84 = getelementptr inbounds i8, ptr %1, i64 2496
  %85 = tail call ptr @InitializeListHead(ptr noundef nonnull %84) #2
  %86 = getelementptr inbounds i8, ptr %1, i64 2602
  store i8 0, ptr %86, align 1, !tbaa !13
  %87 = getelementptr inbounds i8, ptr %1, i64 2512
  %88 = tail call ptr @InitializeListHead(ptr noundef nonnull %87) #2
  %89 = getelementptr inbounds i8, ptr %1, i64 2603
  store i8 0, ptr %89, align 1, !tbaa !13
  %90 = getelementptr inbounds i8, ptr %1, i64 2528
  %91 = tail call ptr @InitializeListHead(ptr noundef nonnull %90) #2
  %92 = getelementptr inbounds i8, ptr %1, i64 2604
  store i8 0, ptr %92, align 1, !tbaa !13
  %93 = getelementptr inbounds i8, ptr %1, i64 2544
  %94 = tail call ptr @InitializeListHead(ptr noundef nonnull %93) #2
  %95 = getelementptr inbounds i8, ptr %1, i64 2605
  store i8 0, ptr %95, align 1, !tbaa !13
  %96 = getelementptr inbounds i8, ptr %1, i64 2560
  %97 = tail call ptr @InitializeListHead(ptr noundef nonnull %96) #2
  %98 = getelementptr inbounds i8, ptr %1, i64 2606
  store i8 0, ptr %98, align 1, !tbaa !13
  br label %.loopexit

99:                                               ; preds = %3, %99
  %indvars.iv = phi i64 [ 0, %3 ], [ %indvars.iv.next, %99 ]
  %100 = getelementptr inbounds [129 x %struct._LIST_ENTRY], ptr %5, i64 0, i64 %indvars.iv
  %101 = tail call ptr @InitializeListHead(ptr noundef nonnull %100) #2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 129
  br i1 %exitcond.not, label %.preheader, label %99, !llvm.loop !14

.loopexit:                                        ; preds = %.preheader, %0
  ret ptr %1
}

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass