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

; 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 }
%struct.IFR_DEFAULT_DATA = type { %struct._LIST_ENTRY, i32, i8, i16, %union.EFI_IFR_TYPE_VALUE }
%union.EFI_IFR_TYPE_VALUE = type <{ i64, [14 x i8] }>

@.str = external hidden unnamed_addr constant [155 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [34 x i8], align 1

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

declare zeroext i8 @DebugAssertEnabled() #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #1

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

declare ptr @AllocateZeroPool(i64 noundef) #1

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @InsertDefaultValue(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 %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %9, i32 0, i32 6
  store ptr %10, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._LIST_ENTRY, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %13, ptr %5, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %58, %2
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = icmp ne ptr %15, %16
  br i1 %17, label %18, label %62

18:                                               ; preds = %14
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = ptrtoint ptr %19 to i64
  %21 = sub i64 %20, 0
  %22 = inttoptr i64 %21 to ptr
  store ptr %22, ptr %6, align 8, !tbaa !5
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.IFR_DEFAULT_DATA, ptr %23, i32 0, i32 3
  %25 = load i16, ptr %24, align 2, !tbaa !11
  %26 = zext i16 %25 to i32
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.IFR_DEFAULT_DATA, ptr %27, i32 0, i32 3
  %29 = load i16, ptr %28, align 2, !tbaa !11
  %30 = zext i16 %29 to i32
  %31 = icmp eq i32 %26, %30
  br i1 %31, label %32, label %57

32:                                               ; preds = %18
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.IFR_DEFAULT_DATA, ptr %33, i32 0, i32 1
  %35 = load i32, ptr %34, align 8, !tbaa !15
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.IFR_DEFAULT_DATA, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 8, !tbaa !15
  %39 = icmp ugt i32 %35, %38
  br i1 %39, label %40, label %56

40:                                               ; preds = %32
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.IFR_DEFAULT_DATA, ptr %41, i32 0, i32 4
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.IFR_DEFAULT_DATA, ptr %43, i32 0, i32 4
  %45 = call ptr @CopyMem(ptr noundef %42, ptr noundef %44, i64 noundef 22)
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.IFR_DEFAULT_DATA, ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 8, !tbaa !15
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.IFR_DEFAULT_DATA, ptr %49, i32 0, i32 1
  store i32 %48, ptr %50, align 8, !tbaa !15
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.IFR_DEFAULT_DATA, ptr %51, i32 0, i32 2
  %53 = load i8, ptr %52, align 4, !tbaa !16
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.IFR_DEFAULT_DATA, ptr %54, i32 0, i32 2
  store i8 %53, ptr %55, align 4, !tbaa !16
  br label %56

56:                                               ; preds = %40, %32
  store i32 1, ptr %8, align 4
  br label %82

57:                                               ; preds = %18
  br label %58

58:                                               ; preds = %57
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._LIST_ENTRY, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !9
  store ptr %61, ptr %5, align 8, !tbaa !5
  br label %14, !llvm.loop !17

62:                                               ; preds = %14
  %63 = call ptr @AllocateZeroPool(i64 noundef 48)
  store ptr %63, ptr %6, align 8, !tbaa !5
  br label %64

64:                                               ; preds = %62
  %65 = call zeroext i8 @DebugAssertEnabled()
  %66 = icmp ne i8 %65, 0
  br i1 %66, label %67, label %72

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

70:                                               ; preds = %67
  call void @DebugAssert(ptr noundef @.str, i64 noundef 682, ptr noundef @.str.17)
  br label %71

71:                                               ; preds = %70, %67
  br label %72

72:                                               ; preds = %71, %64
  br label %73

73:                                               ; preds = %72
  br label %74

74:                                               ; preds = %73
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = call ptr @CopyMem(ptr noundef %75, ptr noundef %76, i64 noundef 48)
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.IFR_DEFAULT_DATA, ptr %79, i32 0, i32 0
  %81 = call ptr @InsertTailList(ptr noundef %78, ptr noundef %80)
  store i32 0, ptr %8, align 4
  br label %82

82:                                               ; preds = %74, %56
  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
  %83 = load i32, ptr %8, align 4
  switch i32 %83, label %85 [
    i32 0, label %84
    i32 1, label %84
  ]

84:                                               ; preds = %82, %82
  ret void

85:                                               ; preds = %82
  unreachable
}

declare ptr @InsertTailList(ptr noundef, 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, !6, i64 0}
!10 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!11 = !{!12, !14, i64 22}
!12 = !{!"", !10, i64 0, !13, i64 16, !7, i64 20, !14, i64 22, !7, i64 24}
!13 = !{!"int", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!12, !13, i64 16}
!16 = !{!12, !7, i64 20}
!17 = distinct !{!17, !18}
!18 = !{!"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"

@.str = external hidden unnamed_addr constant [155 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [34 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

declare ptr @AllocateZeroPool(i64 noundef) local_unnamed_addr #0

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @InsertDefaultValue(ptr noundef readonly %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = getelementptr inbounds i8, ptr %1, i64 22
  br label %5

5:                                                ; preds = %6, %2
  %.0.in = phi ptr [ %3, %2 ], [ %.0, %6 ]
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, %3
  br i1 %.not, label %25, label %6

6:                                                ; preds = %5
  %7 = getelementptr inbounds i8, ptr %.0, i64 22
  %8 = load i16, ptr %7, align 2, !tbaa !10
  %9 = load i16, ptr %4, align 2, !tbaa !10
  %10 = icmp eq i16 %8, %9
  br i1 %10, label %11, label %5, !llvm.loop !14

11:                                               ; preds = %6
  %12 = getelementptr inbounds i8, ptr %1, i64 16
  %13 = load i32, ptr %12, align 8, !tbaa !16
  %14 = getelementptr inbounds i8, ptr %.0, i64 16
  %15 = load i32, ptr %14, align 8, !tbaa !16
  %16 = icmp ugt i32 %13, %15
  br i1 %16, label %17, label %34

17:                                               ; preds = %11
  %18 = getelementptr inbounds i8, ptr %.0, i64 24
  %19 = getelementptr inbounds i8, ptr %1, i64 24
  %20 = tail call ptr @CopyMem(ptr noundef nonnull %18, ptr noundef nonnull %19, i64 noundef 22) #2
  %21 = load i32, ptr %12, align 8, !tbaa !16
  store i32 %21, ptr %14, align 8, !tbaa !16
  %22 = getelementptr inbounds i8, ptr %1, i64 20
  %23 = load i8, ptr %22, align 4, !tbaa !17
  %24 = getelementptr inbounds i8, ptr %.0, i64 20
  store i8 %23, ptr %24, align 4, !tbaa !17
  br label %34

25:                                               ; preds = %5
  %26 = tail call ptr @AllocateZeroPool(i64 noundef 48) #2
  %27 = tail call zeroext i8 @DebugAssertEnabled() #2
  %28 = icmp eq i8 %27, 0
  %29 = icmp ne ptr %26, null
  %or.cond = select i1 %28, i1 true, i1 %29
  br i1 %or.cond, label %31, label %30

30:                                               ; preds = %25
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 682, ptr noundef nonnull @.str.17) #2
  br label %31

31:                                               ; preds = %30, %25
  %32 = tail call ptr @CopyMem(ptr noundef %26, ptr noundef %1, i64 noundef 48) #2
  %33 = tail call ptr @InsertTailList(ptr noundef %.0, ptr noundef %26) #2
  br label %34

34:                                               ; preds = %11, %17, %31
  ret void
}

declare ptr @InsertTailList(ptr noundef, 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 = !{!"_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 = !{!11, !13, i64 22}
!11 = !{!"", !6, i64 0, !12, i64 16, !8, i64 20, !13, i64 22, !8, i64 24}
!12 = !{!"int", !8, i64 0}
!13 = !{!"short", !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!11, !12, i64 16}
!17 = !{!11, !8, i64 20}


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