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

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

@.str = external hidden unnamed_addr constant [155 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [29 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 i64 @StrSize(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i64 @AppendToMultiString(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = 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) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %18, label %11

11:                                               ; preds = %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %18, label %15

15:                                               ; preds = %11
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %15, %11, %2
  store i64 -9223372036854775806, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %58

19:                                               ; preds = %15
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = call i64 @StrSize(ptr noundef %20)
  store i64 %21, ptr %6, align 8, !tbaa !9
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = call i64 @StrSize(ptr noundef %23)
  store i64 %24, ptr %7, align 8, !tbaa !9
  %25 = load i64, ptr %7, align 8, !tbaa !9
  %26 = load i64, ptr %6, align 8, !tbaa !9
  %27 = add i64 %25, %26
  %28 = icmp ugt i64 %27, 1024
  br i1 %28, label %32, label %29

29:                                               ; preds = %19
  %30 = load i64, ptr %7, align 8, !tbaa !9
  %31 = icmp ugt i64 %30, 1024
  br i1 %31, label %32, label %53

32:                                               ; preds = %29, %19
  %33 = load i64, ptr %7, align 8, !tbaa !9
  %34 = load i64, ptr %7, align 8, !tbaa !9
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = add i64 %34, %35
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = call ptr @ReallocatePool(i64 noundef %33, i64 noundef %36, ptr noundef %38)
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %39, ptr %40, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %32
  %42 = call zeroext i8 @DebugAssertEnabled()
  %43 = icmp ne i8 %42, 0
  br i1 %43, label %44, label %50

44:                                               ; preds = %41
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load ptr, ptr %45, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %49, label %48

48:                                               ; preds = %44
  call void @DebugAssert(ptr noundef @.str, i64 noundef 413, ptr noundef @.str.13)
  br label %49

49:                                               ; preds = %48, %44
  br label %50

50:                                               ; preds = %49, %41
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52, %29
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = load ptr, ptr %54, align 8, !tbaa !5
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = call ptr @StrCat(ptr noundef %55, ptr noundef %56)
  store i64 0, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %58

58:                                               ; preds = %53, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %59 = load i64, ptr %3, align 8
  ret i64 %59
}

declare ptr @ReallocatePool(i64 noundef, i64 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, !10, i64 0}
!10 = !{!"long long", !7, 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"

@.str = external hidden unnamed_addr constant [155 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [29 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 i64 @StrSize(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775806, 1) i64 @AppendToMultiString(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %22, label %4

4:                                                ; preds = %2
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  %7 = icmp eq ptr %1, null
  %or.cond = or i1 %7, %6
  br i1 %or.cond, label %22, label %8

8:                                                ; preds = %4
  %9 = tail call i64 @StrSize(ptr noundef nonnull %1) #2
  %10 = load ptr, ptr %0, align 8, !tbaa !5
  %11 = tail call i64 @StrSize(ptr noundef %10) #2
  %12 = add i64 %11, %9
  %13 = icmp ugt i64 %12, 1024
  %14 = icmp ugt i64 %11, 1024
  %or.cond3 = or i1 %14, %13
  %.pre23 = load ptr, ptr %0, align 8, !tbaa !5
  br i1 %or.cond3, label %15, label %19

15:                                               ; preds = %8
  %16 = tail call ptr @ReallocatePool(i64 noundef %11, i64 noundef %12, ptr noundef %.pre23) #2
  store ptr %16, ptr %0, align 8, !tbaa !5
  %17 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp ne i8 %17, 0
  %.pre22 = load ptr, ptr %0, align 8, !tbaa !5
  %.not21 = icmp eq ptr %.pre22, null
  %or.cond24 = select i1 %.not, i1 %.not21, i1 false
  br i1 %or.cond24, label %18, label %19

18:                                               ; preds = %15
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 413, ptr noundef nonnull @.str.13) #2
  %.pre = load ptr, ptr %0, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %15, %18, %8
  %20 = phi ptr [ %.pre22, %15 ], [ %.pre, %18 ], [ %.pre23, %8 ]
  %21 = tail call ptr @StrCat(ptr noundef %20, ptr noundef nonnull %1) #2
  br label %22

22:                                               ; preds = %2, %4, %19
  %.0 = phi i64 [ 0, %19 ], [ -9223372036854775806, %4 ], [ -9223372036854775806, %2 ]
  ret i64 %.0
}

declare ptr @ReallocatePool(i64 noundef, i64 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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