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

; 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._IP4_ROUTE_TABLE = type { i64, i32, [33 x %struct._LIST_ENTRY], ptr, %struct.IP4_ROUTE_CACHE }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.IP4_ROUTE_CACHE = type { [31 x %struct._LIST_ENTRY] }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare ptr @AllocatePool(i64 noundef) #1

declare ptr @InitializeListHead(ptr noundef) #1

; 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 void @Ip4InitRouteCache(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @Ip4CreateRouteTable() #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 1048)
  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 %33

9:                                                ; preds = %0
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct._IP4_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._IP4_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, 33
  br i1 %16, label %17, label %27

17:                                               ; preds = %14
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._IP4_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 [33 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
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._IP4_ROUTE_TABLE, ptr %28, i32 0, i32 3
  store ptr null, ptr %29, align 8, !tbaa !18
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._IP4_ROUTE_TABLE, ptr %30, i32 0, i32 4
  call void @Ip4InitRouteCache(ptr noundef %31)
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %32, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %33

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

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 = !{!"_IP4_ROUTE_TABLE", !11, i64 0, !12, i64 8, !7, i64 16, !6, i64 544, !13, i64 552}
!11 = !{!"long long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"", !7, i64 0}
!14 = !{!10, !12, i64 8}
!15 = !{!12, !12, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!10, !6, i64 544}


; 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 ptr @AllocatePool(i64 noundef) local_unnamed_addr #0

declare ptr @InitializeListHead(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local ptr @Ip4CreateRouteTable() local_unnamed_addr #1 {
  %1 = tail call ptr @AllocatePool(i64 noundef 1048) #2
  %2 = icmp eq ptr %1, null
  br i1 %2, label %73, 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 !13
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %6 = tail call ptr @InitializeListHead(ptr noundef nonnull %5) #2
  %7 = getelementptr inbounds i8, ptr %1, i64 32
  %8 = tail call ptr @InitializeListHead(ptr noundef nonnull %7) #2
  %9 = getelementptr inbounds i8, ptr %1, i64 48
  %10 = tail call ptr @InitializeListHead(ptr noundef nonnull %9) #2
  %11 = getelementptr inbounds i8, ptr %1, i64 64
  %12 = tail call ptr @InitializeListHead(ptr noundef nonnull %11) #2
  %13 = getelementptr inbounds i8, ptr %1, i64 80
  %14 = tail call ptr @InitializeListHead(ptr noundef nonnull %13) #2
  %15 = getelementptr inbounds i8, ptr %1, i64 96
  %16 = tail call ptr @InitializeListHead(ptr noundef nonnull %15) #2
  %17 = getelementptr inbounds i8, ptr %1, i64 112
  %18 = tail call ptr @InitializeListHead(ptr noundef nonnull %17) #2
  %19 = getelementptr inbounds i8, ptr %1, i64 128
  %20 = tail call ptr @InitializeListHead(ptr noundef nonnull %19) #2
  %21 = getelementptr inbounds i8, ptr %1, i64 144
  %22 = tail call ptr @InitializeListHead(ptr noundef nonnull %21) #2
  %23 = getelementptr inbounds i8, ptr %1, i64 160
  %24 = tail call ptr @InitializeListHead(ptr noundef nonnull %23) #2
  %25 = getelementptr inbounds i8, ptr %1, i64 176
  %26 = tail call ptr @InitializeListHead(ptr noundef nonnull %25) #2
  %27 = getelementptr inbounds i8, ptr %1, i64 192
  %28 = tail call ptr @InitializeListHead(ptr noundef nonnull %27) #2
  %29 = getelementptr inbounds i8, ptr %1, i64 208
  %30 = tail call ptr @InitializeListHead(ptr noundef nonnull %29) #2
  %31 = getelementptr inbounds i8, ptr %1, i64 224
  %32 = tail call ptr @InitializeListHead(ptr noundef nonnull %31) #2
  %33 = getelementptr inbounds i8, ptr %1, i64 240
  %34 = tail call ptr @InitializeListHead(ptr noundef nonnull %33) #2
  %35 = getelementptr inbounds i8, ptr %1, i64 256
  %36 = tail call ptr @InitializeListHead(ptr noundef nonnull %35) #2
  %37 = getelementptr inbounds i8, ptr %1, i64 272
  %38 = tail call ptr @InitializeListHead(ptr noundef nonnull %37) #2
  %39 = getelementptr inbounds i8, ptr %1, i64 288
  %40 = tail call ptr @InitializeListHead(ptr noundef nonnull %39) #2
  %41 = getelementptr inbounds i8, ptr %1, i64 304
  %42 = tail call ptr @InitializeListHead(ptr noundef nonnull %41) #2
  %43 = getelementptr inbounds i8, ptr %1, i64 320
  %44 = tail call ptr @InitializeListHead(ptr noundef nonnull %43) #2
  %45 = getelementptr inbounds i8, ptr %1, i64 336
  %46 = tail call ptr @InitializeListHead(ptr noundef nonnull %45) #2
  %47 = getelementptr inbounds i8, ptr %1, i64 352
  %48 = tail call ptr @InitializeListHead(ptr noundef nonnull %47) #2
  %49 = getelementptr inbounds i8, ptr %1, i64 368
  %50 = tail call ptr @InitializeListHead(ptr noundef nonnull %49) #2
  %51 = getelementptr inbounds i8, ptr %1, i64 384
  %52 = tail call ptr @InitializeListHead(ptr noundef nonnull %51) #2
  %53 = getelementptr inbounds i8, ptr %1, i64 400
  %54 = tail call ptr @InitializeListHead(ptr noundef nonnull %53) #2
  %55 = getelementptr inbounds i8, ptr %1, i64 416
  %56 = tail call ptr @InitializeListHead(ptr noundef nonnull %55) #2
  %57 = getelementptr inbounds i8, ptr %1, i64 432
  %58 = tail call ptr @InitializeListHead(ptr noundef nonnull %57) #2
  %59 = getelementptr inbounds i8, ptr %1, i64 448
  %60 = tail call ptr @InitializeListHead(ptr noundef nonnull %59) #2
  %61 = getelementptr inbounds i8, ptr %1, i64 464
  %62 = tail call ptr @InitializeListHead(ptr noundef nonnull %61) #2
  %63 = getelementptr inbounds i8, ptr %1, i64 480
  %64 = tail call ptr @InitializeListHead(ptr noundef nonnull %63) #2
  %65 = getelementptr inbounds i8, ptr %1, i64 496
  %66 = tail call ptr @InitializeListHead(ptr noundef nonnull %65) #2
  %67 = getelementptr inbounds i8, ptr %1, i64 512
  %68 = tail call ptr @InitializeListHead(ptr noundef nonnull %67) #2
  %69 = getelementptr inbounds i8, ptr %1, i64 528
  %70 = tail call ptr @InitializeListHead(ptr noundef nonnull %69) #2
  %71 = getelementptr inbounds i8, ptr %1, i64 544
  store ptr null, ptr %71, align 8, !tbaa !14
  %72 = getelementptr inbounds i8, ptr %1, i64 552
  tail call void @Ip4InitRouteCache(ptr noundef nonnull %72)
  br label %73

73:                                               ; preds = %0, %3
  ret ptr %1
}

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 = !{!"_IP4_ROUTE_TABLE", !7, i64 0, !10, i64 8, !8, i64 16, !11, i64 544, !12, i64 552}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"", !8, i64 0}
!13 = !{!6, !10, i64 8}
!14 = !{!6, !11, i64 544}


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