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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @CatPrint(ptr noundef %0, ptr noundef %1, ...) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca [1 x %struct.__va_list_tag], align 16
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %10 = call ptr @AllocateZeroPool(i64 noundef 4096)
  store ptr %10, ptr %6, align 8, !tbaa !5
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %24

13:                                               ; preds = %2
  br label %14

14:                                               ; preds = %13
  %15 = call zeroext i8 @DebugAssertEnabled()
  %16 = icmp ne i8 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  call void @DebugAssert(ptr noundef @.str, i64 noundef 78, ptr noundef @.str.1)
  br label %18

18:                                               ; preds = %17, %14
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.POOL_PRINT, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  store ptr %23, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %110

24:                                               ; preds = %2
  %25 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %7, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %25)
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %7, i64 0, i64 0
  %29 = call i64 @UnicodeVSPrint(ptr noundef %26, i64 noundef 4096, ptr noundef %27, ptr noundef %28)
  %30 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %7, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %30)
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.POOL_PRINT, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  %34 = icmp eq ptr null, %33
  br i1 %34, label %35, label %55

35:                                               ; preds = %24
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = call i64 @StrSize(ptr noundef %36)
  store i64 %37, ptr %8, align 8, !tbaa !12
  %38 = load i64, ptr %8, align 8, !tbaa !12
  %39 = call ptr @AllocateZeroPool(i64 noundef %38)
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.POOL_PRINT, ptr %40, i32 0, i32 0
  store ptr %39, ptr %41, align 8, !tbaa !9
  br label %42

42:                                               ; preds = %35
  %43 = call zeroext i8 @DebugAssertEnabled()
  %44 = icmp ne i8 %43, 0
  br i1 %44, label %45, label %52

45:                                               ; preds = %42
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.POOL_PRINT, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !9
  %49 = icmp ne ptr %48, null
  br i1 %49, label %51, label %50

50:                                               ; preds = %45
  call void @DebugAssert(ptr noundef @.str, i64 noundef 88, ptr noundef @.str.2)
  br label %51

51:                                               ; preds = %50, %45
  br label %52

52:                                               ; preds = %51, %42
  br label %53

53:                                               ; preds = %52
  br label %54

54:                                               ; preds = %53
  br label %89

55:                                               ; preds = %24
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = call i64 @StrSize(ptr noundef %56)
  store i64 %57, ptr %8, align 8, !tbaa !12
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.POOL_PRINT, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !9
  %61 = call i64 @StrSize(ptr noundef %60)
  %62 = sub i64 %61, 2
  %63 = load i64, ptr %8, align 8, !tbaa !12
  %64 = add i64 %63, %62
  store i64 %64, ptr %8, align 8, !tbaa !12
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.POOL_PRINT, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !9
  %68 = call i64 @StrSize(ptr noundef %67)
  %69 = load i64, ptr %8, align 8, !tbaa !12
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.POOL_PRINT, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !9
  %73 = call ptr @ReallocatePool(i64 noundef %68, i64 noundef %69, ptr noundef %72)
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.POOL_PRINT, ptr %74, i32 0, i32 0
  store ptr %73, ptr %75, align 8, !tbaa !9
  br label %76

76:                                               ; preds = %55
  %77 = call zeroext i8 @DebugAssertEnabled()
  %78 = icmp ne i8 %77, 0
  br i1 %78, label %79, label %86

79:                                               ; preds = %76
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.POOL_PRINT, ptr %80, i32 0, i32 0
  %82 = load ptr, ptr %81, align 8, !tbaa !9
  %83 = icmp ne ptr %82, null
  br i1 %83, label %85, label %84

84:                                               ; preds = %79
  call void @DebugAssert(ptr noundef @.str, i64 noundef 98, ptr noundef @.str.2)
  br label %85

85:                                               ; preds = %84, %79
  br label %86

86:                                               ; preds = %85, %76
  br label %87

87:                                               ; preds = %86
  br label %88

88:                                               ; preds = %87
  br label %89

89:                                               ; preds = %88, %54
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.POOL_PRINT, ptr %90, i32 0, i32 0
  %92 = load ptr, ptr %91, align 8, !tbaa !9
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  %94 = load i64, ptr %8, align 8, !tbaa !12
  %95 = udiv i64 %94, 2
  %96 = sub i64 %95, 1
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.POOL_PRINT, ptr %97, i32 0, i32 0
  %99 = load ptr, ptr %98, align 8, !tbaa !9
  %100 = call i64 @StrLen(ptr noundef %99)
  %101 = sub i64 %96, %100
  %102 = call ptr @StrnCat(ptr noundef %92, ptr noundef %93, i64 noundef %101)
  %103 = load i64, ptr %8, align 8, !tbaa !12
  %104 = load ptr, ptr %4, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.POOL_PRINT, ptr %104, i32 0, i32 1
  store i64 %103, ptr %105, align 8, !tbaa !13
  %106 = load ptr, ptr %6, align 8, !tbaa !5
  call void @FreePool(ptr noundef %106)
  %107 = load ptr, ptr %4, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.POOL_PRINT, ptr %107, i32 0, i32 0
  %109 = load ptr, ptr %108, align 8, !tbaa !9
  store ptr %109, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %110

110:                                              ; preds = %89, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %111 = load ptr, ptr %3, align 8
  ret ptr %111
}

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

declare ptr @AllocateZeroPool(i64 noundef) #2

declare zeroext i8 @DebugAssertEnabled() #2

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

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

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

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

declare i64 @StrSize(ptr noundef) #2

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

declare ptr @StrnCat(ptr noundef, ptr noundef, i64 noundef) #2

declare i64 @StrLen(ptr noundef) #2

declare void @FreePool(ptr noundef) #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 = { "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 = { nocallback nofree nosync nounwind willreturn }
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, !6, i64 0}
!10 = !{!"", !6, i64 0, !11, i64 8}
!11 = !{!"long long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 8}


; 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 [155 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @CatPrint(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
  %4 = tail call ptr @AllocateZeroPool(i64 noundef 4096) #4
  %5 = icmp eq ptr %4, null
  br i1 %5, label %6, label %9

6:                                                ; preds = %2
  %7 = tail call zeroext i8 @DebugAssertEnabled() #4
  %.not30 = icmp eq i8 %7, 0
  br i1 %.not30, label %39, label %8

8:                                                ; preds = %6
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 78, ptr noundef nonnull @.str.1) #4
  br label %39

9:                                                ; preds = %2
  call void @llvm.va_start.p0(ptr nonnull %3)
  %10 = call i64 @UnicodeVSPrint(ptr noundef nonnull %4, i64 noundef 4096, ptr noundef %1, ptr noundef nonnull %3) #4
  call void @llvm.va_end.p0(ptr nonnull %3)
  %11 = load ptr, ptr %0, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  %13 = call i64 @StrSize(ptr noundef nonnull %4) #4
  br i1 %12, label %14, label %19

14:                                               ; preds = %9
  %15 = call ptr @AllocateZeroPool(i64 noundef %13) #4
  store ptr %15, ptr %0, align 8, !tbaa !5
  %16 = call zeroext i8 @DebugAssertEnabled() #4
  %.not28 = icmp eq i8 %16, 0
  br i1 %.not28, label %31, label %17

17:                                               ; preds = %14
  %18 = load ptr, ptr %0, align 8, !tbaa !5
  %.not29 = icmp eq ptr %18, null
  br i1 %.not29, label %.sink.split, label %31

19:                                               ; preds = %9
  %20 = load ptr, ptr %0, align 8, !tbaa !5
  %21 = call i64 @StrSize(ptr noundef %20) #4
  %22 = add i64 %13, -2
  %23 = add i64 %22, %21
  %24 = load ptr, ptr %0, align 8, !tbaa !5
  %25 = call i64 @StrSize(ptr noundef %24) #4
  %26 = load ptr, ptr %0, align 8, !tbaa !5
  %27 = call ptr @ReallocatePool(i64 noundef %25, i64 noundef %23, ptr noundef %26) #4
  store ptr %27, ptr %0, align 8, !tbaa !5
  %28 = call zeroext i8 @DebugAssertEnabled() #4
  %.not = icmp eq i8 %28, 0
  br i1 %.not, label %31, label %29

29:                                               ; preds = %19
  %30 = load ptr, ptr %0, align 8, !tbaa !5
  %.not27 = icmp eq ptr %30, null
  br i1 %.not27, label %.sink.split, label %31

.sink.split:                                      ; preds = %29, %17
  %.sink = phi i64 [ 88, %17 ], [ 98, %29 ]
  %.0.ph = phi i64 [ %13, %17 ], [ %23, %29 ]
  call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef %.sink, ptr noundef nonnull @.str.2) #4
  br label %31

31:                                               ; preds = %.sink.split, %19, %29, %14, %17
  %.0 = phi i64 [ %13, %17 ], [ %13, %14 ], [ %23, %29 ], [ %23, %19 ], [ %.0.ph, %.sink.split ]
  %32 = load ptr, ptr %0, align 8, !tbaa !5
  %33 = lshr i64 %.0, 1
  %34 = call i64 @StrLen(ptr noundef %32) #4
  %35 = xor i64 %34, -1
  %36 = add i64 %33, %35
  %37 = call ptr @StrnCat(ptr noundef %32, ptr noundef nonnull %4, i64 noundef %36) #4
  %38 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %.0, ptr %38, align 8, !tbaa !11
  call void @FreePool(ptr noundef nonnull %4) #4
  br label %39

39:                                               ; preds = %6, %8, %31
  %.025 = load ptr, ptr %0, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #4
  ret ptr %.025
}

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

declare ptr @AllocateZeroPool(i64 noundef) local_unnamed_addr #2

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #2

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

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

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

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

declare i64 @StrSize(ptr noundef) local_unnamed_addr #2

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

declare ptr @StrnCat(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare i64 @StrLen(ptr noundef) local_unnamed_addr #2

declare void @FreePool(ptr noundef) local_unnamed_addr #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 = { "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 = { mustprogress nocallback nofree nosync nounwind willreturn }
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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8}
!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 8}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass