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

; 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_LINE = type { i64, [16 x i8], i64, %struct._LIST_ENTRY }
%struct._LIST_ENTRY = type { ptr, ptr }

; 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

; Function Attrs: nounwind uwtable
declare dso_local ptr @HBufferImageCreateLine() #1

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

13:                                               ; preds = %54, %2
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = icmp ult i64 %14, %15
  br i1 %16, label %17, label %55

17:                                               ; preds = %13
  %18 = load i64, ptr %5, align 8, !tbaa !9
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = sub i64 %18, %19
  %21 = icmp uge i64 %20, 16
  br i1 %21, label %22, label %23

22:                                               ; preds = %17
  store i64 16, ptr %8, align 8, !tbaa !9
  br label %27

23:                                               ; preds = %17
  %24 = load i64, ptr %5, align 8, !tbaa !9
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = sub i64 %24, %25
  store i64 %26, ptr %8, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %23, %22
  %28 = call ptr @HBufferImageCreateLine()
  store ptr %28, ptr %9, align 8, !tbaa !5
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = icmp eq ptr %29, null
  br i1 %30, label %31, label %32

31:                                               ; preds = %27
  store i64 -9223372036854775799, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %68

32:                                               ; preds = %27
  %33 = load i64, ptr %8, align 8, !tbaa !9
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._HEFI_EDITOR_LINE, ptr %34, i32 0, i32 2
  store i64 %33, ptr %35, align 8, !tbaa !11
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %51, %32
  %37 = load i64, ptr %7, align 8, !tbaa !9
  %38 = load i64, ptr %8, align 8, !tbaa !9
  %39 = icmp ult i64 %37, %38
  br i1 %39, label %40, label %54

40:                                               ; preds = %36
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = load i64, ptr %6, align 8, !tbaa !9
  %43 = getelementptr inbounds i8, ptr %41, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !14
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._HEFI_EDITOR_LINE, ptr %45, i32 0, i32 1
  %47 = load i64, ptr %7, align 8, !tbaa !9
  %48 = getelementptr inbounds [16 x i8], ptr %46, i64 0, i64 %47
  store i8 %44, ptr %48, align 1, !tbaa !14
  %49 = load i64, ptr %6, align 8, !tbaa !9
  %50 = add i64 %49, 1
  store i64 %50, ptr %6, align 8, !tbaa !9
  br label %51

51:                                               ; preds = %40
  %52 = load i64, ptr %7, align 8, !tbaa !9
  %53 = add i64 %52, 1
  store i64 %53, ptr %7, align 8, !tbaa !9
  br label %36, !llvm.loop !15

54:                                               ; preds = %36
  br label %13, !llvm.loop !17

55:                                               ; preds = %13
  %56 = load i64, ptr %8, align 8, !tbaa !9
  %57 = icmp eq i64 %56, 16
  br i1 %57, label %61, label %58

58:                                               ; preds = %55
  %59 = load i64, ptr %5, align 8, !tbaa !9
  %60 = icmp eq i64 %59, 0
  br i1 %60, label %61, label %67

61:                                               ; preds = %58, %55
  %62 = call ptr @HBufferImageCreateLine()
  store ptr %62, ptr %9, align 8, !tbaa !5
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = icmp eq ptr %63, null
  br i1 %64, label %65, label %66

65:                                               ; preds = %61
  store i64 -9223372036854775799, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %68

66:                                               ; preds = %61
  br label %67

67:                                               ; preds = %66, %58
  store i64 0, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %68

68:                                               ; preds = %67, %65, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %69 = load i64, ptr %3, align 8
  ret i64 %69
}

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @HBufferImageCreateLine() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775799, 1) i64 @HBufferImageBufferToList(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = ptrtoint ptr %0 to i64
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %._crit_edge.thread, label %.lr.ph35.preheader

.lr.ph35.preheader:                               ; preds = %2
  %invariant.gep = getelementptr i8, ptr %0, i64 1
  %invariant.gep55 = getelementptr i8, ptr %0, i64 2
  %invariant.gep57 = getelementptr i8, ptr %0, i64 3
  br label %.lr.ph35

.loopexit:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %vector.ph
  %.lcssa = phi i64 [ %ind.end, %vector.ph ], [ %.lcssa47.unr, %scalar.ph.prol.loopexit ], [ %35, %scalar.ph ]
  %4 = icmp ult i64 %.lcssa, %1
  br i1 %4, label %.lr.ph35, label %._crit_edge, !llvm.loop !5

.lr.ph35:                                         ; preds = %.lr.ph35.preheader, %.loopexit
  %.02434 = phi i64 [ %.lcssa, %.loopexit ], [ 0, %.lr.ph35.preheader ]
  %5 = sub i64 %1, %.02434
  %. = tail call i64 @llvm.umin.i64(i64 %5, i64 16)
  %6 = tail call ptr @HBufferImageCreateLine()
  %7 = ptrtoint ptr %6 to i64
  %8 = icmp eq ptr %6, null
  br i1 %8, label %.loopexit30, label %9

9:                                                ; preds = %.lr.ph35
  %10 = getelementptr inbounds i8, ptr %6, i64 24
  store i64 %., ptr %10, align 8, !tbaa !7
  %.not37 = icmp eq i64 %.02434, %1
  br i1 %.not37, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %9
  %11 = getelementptr inbounds i8, ptr %6, i64 8
  %umax = tail call i64 @llvm.umax.i64(i64 %., i64 1)
  %min.iters.check = icmp ult i64 %5, 16
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph
  %12 = add i64 %7, 8
  %13 = add i64 %.02434, %3
  %14 = sub i64 %12, %13
  %diff.check = icmp ult i64 %14, 16
  br i1 %diff.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %umax, 16
  %ind.end = add i64 %.02434, %n.vec
  %15 = getelementptr inbounds i8, ptr %0, i64 %.02434
  %wide.load = load <16 x i8>, ptr %15, align 1, !tbaa !14
  store <16 x i8> %wide.load, ptr %11, align 1, !tbaa !14
  %cmp.n = icmp eq i64 %umax, %n.vec
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %vector.ph, %vector.memcheck, %.lr.ph
  %.02333.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph ], [ %n.vec, %vector.ph ]
  %.12532.ph = phi i64 [ %.02434, %vector.memcheck ], [ %.02434, %.lr.ph ], [ %ind.end, %vector.ph ]
  %xtraiter = and i64 %umax, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %.02333.prol = phi i64 [ %20, %scalar.ph.prol ], [ %.02333.ph, %scalar.ph.preheader ]
  %.12532.prol = phi i64 [ %19, %scalar.ph.prol ], [ %.12532.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %16 = getelementptr inbounds i8, ptr %0, i64 %.12532.prol
  %17 = load i8, ptr %16, align 1, !tbaa !14
  %18 = getelementptr inbounds [16 x i8], ptr %11, i64 0, i64 %.02333.prol
  store i8 %17, ptr %18, align 1, !tbaa !14
  %19 = add i64 %.12532.prol, 1
  %20 = add nuw nsw i64 %.02333.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 %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !15

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.lcssa47.unr = phi i64 [ poison, %scalar.ph.preheader ], [ %19, %scalar.ph.prol ]
  %.02333.unr = phi i64 [ %.02333.ph, %scalar.ph.preheader ], [ %20, %scalar.ph.prol ]
  %.12532.unr = phi i64 [ %.12532.ph, %scalar.ph.preheader ], [ %19, %scalar.ph.prol ]
  %21 = sub nsw i64 %.02333.ph, %umax
  %22 = icmp ugt i64 %21, -4
  br i1 %22, label %.loopexit, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %.02333 = phi i64 [ %36, %scalar.ph ], [ %.02333.unr, %scalar.ph.prol.loopexit ]
  %.12532 = phi i64 [ %35, %scalar.ph ], [ %.12532.unr, %scalar.ph.prol.loopexit ]
  %23 = getelementptr inbounds i8, ptr %0, i64 %.12532
  %24 = load i8, ptr %23, align 1, !tbaa !14
  %25 = getelementptr inbounds [16 x i8], ptr %11, i64 0, i64 %.02333
  store i8 %24, ptr %25, align 1, !tbaa !14
  %26 = add nuw nsw i64 %.02333, 1
  %gep = getelementptr i8, ptr %invariant.gep, i64 %.12532
  %27 = load i8, ptr %gep, align 1, !tbaa !14
  %28 = getelementptr inbounds [16 x i8], ptr %11, i64 0, i64 %26
  store i8 %27, ptr %28, align 1, !tbaa !14
  %29 = add nuw nsw i64 %.02333, 2
  %gep56 = getelementptr i8, ptr %invariant.gep55, i64 %.12532
  %30 = load i8, ptr %gep56, align 1, !tbaa !14
  %31 = getelementptr inbounds [16 x i8], ptr %11, i64 0, i64 %29
  store i8 %30, ptr %31, align 1, !tbaa !14
  %32 = add nuw nsw i64 %.02333, 3
  %gep58 = getelementptr i8, ptr %invariant.gep57, i64 %.12532
  %33 = load i8, ptr %gep58, align 1, !tbaa !14
  %34 = getelementptr inbounds [16 x i8], ptr %11, i64 0, i64 %32
  store i8 %33, ptr %34, align 1, !tbaa !14
  %35 = add i64 %.12532, 4
  %36 = add nuw nsw i64 %.02333, 4
  %exitcond.not.3 = icmp eq i64 %., %36
  br i1 %exitcond.not.3, label %.loopexit, label %scalar.ph, !llvm.loop !17

._crit_edge:                                      ; preds = %.loopexit, %9
  %37 = icmp ugt i64 %5, 15
  %or.cond = or i1 %.not, %37
  br i1 %or.cond, label %._crit_edge.thread, label %40

._crit_edge.thread:                               ; preds = %2, %._crit_edge
  %38 = tail call ptr @HBufferImageCreateLine()
  %39 = icmp eq ptr %38, null
  br i1 %39, label %.loopexit30, label %40

40:                                               ; preds = %._crit_edge.thread, %._crit_edge
  br label %.loopexit30

.loopexit30:                                      ; preds = %.lr.ph35, %._crit_edge.thread, %40
  %.0 = phi i64 [ 0, %40 ], [ -9223372036854775799, %._crit_edge.thread ], [ -9223372036854775799, %.lr.ph35 ]
  ret i64 %.0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #1

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !9, i64 24}
!8 = !{!"_HEFI_EDITOR_LINE", !9, i64 0, !10, i64 8, !9, i64 24, !12, i64 32}
!9 = !{!"long long", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"_LIST_ENTRY", !13, i64 0, !13, i64 8}
!13 = !{!"any pointer", !10, i64 0}
!14 = !{!10, !10, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.unroll.disable"}
!17 = distinct !{!17, !6, !18}
!18 = !{!"llvm.loop.isvectorized", i32 1}


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