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

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

@HFileImage = external dso_local global %struct.HEFI_EDITOR_FILE_IMAGE, align 8

declare void @FreePool(ptr noundef) #0

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

7:                                                ; preds = %1
  %8 = load ptr, ptr @HFileImage, align 8, !tbaa !9
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %12

10:                                               ; preds = %7
  %11 = load ptr, ptr @HFileImage, align 8, !tbaa !9
  call void @FreePool(ptr noundef %11)
  store ptr null, ptr @HFileImage, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %10, %7
  br label %13

13:                                               ; preds = %12
  br label %14

14:                                               ; preds = %13
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = call i64 @StrLen(ptr noundef %15)
  store i64 %16, ptr %4, align 8, !tbaa !12
  %17 = load i64, ptr %4, align 8, !tbaa !12
  %18 = add i64 %17, 1
  %19 = mul i64 2, %18
  %20 = call ptr @AllocateZeroPool(i64 noundef %19)
  store ptr %20, ptr @HFileImage, align 8, !tbaa !9
  %21 = load ptr, ptr @HFileImage, align 8, !tbaa !9
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %24

23:                                               ; preds = %14
  store i64 -9223372036854775799, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %44

24:                                               ; preds = %14
  store i64 0, ptr %5, align 8, !tbaa !12
  br label %25

25:                                               ; preds = %37, %24
  %26 = load i64, ptr %5, align 8, !tbaa !12
  %27 = load i64, ptr %4, align 8, !tbaa !12
  %28 = icmp ult i64 %26, %27
  br i1 %28, label %29, label %40

29:                                               ; preds = %25
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = load i64, ptr %5, align 8, !tbaa !12
  %32 = getelementptr inbounds i16, ptr %30, i64 %31
  %33 = load i16, ptr %32, align 2, !tbaa !13
  %34 = load ptr, ptr @HFileImage, align 8, !tbaa !9
  %35 = load i64, ptr %5, align 8, !tbaa !12
  %36 = getelementptr inbounds i16, ptr %34, i64 %35
  store i16 %33, ptr %36, align 2, !tbaa !13
  br label %37

37:                                               ; preds = %29
  %38 = load i64, ptr %5, align 8, !tbaa !12
  %39 = add i64 %38, 1
  store i64 %39, ptr %5, align 8, !tbaa !12
  br label %25, !llvm.loop !15

40:                                               ; preds = %25
  %41 = load ptr, ptr @HFileImage, align 8, !tbaa !9
  %42 = load i64, ptr %4, align 8, !tbaa !12
  %43 = getelementptr inbounds i16, ptr %41, i64 %42
  store i16 0, ptr %43, align 2, !tbaa !13
  store i64 0, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %44

44:                                               ; preds = %40, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %45 = load i64, ptr %2, align 8
  ret i64 %45
}

; 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, !6, i64 0}
!10 = !{!"", !6, i64 0, !11, i64 8, !7, i64 16}
!11 = !{!"long long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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

@HFileImage = external dso_local local_unnamed_addr global %struct.HEFI_EDITOR_FILE_IMAGE, align 8

declare void @FreePool(ptr noundef) local_unnamed_addr #0

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

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

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

.preheader:                                       ; preds = %5
  %.not13 = icmp eq i64 %6, 0
  br i1 %.not13, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %min.iters.check = icmp ult i64 %6, 16
  %12 = sub i64 %10, %2
  %diff.check = icmp ult i64 %12, 32
  %or.cond = or i1 %min.iters.check, %diff.check
  br i1 %or.cond, label %.lr.ph.preheader15, label %vector.ph

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

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

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

.lr.ph.preheader15:                               ; preds = %middle.block, %.lr.ph.preheader
  %.012.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %6, 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.preheader15, %.lr.ph.prol
  %.012.prol = phi i64 [ %21, %.lr.ph.prol ], [ %.012.ph, %.lr.ph.preheader15 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader15 ]
  %18 = getelementptr inbounds i16, ptr %0, i64 %.012.prol
  %19 = load i16, ptr %18, align 2, !tbaa !11
  %20 = getelementptr inbounds i16, ptr %9, i64 %.012.prol
  store i16 %19, ptr %20, align 2, !tbaa !11
  %21 = add nuw i64 %.012.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.preheader15
  %.012.unr = phi i64 [ %.012.ph, %.lr.ph.preheader15 ], [ %21, %.lr.ph.prol ]
  %22 = sub i64 %.012.ph, %6
  %23 = icmp ugt i64 %22, -4
  br i1 %23, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.012 = phi i64 [ %39, %.lr.ph ], [ %.012.unr, %.lr.ph.prol.loopexit ]
  %24 = getelementptr inbounds i16, ptr %0, i64 %.012
  %25 = load i16, ptr %24, align 2, !tbaa !11
  %26 = getelementptr inbounds i16, ptr %9, i64 %.012
  store i16 %25, ptr %26, align 2, !tbaa !11
  %27 = add nuw i64 %.012, 1
  %28 = getelementptr inbounds i16, ptr %0, i64 %27
  %29 = load i16, ptr %28, align 2, !tbaa !11
  %30 = getelementptr inbounds i16, ptr %9, i64 %27
  store i16 %29, ptr %30, align 2, !tbaa !11
  %31 = add nuw i64 %.012, 2
  %32 = getelementptr inbounds i16, ptr %0, i64 %31
  %33 = load i16, ptr %32, align 2, !tbaa !11
  %34 = getelementptr inbounds i16, ptr %9, i64 %31
  store i16 %33, ptr %34, align 2, !tbaa !11
  %35 = add nuw i64 %.012, 3
  %36 = getelementptr inbounds i16, ptr %0, i64 %35
  %37 = load i16, ptr %36, align 2, !tbaa !11
  %38 = getelementptr inbounds i16, ptr %9, i64 %35
  store i16 %37, ptr %38, align 2, !tbaa !11
  %39 = add nuw i64 %.012, 4
  %exitcond.not.3 = icmp eq i64 %39, %6
  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
  %40 = getelementptr inbounds i16, ptr %9, i64 %6
  store i16 0, ptr %40, align 2, !tbaa !11
  br label %41

41:                                               ; preds = %5, %._crit_edge
  %.09 = phi i64 [ 0, %._crit_edge ], [ -9223372036854775799, %5 ]
  ret i64 %.09
}

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, !8, i64 16}
!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}


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