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

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

@HDiskImage = external dso_local global %struct.HEFI_EDITOR_DISK_IMAGE, align 8

declare void @FreePool(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i64 @HDiskImageSetDiskNameOffsetSize(ptr noundef %0, i64 noundef %1, i64 noundef %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  br label %11

11:                                               ; preds = %3
  %12 = load ptr, ptr @HDiskImage, align 8, !tbaa !11
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %16

14:                                               ; preds = %11
  %15 = load ptr, ptr @HDiskImage, align 8, !tbaa !11
  call void @FreePool(ptr noundef %15)
  store ptr null, ptr @HDiskImage, align 8, !tbaa !11
  br label %16

16:                                               ; preds = %14, %11
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call i64 @StrLen(ptr noundef %19)
  store i64 %20, ptr %8, align 8, !tbaa !9
  %21 = load i64, ptr %8, align 8, !tbaa !9
  %22 = add i64 %21, 1
  %23 = mul i64 2, %22
  %24 = call ptr @AllocateZeroPool(i64 noundef %23)
  store ptr %24, ptr @HDiskImage, align 8, !tbaa !11
  %25 = load ptr, ptr @HDiskImage, align 8, !tbaa !11
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %28

27:                                               ; preds = %18
  store i64 -9223372036854775799, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %50

28:                                               ; preds = %18
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %41, %28
  %30 = load i64, ptr %9, align 8, !tbaa !9
  %31 = load i64, ptr %8, align 8, !tbaa !9
  %32 = icmp ult i64 %30, %31
  br i1 %32, label %33, label %44

33:                                               ; preds = %29
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i64, ptr %9, align 8, !tbaa !9
  %36 = getelementptr inbounds i16, ptr %34, i64 %35
  %37 = load i16, ptr %36, align 2, !tbaa !13
  %38 = load ptr, ptr @HDiskImage, align 8, !tbaa !11
  %39 = load i64, ptr %9, align 8, !tbaa !9
  %40 = getelementptr inbounds i16, ptr %38, i64 %39
  store i16 %37, ptr %40, align 2, !tbaa !13
  br label %41

41:                                               ; preds = %33
  %42 = load i64, ptr %9, align 8, !tbaa !9
  %43 = add i64 %42, 1
  store i64 %43, ptr %9, align 8, !tbaa !9
  br label %29, !llvm.loop !15

44:                                               ; preds = %29
  %45 = load ptr, ptr @HDiskImage, align 8, !tbaa !11
  %46 = load i64, ptr %8, align 8, !tbaa !9
  %47 = getelementptr inbounds i16, ptr %45, i64 %46
  store i16 0, ptr %47, align 2, !tbaa !13
  %48 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %48, ptr getelementptr inbounds (%struct.HEFI_EDITOR_DISK_IMAGE, ptr @HDiskImage, i32 0, i32 3), align 8, !tbaa !17
  %49 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %49, ptr getelementptr inbounds (%struct.HEFI_EDITOR_DISK_IMAGE, ptr @HDiskImage, i32 0, i32 2), align 8, !tbaa !18
  store i64 0, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %50

50:                                               ; preds = %44, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %51 = load i64, ptr %4, align 8
  ret i64 %51
}

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

declare i64 @StrLen(ptr noundef) #0

declare ptr @AllocateZeroPool(i64 noundef) #0

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 0}
!12 = !{!"", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!12, !10, i64 24}
!18 = !{!12, !10, i64 16}


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

@HDiskImage = external dso_local local_unnamed_addr global %struct.HEFI_EDITOR_DISK_IMAGE, align 8

declare void @FreePool(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775799, 1) i64 @HDiskImageSetDiskNameOffsetSize(ptr noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = ptrtoint ptr %0 to i64
  %5 = load ptr, ptr @HDiskImage, align 8, !tbaa !5
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %7, label %6

6:                                                ; preds = %3
  tail call void @FreePool(ptr noundef nonnull %5) #2
  store ptr null, ptr @HDiskImage, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %6, %3
  %8 = tail call i64 @StrLen(ptr noundef %0) #2
  %9 = shl i64 %8, 1
  %10 = add i64 %9, 2
  %11 = tail call ptr @AllocateZeroPool(i64 noundef %10) #2
  %12 = ptrtoint ptr %11 to i64
  store ptr %11, ptr @HDiskImage, align 8, !tbaa !5
  %13 = icmp eq ptr %11, null
  br i1 %13, label %43, label %.preheader

.preheader:                                       ; preds = %7
  %.not15 = icmp eq i64 %8, 0
  br i1 %.not15, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %min.iters.check = icmp ult i64 %8, 16
  %14 = sub i64 %12, %4
  %diff.check = icmp ult i64 %14, 32
  %or.cond = or i1 %min.iters.check, %diff.check
  br i1 %or.cond, label %.lr.ph.preheader17, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %8, -16
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %15 = getelementptr inbounds i16, ptr %0, i64 %index
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  %wide.load = load <8 x i16>, ptr %15, align 2, !tbaa !11
  %wide.load16 = load <8 x i16>, ptr %16, align 2, !tbaa !11
  %17 = getelementptr inbounds i16, ptr %11, i64 %index
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  store <8 x i16> %wide.load, ptr %17, align 2, !tbaa !11
  store <8 x i16> %wide.load16, ptr %18, align 2, !tbaa !11
  %index.next = add nuw i64 %index, 16
  %19 = icmp eq i64 %index.next, %n.vec
  br i1 %19, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %8, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader17

.lr.ph.preheader17:                               ; preds = %middle.block, %.lr.ph.preheader
  %.014.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %8, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader17, %.lr.ph.prol
  %.014.prol = phi i64 [ %23, %.lr.ph.prol ], [ %.014.ph, %.lr.ph.preheader17 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader17 ]
  %20 = getelementptr inbounds i16, ptr %0, i64 %.014.prol
  %21 = load i16, ptr %20, align 2, !tbaa !11
  %22 = getelementptr inbounds i16, ptr %11, i64 %.014.prol
  store i16 %21, ptr %22, align 2, !tbaa !11
  %23 = add nuw i64 %.014.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !17

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader17
  %.014.unr = phi i64 [ %.014.ph, %.lr.ph.preheader17 ], [ %23, %.lr.ph.prol ]
  %24 = sub i64 %.014.ph, %8
  %25 = icmp ugt i64 %24, -4
  br i1 %25, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.014 = phi i64 [ %41, %.lr.ph ], [ %.014.unr, %.lr.ph.prol.loopexit ]
  %26 = getelementptr inbounds i16, ptr %0, i64 %.014
  %27 = load i16, ptr %26, align 2, !tbaa !11
  %28 = getelementptr inbounds i16, ptr %11, i64 %.014
  store i16 %27, ptr %28, align 2, !tbaa !11
  %29 = add nuw i64 %.014, 1
  %30 = getelementptr inbounds i16, ptr %0, i64 %29
  %31 = load i16, ptr %30, align 2, !tbaa !11
  %32 = getelementptr inbounds i16, ptr %11, i64 %29
  store i16 %31, ptr %32, align 2, !tbaa !11
  %33 = add nuw i64 %.014, 2
  %34 = getelementptr inbounds i16, ptr %0, i64 %33
  %35 = load i16, ptr %34, align 2, !tbaa !11
  %36 = getelementptr inbounds i16, ptr %11, i64 %33
  store i16 %35, ptr %36, align 2, !tbaa !11
  %37 = add nuw i64 %.014, 3
  %38 = getelementptr inbounds i16, ptr %0, i64 %37
  %39 = load i16, ptr %38, align 2, !tbaa !11
  %40 = getelementptr inbounds i16, ptr %11, i64 %37
  store i16 %39, ptr %40, align 2, !tbaa !11
  %41 = add nuw i64 %.014, 4
  %exitcond.not.3 = icmp eq i64 %41, %8
  br i1 %exitcond.not.3, label %._crit_edge, label %.lr.ph, !llvm.loop !19

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block, %.preheader
  %42 = getelementptr inbounds i16, ptr %11, i64 %8
  store i16 0, ptr %42, align 2, !tbaa !11
  store i64 %1, ptr getelementptr inbounds (i8, ptr @HDiskImage, i64 24), align 8, !tbaa !20
  store i64 %2, ptr getelementptr inbounds (i8, ptr @HDiskImage, i64 16), align 8, !tbaa !21
  br label %43

43:                                               ; preds = %7, %._crit_edge
  %.011 = phi i64 [ 0, %._crit_edge ], [ -9223372036854775799, %7 ]
  ret i64 %.011
}

declare i64 @StrLen(ptr noundef) local_unnamed_addr #0

declare ptr @AllocateZeroPool(i64 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = distinct !{!13, !14, !15, !16}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!"llvm.loop.isvectorized", i32 1}
!16 = !{!"llvm.loop.unroll.runtime.disable"}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}
!19 = distinct !{!19, !14, !15}
!20 = !{!6, !10, i64 24}
!21 = !{!6, !10, i64 16}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass