; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdePkg/Library (UefiDevicePathLibCatPrint)

; 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.__va_list_tag = type { i32, i32, ptr, ptr }
%struct.POOL_PRINT = type { ptr, i64, i64 }

@.str = external hidden unnamed_addr constant [153 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef %1, ...) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca [1 x %struct.__va_list_tag], align 16
  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) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #4
  %7 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %6, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %7)
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %6, i64 0, i64 0
  %10 = call i64 @SPrintLength(ptr noundef %8, ptr noundef %9)
  store i64 %10, ptr %5, align 8, !tbaa !9
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.POOL_PRINT, ptr %11, i32 0, i32 1
  %13 = load i64, ptr %12, align 8, !tbaa !11
  %14 = load i64, ptr %5, align 8, !tbaa !9
  %15 = add i64 %14, 1
  %16 = add i64 %13, %15
  %17 = mul i64 %16, 2
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.POOL_PRINT, ptr %18, i32 0, i32 2
  %20 = load i64, ptr %19, align 8, !tbaa !13
  %21 = icmp ugt i64 %17, %20
  br i1 %21, label %22, label %59

22:                                               ; preds = %2
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.POOL_PRINT, ptr %23, i32 0, i32 1
  %25 = load i64, ptr %24, align 8, !tbaa !11
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = add i64 %26, 1
  %28 = mul i64 %27, 2
  %29 = add i64 %25, %28
  %30 = mul i64 %29, 2
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.POOL_PRINT, ptr %31, i32 0, i32 2
  store i64 %30, ptr %32, align 8, !tbaa !13
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.POOL_PRINT, ptr %33, i32 0, i32 1
  %35 = load i64, ptr %34, align 8, !tbaa !11
  %36 = mul i64 %35, 2
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.POOL_PRINT, ptr %37, i32 0, i32 2
  %39 = load i64, ptr %38, align 8, !tbaa !13
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.POOL_PRINT, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !14
  %43 = call ptr @ReallocatePool(i64 noundef %36, i64 noundef %39, ptr noundef %42)
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.POOL_PRINT, ptr %44, i32 0, i32 0
  store ptr %43, ptr %45, align 8, !tbaa !14
  br label %46

46:                                               ; preds = %22
  %47 = call zeroext i8 @DebugAssertEnabled()
  %48 = icmp ne i8 %47, 0
  br i1 %48, label %49, label %56

49:                                               ; preds = %46
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.POOL_PRINT, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !14
  %53 = icmp ne ptr %52, null
  br i1 %53, label %55, label %54

54:                                               ; preds = %49
  call void @DebugAssert(ptr noundef @.str, i64 noundef 52, ptr noundef @.str.1)
  br label %55

55:                                               ; preds = %54, %49
  br label %56

56:                                               ; preds = %55, %46
  br label %57

57:                                               ; preds = %56
  br label %58

58:                                               ; preds = %57
  br label %59

59:                                               ; preds = %58, %2
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.POOL_PRINT, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !14
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.POOL_PRINT, ptr %63, i32 0, i32 1
  %65 = load i64, ptr %64, align 8, !tbaa !11
  %66 = getelementptr inbounds i16, ptr %62, i64 %65
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.POOL_PRINT, ptr %67, i32 0, i32 2
  %69 = load i64, ptr %68, align 8, !tbaa !13
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.POOL_PRINT, ptr %70, i32 0, i32 1
  %72 = load i64, ptr %71, align 8, !tbaa !11
  %73 = mul i64 %72, 2
  %74 = sub i64 %69, %73
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %6, i64 0, i64 0
  %77 = call i64 @UnicodeVSPrint(ptr noundef %66, i64 noundef %74, ptr noundef %75, ptr noundef %76)
  %78 = load i64, ptr %5, align 8, !tbaa !9
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.POOL_PRINT, ptr %79, i32 0, i32 1
  %81 = load i64, ptr %80, align 8, !tbaa !11
  %82 = add i64 %81, %78
  store i64 %82, ptr %80, align 8, !tbaa !11
  %83 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %6, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %83)
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.POOL_PRINT, ptr %84, i32 0, i32 0
  %86 = load ptr, ptr %85, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret ptr %86
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #2

declare i64 @SPrintLength(ptr noundef, ptr noundef) #3

declare ptr @ReallocatePool(i64 noundef, i64 noundef, ptr noundef) #3

declare zeroext i8 @DebugAssertEnabled() #3

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

declare i64 @UnicodeVSPrint(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { "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 #4 = { 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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"", !6, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!12, !10, i64 16}
!14 = !{!12, !6, i64 0}


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

@.str = external hidden unnamed_addr constant [153 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @UefiDevicePathLibCatPrint(ptr nocapture noundef %0, ptr noundef %1, ...) local_unnamed_addr #0 {
  %3 = alloca [1 x %struct.__va_list_tag], align 16
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #4
  call void @llvm.va_start.p0(ptr nonnull %3)
  %4 = call i64 @SPrintLength(ptr noundef %1, ptr noundef nonnull %3) #4
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = add i64 %4, 1
  %8 = add i64 %6, %7
  %9 = shl i64 %8, 1
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %12 = icmp ugt i64 %9, %11
  %.pre21 = load ptr, ptr %0, align 8, !tbaa !12
  br i1 %12, label %13, label %20

13:                                               ; preds = %2
  %14 = shl i64 %7, 2
  %15 = shl i64 %6, 1
  %16 = add i64 %14, %15
  store i64 %16, ptr %10, align 8, !tbaa !11
  %17 = call ptr @ReallocatePool(i64 noundef %15, i64 noundef %16, ptr noundef %.pre21) #4
  store ptr %17, ptr %0, align 8, !tbaa !12
  %18 = call zeroext i8 @DebugAssertEnabled() #4
  %.not = icmp ne i8 %18, 0
  %.pre20 = load ptr, ptr %0, align 8, !tbaa !12
  %.not19 = icmp eq ptr %.pre20, null
  %or.cond = select i1 %.not, i1 %.not19, i1 false
  br i1 %or.cond, label %19, label %20

19:                                               ; preds = %13
  call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 52, ptr noundef nonnull @.str.1) #4
  %.pre = load ptr, ptr %0, align 8, !tbaa !12
  br label %20

20:                                               ; preds = %13, %19, %2
  %21 = phi ptr [ %.pre20, %13 ], [ %.pre, %19 ], [ %.pre21, %2 ]
  %22 = load i64, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds i16, ptr %21, i64 %22
  %24 = load i64, ptr %10, align 8, !tbaa !11
  %25 = shl i64 %22, 1
  %26 = sub i64 %24, %25
  %27 = call i64 @UnicodeVSPrint(ptr noundef %23, i64 noundef %26, ptr noundef %1, ptr noundef nonnull %3) #4
  %28 = load i64, ptr %5, align 8, !tbaa !5
  %29 = add i64 %28, %4
  store i64 %29, ptr %5, align 8, !tbaa !5
  call void @llvm.va_end.p0(ptr nonnull %3)
  %30 = load ptr, ptr %0, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #4
  ret ptr %30
}

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #2

declare i64 @SPrintLength(ptr noundef, ptr noundef) local_unnamed_addr #3

declare ptr @ReallocatePool(i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #3

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #3

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

declare i64 @UnicodeVSPrint(ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #3 = { "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 #4 = { 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, !10, i64 8}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!6, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass