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

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

@.str = external hidden unnamed_addr constant [163 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 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

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

declare zeroext i8 @DebugAssertEnabled() #1

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

; Function Attrs: nounwind uwtable
define dso_local i64 @SerializeVariablesAddVariable(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i64 noundef %4, ptr noundef %5) #2 {
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i64, align 8
  %19 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i32 %3, ptr %11, align 4, !tbaa !9
  store i64 %4, ptr %12, align 8, !tbaa !11
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  %20 = call zeroext i8 @DebugAssertEnabled()
  %21 = zext i8 %20 to i32
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %33

23:                                               ; preds = %6
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = ptrtoint ptr %24 to i64
  %26 = sub i64 %25, 0
  %27 = inttoptr i64 %26 to ptr
  %28 = getelementptr inbounds %struct.SV_INSTANCE, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !13
  %30 = icmp ne i32 %29, 1380013651
  br i1 %30, label %31, label %33

31:                                               ; preds = %23
  call void @DebugAssert(ptr noundef @.str, i64 noundef 758, ptr noundef @.str.1)
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  br label %38

33:                                               ; preds = %23, %6
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = ptrtoint ptr %34 to i64
  %36 = sub i64 %35, 0
  %37 = inttoptr i64 %36 to ptr
  br label %38

38:                                               ; preds = %33, %31
  %39 = phi ptr [ %32, %31 ], [ %37, %33 ]
  store ptr %39, ptr %15, align 8, !tbaa !5
  %40 = load ptr, ptr %15, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.SV_INSTANCE, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 8, !tbaa !13
  %43 = icmp ne i32 %42, 1380013651
  br i1 %43, label %53, label %44

44:                                               ; preds = %38
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = icmp eq ptr %45, null
  br i1 %46, label %53, label %47

47:                                               ; preds = %44
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = icmp eq ptr %48, null
  br i1 %49, label %53, label %50

50:                                               ; preds = %47
  %51 = load ptr, ptr %13, align 8, !tbaa !5
  %52 = icmp eq ptr %51, null
  br i1 %52, label %53, label %54

53:                                               ; preds = %50, %47, %44, %38
  br label %54

54:                                               ; preds = %53, %50
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = call i64 @StrSize(ptr noundef %55)
  %57 = trunc i64 %56 to i32
  store i32 %57, ptr %16, align 4, !tbaa !9
  %58 = load i32, ptr %16, align 4, !tbaa !9
  %59 = zext i32 %58 to i64
  %60 = add i64 4, %59
  %61 = add i64 %60, 16
  %62 = add i64 %61, 4
  %63 = add i64 %62, 4
  %64 = load i64, ptr %12, align 8, !tbaa !11
  %65 = add i64 %63, %64
  store i64 %65, ptr %18, align 8, !tbaa !11
  %66 = load ptr, ptr %15, align 8, !tbaa !5
  %67 = load i64, ptr %18, align 8, !tbaa !11
  %68 = call i64 @EnsureExtraBufferSpace(ptr noundef %66, i64 noundef %67)
  store i64 %68, ptr %14, align 8, !tbaa !11
  %69 = load i64, ptr %14, align 8, !tbaa !11
  %70 = icmp slt i64 %69, 0
  br i1 %70, label %71, label %73

71:                                               ; preds = %54
  %72 = load i64, ptr %14, align 8, !tbaa !11
  store i64 %72, ptr %7, align 8
  store i32 1, ptr %19, align 4
  br label %88

73:                                               ; preds = %54
  %74 = load ptr, ptr %15, align 8, !tbaa !5
  call void @AppendToBuffer(ptr noundef %74, ptr noundef %16, i64 noundef 4)
  %75 = load ptr, ptr %15, align 8, !tbaa !5
  %76 = load ptr, ptr %9, align 8, !tbaa !5
  %77 = load i32, ptr %16, align 4, !tbaa !9
  %78 = zext i32 %77 to i64
  call void @AppendToBuffer(ptr noundef %75, ptr noundef %76, i64 noundef %78)
  %79 = load ptr, ptr %15, align 8, !tbaa !5
  %80 = load ptr, ptr %10, align 8, !tbaa !5
  call void @AppendToBuffer(ptr noundef %79, ptr noundef %80, i64 noundef 16)
  %81 = load ptr, ptr %15, align 8, !tbaa !5
  call void @AppendToBuffer(ptr noundef %81, ptr noundef %11, i64 noundef 4)
  %82 = load i64, ptr %12, align 8, !tbaa !11
  %83 = trunc i64 %82 to i32
  store i32 %83, ptr %17, align 4, !tbaa !9
  %84 = load ptr, ptr %15, align 8, !tbaa !5
  call void @AppendToBuffer(ptr noundef %84, ptr noundef %17, i64 noundef 4)
  %85 = load ptr, ptr %15, align 8, !tbaa !5
  %86 = load ptr, ptr %13, align 8, !tbaa !5
  %87 = load i64, ptr %12, align 8, !tbaa !11
  call void @AppendToBuffer(ptr noundef %85, ptr noundef %86, i64 noundef %87)
  store i64 0, ptr %7, align 8
  store i32 1, ptr %19, align 4
  br label %88

88:                                               ; preds = %73, %71
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  %89 = load i64, ptr %7, align 8
  ret i64 %89
}

declare i64 @StrSize(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i64 @EnsureExtraBufferSpace(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @AppendToBuffer(ptr noundef, ptr noundef, i64 noundef) #2

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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"", !10, i64 0, !6, i64 8, !12, i64 16, !12, i64 24}


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

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

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

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775808, 1) i64 @SerializeVariablesAddVariable(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i64 noundef %4, ptr noundef %5) local_unnamed_addr #2 {
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %3, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %9) #3
  %10 = tail call zeroext i8 @DebugAssertEnabled() #3
  %.not = icmp eq i8 %10, 0
  br i1 %.not, label %14, label %11

11:                                               ; preds = %6
  %12 = load i32, ptr %0, align 8, !tbaa !9
  %.not30 = icmp eq i32 %12, 1380013651
  br i1 %.not30, label %14, label %13

13:                                               ; preds = %11
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 758, ptr noundef nonnull @.str.1) #3
  br label %14

14:                                               ; preds = %6, %11, %13
  %15 = tail call i64 @StrSize(ptr noundef %1) #3
  %16 = trunc i64 %15 to i32
  store i32 %16, ptr %8, align 4, !tbaa !5
  %17 = and i64 %15, 4294967295
  %18 = add i64 %4, 28
  %19 = add i64 %18, %17
  %20 = tail call i64 @EnsureExtraBufferSpace(ptr noundef %0, i64 noundef %19)
  %21 = icmp slt i64 %20, 0
  br i1 %21, label %26, label %22

22:                                               ; preds = %14
  call void @AppendToBuffer(ptr noundef %0, ptr noundef nonnull %8, i64 noundef 4)
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = zext i32 %23 to i64
  call void @AppendToBuffer(ptr noundef %0, ptr noundef %1, i64 noundef %24)
  call void @AppendToBuffer(ptr noundef %0, ptr noundef %2, i64 noundef 16)
  call void @AppendToBuffer(ptr noundef %0, ptr noundef nonnull %7, i64 noundef 4)
  %25 = trunc i64 %4 to i32
  store i32 %25, ptr %9, align 4, !tbaa !5
  call void @AppendToBuffer(ptr noundef %0, ptr noundef nonnull %9, i64 noundef 4)
  call void @AppendToBuffer(ptr noundef %0, ptr noundef %5, i64 noundef %4)
  br label %26

26:                                               ; preds = %14, %22
  %.0 = phi i64 [ 0, %22 ], [ %20, %14 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #3
  ret i64 %.0
}

declare i64 @StrSize(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i64 @EnsureExtraBufferSpace(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @AppendToBuffer(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = !{!"int", !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, !12, i64 16, !12, i64 24}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"long long", !7, i64 0}


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