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

; 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_VARSTORAGE_DATA = type { %struct._LIST_ENTRY, %struct.GUID, ptr, i16, i8, %struct._LIST_ENTRY }
%struct.GUID = type { i32, i16, i16, [8 x i8] }
%struct._LIST_ENTRY = type { ptr, ptr }

@.str.2 = external hidden unnamed_addr constant [6 x i32], align 4
@.str.5 = external hidden unnamed_addr constant [6 x i32], align 4
@.str.11 = external hidden unnamed_addr constant [2 x i32], align 4
@.str.23 = external hidden unnamed_addr constant [6 x i32], align 4

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

declare i64 @StrLen(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 void @FreePool(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @GenerateSubStr(ptr noundef, i64 noundef, ptr noundef, i8 noundef zeroext, ptr noundef) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @GenerateHdr(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store i64 0, ptr %11, align 8, !tbaa !9
  store ptr null, ptr %8, align 8, !tbaa !5
  store ptr null, ptr %7, align 8, !tbaa !5
  store ptr null, ptr %9, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.IFR_VARSTORAGE_DATA, ptr %12, i32 0, i32 1
  call void @GenerateSubStr(ptr noundef @.str.2, i64 noundef 16, ptr noundef %13, i8 noundef zeroext 1, ptr noundef %7)
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.IFR_VARSTORAGE_DATA, ptr %14, i32 0, i32 2
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %27

18:                                               ; preds = %3
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.IFR_VARSTORAGE_DATA, ptr %19, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = call i64 @StrLen(ptr noundef %21)
  %23 = mul i64 %22, 2
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.IFR_VARSTORAGE_DATA, ptr %24, i32 0, i32 2
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  call void @GenerateSubStr(ptr noundef @.str.23, i64 noundef %23, ptr noundef %26, i8 noundef zeroext 2, ptr noundef %8)
  br label %28

27:                                               ; preds = %3
  call void @GenerateSubStr(ptr noundef @.str.23, i64 noundef 0, ptr noundef null, i8 noundef zeroext 2, ptr noundef %8)
  br label %28

28:                                               ; preds = %27, %18
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = call i64 @GetDevicePathSize(ptr noundef %29)
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  call void @GenerateSubStr(ptr noundef @.str.5, i64 noundef %30, ptr noundef %31, i8 noundef zeroext 1, ptr noundef %9)
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = call i64 @StrLen(ptr noundef %32)
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = call i64 @StrLen(ptr noundef %34)
  %36 = add i64 %33, %35
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = call i64 @StrLen(ptr noundef %37)
  %39 = add i64 %36, %38
  %40 = add i64 %39, 1
  store i64 %40, ptr %10, align 8, !tbaa !9
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.IFR_VARSTORAGE_DATA, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !11
  %44 = icmp eq ptr %43, null
  br i1 %44, label %45, label %48

45:                                               ; preds = %28
  %46 = load i64, ptr %10, align 8, !tbaa !9
  %47 = add i64 %46, 1
  store i64 %47, ptr %10, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %45, %28
  %49 = load i64, ptr %10, align 8, !tbaa !9
  %50 = mul i64 %49, 2
  %51 = call ptr @AllocateZeroPool(i64 noundef %50)
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %51, ptr %52, align 8, !tbaa !5
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  %55 = icmp eq ptr %54, null
  br i1 %55, label %56, label %57

56:                                               ; preds = %48
  store i64 -9223372036854775799, ptr %11, align 8, !tbaa !9
  br label %86

57:                                               ; preds = %48
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = call ptr @StrCpy(ptr noundef %59, ptr noundef %60)
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load ptr, ptr %62, align 8, !tbaa !5
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = call ptr @StrCat(ptr noundef %63, ptr noundef %64)
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.IFR_VARSTORAGE_DATA, ptr %66, i32 0, i32 2
  %68 = load ptr, ptr %67, align 8, !tbaa !11
  %69 = icmp eq ptr %68, null
  br i1 %69, label %70, label %74

70:                                               ; preds = %57
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = load ptr, ptr %71, align 8, !tbaa !5
  %73 = call ptr @StrCat(ptr noundef %72, ptr noundef @.str.11)
  br label %74

74:                                               ; preds = %70, %57
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = load ptr, ptr %75, align 8, !tbaa !5
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = call ptr @StrCat(ptr noundef %76, ptr noundef %77)
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = load ptr, ptr %79, align 8, !tbaa !5
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = load ptr, ptr %81, align 8, !tbaa !5
  %83 = call i64 @StrLen(ptr noundef %82)
  %84 = getelementptr inbounds i16, ptr %80, i64 %83
  %85 = getelementptr inbounds i16, ptr %84, i64 -1
  store i16 0, ptr %85, align 2, !tbaa !17
  br label %86

86:                                               ; preds = %74, %56
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  %88 = icmp ne ptr %87, null
  br i1 %88, label %89, label %91

89:                                               ; preds = %86
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  call void @FreePool(ptr noundef %90)
  br label %91

91:                                               ; preds = %89, %86
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = icmp ne ptr %92, null
  br i1 %93, label %94, label %96

94:                                               ; preds = %91
  %95 = load ptr, ptr %8, align 8, !tbaa !5
  call void @FreePool(ptr noundef %95)
  br label %96

96:                                               ; preds = %94, %91
  %97 = load ptr, ptr %9, align 8, !tbaa !5
  %98 = icmp ne ptr %97, null
  br i1 %98, label %99, label %101

99:                                               ; preds = %96
  %100 = load ptr, ptr %9, align 8, !tbaa !5
  call void @FreePool(ptr noundef %100)
  br label %101

101:                                              ; preds = %99, %96
  %102 = load i64, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i64 %102
}

declare i64 @GetDevicePathSize(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}
!11 = !{!12, !6, i64 32}
!12 = !{!"", !13, i64 0, !14, i64 16, !6, i64 32, !16, i64 40, !7, i64 42, !13, i64 48}
!13 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!14 = !{!"", !15, i64 0, !16, i64 4, !16, i64 6, !7, i64 8}
!15 = !{!"int", !7, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!16, !16, 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.2 = external hidden unnamed_addr constant [6 x i32], align 4
@.str.5 = external hidden unnamed_addr constant [6 x i32], align 4
@.str.11 = external hidden unnamed_addr constant [2 x i32], align 4
@.str.23 = external hidden unnamed_addr constant [6 x i32], align 4

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

declare i64 @StrLen(ptr noundef) local_unnamed_addr #1

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

declare ptr @AllocateZeroPool(i64 noundef) local_unnamed_addr #1

declare void @FreePool(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @GenerateSubStr(ptr noundef, i64 noundef, ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #2

declare ptr @StrCpy(ptr noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775799, 1) i64 @GenerateHdr(ptr noundef %0, ptr noundef %1, ptr nocapture noundef %2) local_unnamed_addr #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  store ptr null, ptr %5, align 8, !tbaa !5
  store ptr null, ptr %4, align 8, !tbaa !5
  store ptr null, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  call void @GenerateSubStr(ptr noundef nonnull @.str.2, i64 noundef 16, ptr noundef nonnull %7, i8 noundef zeroext 1, ptr noundef nonnull %4)
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %14, label %10

10:                                               ; preds = %3
  %11 = call i64 @StrLen(ptr noundef nonnull %9) #3
  %12 = shl i64 %11, 1
  %13 = load ptr, ptr %8, align 8, !tbaa !9
  call void @GenerateSubStr(ptr noundef nonnull @.str.23, i64 noundef %12, ptr noundef %13, i8 noundef zeroext 2, ptr noundef nonnull %5)
  br label %15

14:                                               ; preds = %3
  call void @GenerateSubStr(ptr noundef nonnull @.str.23, i64 noundef 0, ptr noundef null, i8 noundef zeroext 2, ptr noundef nonnull %5)
  br label %15

15:                                               ; preds = %14, %10
  %16 = call i64 @GetDevicePathSize(ptr noundef %1) #3
  call void @GenerateSubStr(ptr noundef nonnull @.str.5, i64 noundef %16, ptr noundef %1, i8 noundef zeroext 1, ptr noundef nonnull %6)
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = call i64 @StrLen(ptr noundef %17) #3
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call i64 @StrLen(ptr noundef %19) #3
  %21 = add i64 %20, %18
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = call i64 @StrLen(ptr noundef %22) #3
  %24 = add i64 %21, %23
  %25 = load ptr, ptr %8, align 8, !tbaa !9
  %26 = icmp eq ptr %25, null
  %spec.select.v = select i1 %26, i64 2, i64 1
  %spec.select = add i64 %24, %spec.select.v
  %27 = shl i64 %spec.select, 1
  %28 = call ptr @AllocateZeroPool(i64 noundef %27) #3
  store ptr %28, ptr %2, align 8, !tbaa !5
  %29 = icmp eq ptr %28, null
  br i1 %29, label %49, label %30

30:                                               ; preds = %15
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = call ptr @StrCpy(ptr noundef nonnull %28, ptr noundef %31) #3
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = call ptr @StrCat(ptr noundef %33, ptr noundef %34) #3
  %36 = load ptr, ptr %8, align 8, !tbaa !9
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %41

38:                                               ; preds = %30
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = call ptr @StrCat(ptr noundef %39, ptr noundef nonnull @.str.11) #3
  br label %41

41:                                               ; preds = %38, %30
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = call ptr @StrCat(ptr noundef %42, ptr noundef %43) #3
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = call i64 @StrLen(ptr noundef %45) #3
  %47 = getelementptr inbounds i16, ptr %45, i64 %46
  %48 = getelementptr inbounds i8, ptr %47, i64 -2
  store i16 0, ptr %48, align 2, !tbaa !15
  br label %49

49:                                               ; preds = %15, %41
  %.0 = phi i64 [ 0, %41 ], [ -9223372036854775799, %15 ]
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %.not24 = icmp eq ptr %50, null
  br i1 %.not24, label %52, label %51

51:                                               ; preds = %49
  call void @FreePool(ptr noundef nonnull %50) #3
  br label %52

52:                                               ; preds = %51, %49
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %.not25 = icmp eq ptr %53, null
  br i1 %.not25, label %55, label %54

54:                                               ; preds = %52
  call void @FreePool(ptr noundef nonnull %53) #3
  br label %55

55:                                               ; preds = %54, %52
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %.not26 = icmp eq ptr %56, null
  br i1 %.not26, label %58, label %57

57:                                               ; preds = %55
  call void @FreePool(ptr noundef nonnull %56) #3
  br label %58

58:                                               ; preds = %57, %55
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  ret i64 %.0
}

declare i64 @GetDevicePathSize(ptr noundef) local_unnamed_addr #1

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 32}
!10 = !{!"", !11, i64 0, !12, i64 16, !6, i64 32, !14, i64 40, !7, i64 42, !11, i64 48}
!11 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!12 = !{!"", !13, i64 0, !14, i64 4, !14, i64 6, !7, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!14, !14, i64 0}


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