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

; 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.IFR_BLOCK_DATA = type { %struct._LIST_ENTRY, i16, i16, i16, i8, i8, %struct._LIST_ENTRY, ptr }
%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

declare void @FreePool(ptr noundef) #1

declare ptr @InsertTailList(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @InsertBlockData(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %10, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %11, i32 0, i32 7
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %20

15:                                               ; preds = %2
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %17, i32 0, i32 0
  %19 = call ptr @InsertTailList(ptr noundef %16, ptr noundef %18)
  store i32 1, ptr %8, align 4
  br label %103

20:                                               ; preds = %2
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._LIST_ENTRY, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  store ptr %23, ptr %5, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %94, %20
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = icmp ne ptr %25, %26
  br i1 %27, label %28, label %98

28:                                               ; preds = %24
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = ptrtoint ptr %29 to i64
  %31 = sub i64 %30, 0
  %32 = inttoptr i64 %31 to ptr
  store ptr %32, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %33, i32 0, i32 1
  %35 = load i16, ptr %34, align 8, !tbaa !14
  %36 = zext i16 %35 to i32
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %37, i32 0, i32 1
  %39 = load i16, ptr %38, align 8, !tbaa !14
  %40 = zext i16 %39 to i32
  %41 = icmp eq i32 %36, %40
  br i1 %41, label %42, label %77

42:                                               ; preds = %28
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %43, i32 0, i32 2
  %45 = load i16, ptr %44, align 2, !tbaa !15
  %46 = zext i16 %45 to i32
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %47, i32 0, i32 2
  %49 = load i16, ptr %48, align 2, !tbaa !15
  %50 = zext i16 %49 to i32
  %51 = icmp sgt i32 %46, %50
  br i1 %51, label %52, label %57

52:                                               ; preds = %42
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %54, i32 0, i32 0
  %56 = call ptr @InsertTailList(ptr noundef %53, ptr noundef %55)
  store i32 1, ptr %8, align 4
  br label %103

57:                                               ; preds = %42
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %58, i32 0, i32 2
  %60 = load i16, ptr %59, align 2, !tbaa !15
  %61 = zext i16 %60 to i32
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %62, i32 0, i32 2
  %64 = load i16, ptr %63, align 2, !tbaa !15
  %65 = zext i16 %64 to i32
  %66 = icmp eq i32 %61, %65
  br i1 %66, label %67, label %76

67:                                               ; preds = %57
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = icmp ne ptr %68, %69
  br i1 %70, label %71, label %75

71:                                               ; preds = %67
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  call void @FreePool(ptr noundef %72)
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %73, ptr %74, align 8, !tbaa !5
  br label %75

75:                                               ; preds = %71, %67
  store i32 1, ptr %8, align 4
  br label %103

76:                                               ; preds = %57
  br label %93

77:                                               ; preds = %28
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %78, i32 0, i32 1
  %80 = load i16, ptr %79, align 8, !tbaa !14
  %81 = zext i16 %80 to i32
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %82, i32 0, i32 1
  %84 = load i16, ptr %83, align 8, !tbaa !14
  %85 = zext i16 %84 to i32
  %86 = icmp sgt i32 %81, %85
  br i1 %86, label %87, label %92

87:                                               ; preds = %77
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %89, i32 0, i32 0
  %91 = call ptr @InsertTailList(ptr noundef %88, ptr noundef %90)
  store i32 1, ptr %8, align 4
  br label %103

92:                                               ; preds = %77
  br label %93

93:                                               ; preds = %92, %76
  br label %94

94:                                               ; preds = %93
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct._LIST_ENTRY, ptr %95, i32 0, i32 0
  %97 = load ptr, ptr %96, align 8, !tbaa !13
  store ptr %97, ptr %5, align 8, !tbaa !5
  br label %24, !llvm.loop !16

98:                                               ; preds = %24
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = load ptr, ptr %7, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %100, i32 0, i32 0
  %102 = call ptr @InsertTailList(ptr noundef %99, ptr noundef %101)
  store i32 0, ptr %8, align 4
  br label %103

103:                                              ; preds = %98, %87, %75, %52, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  %104 = load i32, ptr %8, align 4
  switch i32 %104, label %106 [
    i32 0, label %105
    i32 1, label %105
  ]

105:                                              ; preds = %103, %103
  ret void

106:                                              ; preds = %103
  unreachable
}

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, !6, i64 40}
!10 = !{!"", !11, i64 0, !12, i64 16, !12, i64 18, !12, i64 20, !7, i64 22, !7, i64 23, !11, i64 24, !6, i64 40}
!11 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!12 = !{!"short", !7, i64 0}
!13 = !{!11, !6, i64 0}
!14 = !{!10, !12, i64 16}
!15 = !{!10, !12, i64 18}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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

declare ptr @InsertTailList(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @InsertBlockData(ptr noundef %0, ptr nocapture noundef %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr %1, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 40
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %.preheader, label %9

.preheader:                                       ; preds = %2
  %.038 = load ptr, ptr %0, align 8, !tbaa !13
  %.not3339 = icmp eq ptr %.038, %0
  br i1 %.not3339, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %6 = getelementptr inbounds i8, ptr %3, i64 16
  %7 = load i16, ptr %6, align 8, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %3, i64 18
  br label %11

9:                                                ; preds = %2
  %10 = tail call ptr @InsertTailList(ptr noundef %0, ptr noundef nonnull %3) #2
  br label %32

11:                                               ; preds = %.lr.ph, %30
  %.040 = phi ptr [ %.038, %.lr.ph ], [ %.0, %30 ]
  %12 = getelementptr inbounds i8, ptr %.040, i64 16
  %13 = load i16, ptr %12, align 8, !tbaa !14
  %14 = icmp eq i16 %13, %7
  br i1 %14, label %15, label %26

15:                                               ; preds = %11
  %16 = getelementptr inbounds i8, ptr %.040, i64 18
  %17 = load i16, ptr %16, align 2, !tbaa !15
  %18 = load i16, ptr %8, align 2, !tbaa !15
  %19 = icmp ugt i16 %17, %18
  br i1 %19, label %20, label %22

20:                                               ; preds = %15
  %21 = tail call ptr @InsertTailList(ptr noundef nonnull %.040, ptr noundef nonnull %3) #2
  br label %32

22:                                               ; preds = %15
  %23 = icmp eq i16 %17, %18
  br i1 %23, label %24, label %30

24:                                               ; preds = %22
  %.not34 = icmp eq ptr %3, %.040
  br i1 %.not34, label %32, label %25

25:                                               ; preds = %24
  tail call void @FreePool(ptr noundef nonnull %3) #2
  store ptr %.040, ptr %1, align 8, !tbaa !5
  br label %32

26:                                               ; preds = %11
  %27 = icmp ugt i16 %13, %7
  br i1 %27, label %28, label %30

28:                                               ; preds = %26
  %29 = tail call ptr @InsertTailList(ptr noundef nonnull %.040, ptr noundef nonnull %3) #2
  br label %32

30:                                               ; preds = %22, %26
  %.0 = load ptr, ptr %.040, align 8, !tbaa !13
  %.not33 = icmp eq ptr %.0, %0
  br i1 %.not33, label %._crit_edge, label %11, !llvm.loop !16

._crit_edge:                                      ; preds = %30, %.preheader
  %.0.lcssa = phi ptr [ %.038, %.preheader ], [ %.0, %30 ]
  %31 = tail call ptr @InsertTailList(ptr noundef %.0.lcssa, ptr noundef nonnull %3) #2
  br label %32

32:                                               ; preds = %24, %25, %._crit_edge, %28, %20, %9
  ret void
}

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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 40}
!10 = !{!"", !11, i64 0, !12, i64 16, !12, i64 18, !12, i64 20, !7, i64 22, !7, i64 23, !11, i64 24, !6, i64 40}
!11 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!12 = !{!"short", !7, i64 0}
!13 = !{!11, !6, i64 0}
!14 = !{!10, !12, i64 16}
!15 = !{!10, !12, i64 18}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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