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

; 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_BUFFER_IMAGE = type { ptr, ptr, i64, ptr, %struct.HEFI_EDITOR_POSITION, %struct.HEFI_EDITOR_POSITION, %struct.HEFI_EDITOR_POSITION, i64, i8, i8, i32, ptr, ptr, ptr }
%struct.HEFI_EDITOR_POSITION = type { i64, i64 }
%struct.HEFI_EDITOR_GLOBAL_EDITOR = type { ptr, %union.HEFI_EDITOR_COLOR_UNION, %struct.HEFI_EDITOR_POSITION, i8, ptr, i32, i32, i64, i64 }
%union.HEFI_EDITOR_COLOR_UNION = type { i64 }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct._HEFI_EDITOR_LINE = type { i64, [16 x i8], i64, %struct._LIST_ENTRY }

@HBufferImage = external dso_local global %struct.HEFI_EDITOR_BUFFER_IMAGE, align 8
@HMainEditor = external global %struct.HEFI_EDITOR_GLOBAL_EDITOR, align 8
@.str.10 = external hidden unnamed_addr constant [167 x i8], align 1
@.str.11 = 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

declare ptr @AllocateZeroPool(i64 noundef) #1

; 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 i64 @HBufferImageFreeLines() #2

declare void @FreePool(ptr noundef) #1

declare zeroext i8 @DebugAssertEnabled() #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @HBufferImageGetTotalSize() #2

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @HBufferImageAddCharacterToBuffer(i64 noundef %0, i64 noundef %1, ptr noundef %2) #2 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = alloca i32, align 4
  store i64 %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !5
  store ptr %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
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  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 8, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %19 = call i64 @HBufferImageGetTotalSize()
  store i64 %19, ptr %11, align 8, !tbaa !5
  %20 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 6), align 8, !tbaa !11
  store i64 %20, ptr %15, align 8, !tbaa !5
  %21 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 6), i32 0, i32 1), align 8, !tbaa !15
  store i64 %21, ptr %14, align 8, !tbaa !5
  %22 = load i64, ptr %15, align 8, !tbaa !5
  %23 = sub i64 %22, 1
  %24 = mul i64 %23, 16
  %25 = load i64, ptr %14, align 8, !tbaa !5
  %26 = add i64 %24, %25
  %27 = sub i64 %26, 1
  store i64 %27, ptr %16, align 8, !tbaa !5
  %28 = load i64, ptr %5, align 8, !tbaa !5
  %29 = icmp ugt i64 %28, 0
  br i1 %29, label %30, label %33

30:                                               ; preds = %3
  %31 = load i64, ptr %5, align 8, !tbaa !5
  %32 = sub i64 %31, 1
  store i64 %32, ptr %17, align 8, !tbaa !5
  br label %34

33:                                               ; preds = %3
  store i64 0, ptr %17, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %33, %30
  %35 = load i64, ptr %17, align 8, !tbaa !5
  %36 = udiv i64 %35, 16
  %37 = add i64 %36, 1
  %38 = load i64, ptr %17, align 8, !tbaa !5
  %39 = urem i64 %38, 16
  %40 = add i64 %39, 1
  call void @HBufferImageMovePosition(i64 noundef %37, i64 noundef %40, i8 noundef zeroext 1)
  %41 = load i64, ptr %11, align 8, !tbaa !5
  %42 = load i64, ptr %6, align 8, !tbaa !5
  %43 = add i64 %41, %42
  %44 = call ptr @AllocateZeroPool(i64 noundef %43)
  store ptr %44, ptr %9, align 8, !tbaa !9
  %45 = load ptr, ptr %9, align 8, !tbaa !9
  %46 = icmp eq ptr %45, null
  br i1 %46, label %47, label %48

47:                                               ; preds = %34
  store i64 -9223372036854775799, ptr %4, align 8
  store i32 1, ptr %18, align 4
  br label %156

48:                                               ; preds = %34
  %49 = load ptr, ptr %9, align 8, !tbaa !9
  %50 = load i64, ptr %11, align 8, !tbaa !5
  %51 = call i64 @HBufferImageListToBuffer(ptr noundef %49, i64 noundef %50)
  %52 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %52, ptr %10, align 8, !tbaa !9
  %53 = load i64, ptr %11, align 8, !tbaa !5
  %54 = load i64, ptr %6, align 8, !tbaa !5
  %55 = add i64 %53, %54
  %56 = sub i64 %55, 1
  store i64 %56, ptr %8, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %71, %48
  %58 = load i64, ptr %8, align 8, !tbaa !5
  %59 = load i64, ptr %5, align 8, !tbaa !5
  %60 = icmp sge i64 %58, %59
  br i1 %60, label %61, label %74

61:                                               ; preds = %57
  %62 = load ptr, ptr %10, align 8, !tbaa !9
  %63 = load i64, ptr %8, align 8, !tbaa !5
  %64 = load i64, ptr %6, align 8, !tbaa !5
  %65 = sub i64 %63, %64
  %66 = getelementptr inbounds i8, ptr %62, i64 %65
  %67 = load i8, ptr %66, align 1, !tbaa !16
  %68 = load ptr, ptr %10, align 8, !tbaa !9
  %69 = load i64, ptr %8, align 8, !tbaa !5
  %70 = getelementptr inbounds i8, ptr %68, i64 %69
  store i8 %67, ptr %70, align 1, !tbaa !16
  br label %71

71:                                               ; preds = %61
  %72 = load i64, ptr %8, align 8, !tbaa !5
  %73 = add nsw i64 %72, -1
  store i64 %73, ptr %8, align 8, !tbaa !5
  br label %57, !llvm.loop !17

74:                                               ; preds = %57
  store i64 0, ptr %8, align 8, !tbaa !5
  br label %75

75:                                               ; preds = %89, %74
  %76 = load i64, ptr %8, align 8, !tbaa !5
  %77 = load i64, ptr %6, align 8, !tbaa !5
  %78 = icmp slt i64 %76, %77
  br i1 %78, label %79, label %92

79:                                               ; preds = %75
  %80 = load ptr, ptr %7, align 8, !tbaa !9
  %81 = load i64, ptr %8, align 8, !tbaa !5
  %82 = getelementptr inbounds i8, ptr %80, i64 %81
  %83 = load i8, ptr %82, align 1, !tbaa !16
  %84 = load ptr, ptr %10, align 8, !tbaa !9
  %85 = load i64, ptr %8, align 8, !tbaa !5
  %86 = load i64, ptr %5, align 8, !tbaa !5
  %87 = add i64 %85, %86
  %88 = getelementptr inbounds i8, ptr %84, i64 %87
  store i8 %83, ptr %88, align 1, !tbaa !16
  br label %89

89:                                               ; preds = %79
  %90 = load i64, ptr %8, align 8, !tbaa !5
  %91 = add nsw i64 %90, 1
  store i64 %91, ptr %8, align 8, !tbaa !5
  br label %75, !llvm.loop !19

92:                                               ; preds = %75
  %93 = load i64, ptr %6, align 8, !tbaa !5
  %94 = load i64, ptr %11, align 8, !tbaa !5
  %95 = add i64 %94, %93
  store i64 %95, ptr %11, align 8, !tbaa !5
  %96 = call i64 @HBufferImageFreeLines()
  %97 = load ptr, ptr %9, align 8, !tbaa !9
  %98 = load i64, ptr %11, align 8, !tbaa !5
  %99 = call i64 @HBufferImageBufferToList(ptr noundef %97, i64 noundef %98)
  %100 = load ptr, ptr %9, align 8, !tbaa !9
  call void @FreePool(ptr noundef %100)
  %101 = load ptr, ptr @HMainEditor, align 8, !tbaa !20
  %102 = getelementptr inbounds %struct.HEFI_EDITOR_BUFFER_IMAGE, ptr %101, i32 0, i32 0
  %103 = load ptr, ptr %102, align 8, !tbaa !22
  %104 = getelementptr inbounds %struct._LIST_ENTRY, ptr %103, i32 0, i32 0
  %105 = load ptr, ptr %104, align 8, !tbaa !23
  store ptr %105, ptr %13, align 8, !tbaa !9
  store i64 0, ptr %8, align 8, !tbaa !5
  br label %106

106:                                              ; preds = %115, %92
  %107 = load i64, ptr %8, align 8, !tbaa !5
  %108 = load i64, ptr %17, align 8, !tbaa !5
  %109 = sdiv i64 %108, 16
  %110 = icmp slt i64 %107, %109
  br i1 %110, label %111, label %118

111:                                              ; preds = %106
  %112 = load ptr, ptr %13, align 8, !tbaa !9
  %113 = getelementptr inbounds %struct._LIST_ENTRY, ptr %112, i32 0, i32 0
  %114 = load ptr, ptr %113, align 8, !tbaa !23
  store ptr %114, ptr %13, align 8, !tbaa !9
  br label %115

115:                                              ; preds = %111
  %116 = load i64, ptr %8, align 8, !tbaa !5
  %117 = add nsw i64 %116, 1
  store i64 %117, ptr %8, align 8, !tbaa !5
  br label %106, !llvm.loop !25

118:                                              ; preds = %106
  %119 = call zeroext i8 @DebugAssertEnabled()
  %120 = zext i8 %119 to i32
  %121 = icmp ne i32 %120, 0
  br i1 %121, label %122, label %132

122:                                              ; preds = %118
  %123 = load ptr, ptr %13, align 8, !tbaa !9
  %124 = ptrtoint ptr %123 to i64
  %125 = sub i64 %124, ptrtoint (ptr getelementptr inbounds (%struct._HEFI_EDITOR_LINE, ptr null, i32 0, i32 3) to i64)
  %126 = inttoptr i64 %125 to ptr
  %127 = getelementptr inbounds %struct._HEFI_EDITOR_LINE, ptr %126, i32 0, i32 0
  %128 = load i64, ptr %127, align 8, !tbaa !26
  %129 = icmp ne i64 %128, 1819043173
  br i1 %129, label %130, label %132

130:                                              ; preds = %122
  call void @DebugAssert(ptr noundef @.str.10, i64 noundef 2102, ptr noundef @.str.11)
  %131 = load ptr, ptr %13, align 8, !tbaa !9
  br label %137

132:                                              ; preds = %122, %118
  %133 = load ptr, ptr %13, align 8, !tbaa !9
  %134 = ptrtoint ptr %133 to i64
  %135 = sub i64 %134, ptrtoint (ptr getelementptr inbounds (%struct._HEFI_EDITOR_LINE, ptr null, i32 0, i32 3) to i64)
  %136 = inttoptr i64 %135 to ptr
  br label %137

137:                                              ; preds = %132, %130
  %138 = phi ptr [ %131, %130 ], [ %136, %132 ]
  store ptr %138, ptr %12, align 8, !tbaa !9
  %139 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %139, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 3), align 8, !tbaa !28
  %140 = load i64, ptr %16, align 8, !tbaa !5
  %141 = load i64, ptr %5, align 8, !tbaa !5
  %142 = icmp uge i64 %140, %141
  br i1 %142, label %143, label %147

143:                                              ; preds = %137
  %144 = load i64, ptr %16, align 8, !tbaa !5
  %145 = load i64, ptr %6, align 8, !tbaa !5
  %146 = add i64 %144, %145
  store i64 %146, ptr %17, align 8, !tbaa !5
  br label %149

147:                                              ; preds = %137
  %148 = load i64, ptr %16, align 8, !tbaa !5
  store i64 %148, ptr %17, align 8, !tbaa !5
  br label %149

149:                                              ; preds = %147, %143
  %150 = load i64, ptr %17, align 8, !tbaa !5
  %151 = udiv i64 %150, 16
  %152 = add i64 %151, 1
  %153 = load i64, ptr %17, align 8, !tbaa !5
  %154 = urem i64 %153, 16
  %155 = add i64 %154, 1
  call void @HBufferImageMovePosition(i64 noundef %152, i64 noundef %155, i8 noundef zeroext 1)
  store i64 0, ptr %4, align 8
  store i32 1, ptr %18, align 4
  br label %156

156:                                              ; preds = %149, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, 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
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  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
  %157 = load i64, ptr %4, align 8
  ret i64 %157
}

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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 64}
!12 = !{!"", !10, i64 0, !10, i64 8, !6, i64 16, !10, i64 24, !13, i64 32, !13, i64 48, !13, i64 64, !6, i64 80, !7, i64 88, !7, i64 89, !14, i64 92, !10, i64 96, !10, i64 104, !10, i64 112}
!13 = !{!"", !6, i64 0, !6, i64 8}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !6, i64 72}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = !{!21, !10, i64 0}
!21 = !{!"", !10, i64 0, !7, i64 8, !13, i64 16, !7, i64 32, !10, i64 40, !14, i64 48, !14, i64 52, !6, i64 56, !6, i64 64}
!22 = !{!12, !10, i64 0}
!23 = !{!24, !10, i64 0}
!24 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!25 = distinct !{!25, !18}
!26 = !{!27, !6, i64 0}
!27 = !{!"_HEFI_EDITOR_LINE", !6, i64 0, !7, i64 8, !6, i64 24, !24, i64 32}
!28 = !{!12, !10, 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"

%struct.HEFI_EDITOR_BUFFER_IMAGE = type { ptr, ptr, i64, ptr, %struct.HEFI_EDITOR_POSITION, %struct.HEFI_EDITOR_POSITION, %struct.HEFI_EDITOR_POSITION, i64, i8, i8, i32, ptr, ptr, ptr }
%struct.HEFI_EDITOR_POSITION = type { i64, i64 }
%struct.HEFI_EDITOR_GLOBAL_EDITOR = type { ptr, %union.HEFI_EDITOR_COLOR_UNION, %struct.HEFI_EDITOR_POSITION, i8, ptr, i32, i32, i64, i64 }
%union.HEFI_EDITOR_COLOR_UNION = type { i64 }

@HBufferImage = external dso_local local_unnamed_addr global %struct.HEFI_EDITOR_BUFFER_IMAGE, align 8
@HMainEditor = external local_unnamed_addr global %struct.HEFI_EDITOR_GLOBAL_EDITOR, align 8
@.str.10 = external hidden unnamed_addr constant [167 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [21 x i8], align 1

declare ptr @AllocateZeroPool(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @HBufferImageFreeLines() local_unnamed_addr #1

declare void @FreePool(ptr noundef) local_unnamed_addr #0

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @HBufferImageMovePosition(i64 noundef, i64 noundef, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @HBufferImageGetTotalSize() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @HBufferImageListToBuffer(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @HBufferImageBufferToList(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775799, 1) i64 @HBufferImageAddCharacterToBuffer(i64 noundef %0, i64 noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 {
  %4 = ptrtoint ptr %2 to i64
  %5 = tail call i64 @HBufferImageGetTotalSize()
  %6 = load i64, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 64), align 8, !tbaa !5
  %7 = load i64, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 72), align 8, !tbaa !13
  %8 = shl i64 %6, 4
  %9 = add i64 %8, -17
  %10 = add i64 %9, %7
  %.0 = tail call i64 @llvm.usub.sat.i64(i64 %0, i64 1)
  %11 = lshr i64 %.0, 4
  %12 = add nuw nsw i64 %11, 1
  %13 = and i64 %.0, 15
  %14 = add nuw nsw i64 %13, 1
  tail call void @HBufferImageMovePosition(i64 noundef %12, i64 noundef %14, i8 noundef zeroext 1)
  %15 = add i64 %5, %1
  %16 = tail call ptr @AllocateZeroPool(i64 noundef %15) #3
  %17 = ptrtoint ptr %16 to i64
  %18 = icmp eq ptr %16, null
  br i1 %18, label %93, label %19

19:                                               ; preds = %3
  %20 = tail call i64 @HBufferImageListToBuffer(ptr noundef nonnull %16, i64 noundef %5)
  %.05164 = add i64 %15, -1
  %.not6065 = icmp slt i64 %.05164, %0
  br i1 %.not6065, label %.preheader, label %iter.check

iter.check:                                       ; preds = %19
  %21 = add i64 %5, %1
  %22 = sub i64 1, %21
  %23 = sub i64 0, %0
  %24 = tail call i64 @llvm.smax.i64(i64 %22, i64 %23)
  %25 = add i64 %24, %21
  %min.iters.check = icmp ult i64 %25, 4
  br i1 %min.iters.check, label %.lr.ph.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %iter.check
  %26 = add i64 %5, %1
  %27 = add i64 %26, -2
  %28 = add i64 %0, -1
  %smin = tail call i64 @llvm.smin.i64(i64 %27, i64 %28)
  %29 = sub i64 %27, %smin
  %scevgep = getelementptr i8, ptr %16, i64 %.05164
  %30 = sub i64 0, %29
  %31 = getelementptr i8, ptr %scevgep, i64 %30
  %32 = icmp ugt ptr %31, %scevgep
  %33 = getelementptr i8, ptr %16, i64 %5
  %scevgep76 = getelementptr i8, ptr %33, i64 -1
  %34 = sub i64 0, %29
  %35 = getelementptr i8, ptr %scevgep76, i64 %34
  %36 = icmp ugt ptr %35, %scevgep76
  %37 = or i1 %32, %36
  %38 = add i64 %1, 15
  %diff.check = icmp ult i64 %38, 16
  %or.cond = or i1 %37, %diff.check
  br i1 %or.cond, label %.lr.ph.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %vector.scevcheck
  %min.iters.check81 = icmp ult i64 %25, 16
  br i1 %min.iters.check81, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %25, -16
  %invariant.gep128 = getelementptr i8, ptr %16, i64 -15
  %invariant.gep130 = getelementptr i8, ptr %16, i64 -15
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = sub i64 %.05164, %index
  %39 = sub i64 %offset.idx, %1
  %gep129 = getelementptr i8, ptr %invariant.gep128, i64 %39
  %wide.load = load <16 x i8>, ptr %gep129, align 1, !tbaa !14
  %gep131 = getelementptr i8, ptr %invariant.gep130, i64 %offset.idx
  store <16 x i8> %wide.load, ptr %gep131, align 1, !tbaa !14
  %index.next = add nuw i64 %index, 16
  %40 = icmp eq i64 %index.next, %n.vec
  br i1 %40, label %middle.block, label %vector.body, !llvm.loop !15

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %25, %n.vec
  br i1 %cmp.n, label %.preheader, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %ind.end85 = sub i64 %.05164, %n.vec
  %n.vec.remaining = and i64 %25, 12
  %min.epilog.iters.check = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check, label %.lr.ph.preheader, label %vec.epilog.ph

.lr.ph.preheader:                                 ; preds = %vec.epilog.middle.block, %vector.scevcheck, %iter.check, %vec.epilog.iter.check
  %.05166.ph = phi i64 [ %.05164, %iter.check ], [ %.05164, %vector.scevcheck ], [ %ind.end85, %vec.epilog.iter.check ], [ %ind.end, %vec.epilog.middle.block ]
  br label %.lr.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec84 = and i64 %25, -4
  %ind.end = sub i64 %.05164, %n.vec84
  %invariant.gep132 = getelementptr i8, ptr %16, i64 -3
  %invariant.gep134 = getelementptr i8, ptr %16, i64 -3
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index86 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next91, %vec.epilog.vector.body ]
  %offset.idx87 = sub i64 %.05164, %index86
  %41 = sub i64 %offset.idx87, %1
  %gep133 = getelementptr i8, ptr %invariant.gep132, i64 %41
  %wide.load88 = load <4 x i8>, ptr %gep133, align 1, !tbaa !14
  %gep135 = getelementptr i8, ptr %invariant.gep134, i64 %offset.idx87
  store <4 x i8> %wide.load88, ptr %gep135, align 1, !tbaa !14
  %index.next91 = add nuw i64 %index86, 4
  %42 = icmp eq i64 %index.next91, %n.vec84
  br i1 %42, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !19

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %cmp.n92 = icmp eq i64 %25, %n.vec84
  br i1 %cmp.n92, label %.preheader, label %.lr.ph.preheader

.preheader:                                       ; preds = %.lr.ph, %middle.block, %vec.epilog.middle.block, %19
  %invariant.gep = getelementptr i8, ptr %16, i64 %0
  %43 = icmp sgt i64 %1, 0
  br i1 %43, label %iter.check98, label %._crit_edge

iter.check98:                                     ; preds = %.preheader
  %min.iters.check96 = icmp ult i64 %1, 8
  br i1 %min.iters.check96, label %.lr.ph68.preheader, label %vector.memcheck93

vector.memcheck93:                                ; preds = %iter.check98
  %44 = add i64 %17, %0
  %45 = sub i64 %44, %4
  %diff.check94 = icmp ult i64 %45, 32
  br i1 %diff.check94, label %.lr.ph68.preheader, label %vector.main.loop.iter.check100

vector.main.loop.iter.check100:                   ; preds = %vector.memcheck93
  %min.iters.check99 = icmp ult i64 %1, 32
  br i1 %min.iters.check99, label %vec.epilog.ph112, label %vector.ph101

vector.ph101:                                     ; preds = %vector.main.loop.iter.check100
  %n.vec103 = and i64 %1, 9223372036854775776
  br label %vector.body104

vector.body104:                                   ; preds = %vector.body104, %vector.ph101
  %index105 = phi i64 [ 0, %vector.ph101 ], [ %index.next108, %vector.body104 ]
  %46 = getelementptr inbounds i8, ptr %2, i64 %index105
  %47 = getelementptr inbounds i8, ptr %46, i64 16
  %wide.load106 = load <16 x i8>, ptr %46, align 1, !tbaa !14
  %wide.load107 = load <16 x i8>, ptr %47, align 1, !tbaa !14
  %48 = getelementptr i8, ptr %invariant.gep, i64 %index105
  %49 = getelementptr i8, ptr %48, i64 16
  store <16 x i8> %wide.load106, ptr %48, align 1, !tbaa !14
  store <16 x i8> %wide.load107, ptr %49, align 1, !tbaa !14
  %index.next108 = add nuw i64 %index105, 32
  %50 = icmp eq i64 %index.next108, %n.vec103
  br i1 %50, label %middle.block95, label %vector.body104, !llvm.loop !20

middle.block95:                                   ; preds = %vector.body104
  %cmp.n109 = icmp eq i64 %n.vec103, %1
  br i1 %cmp.n109, label %._crit_edge, label %vec.epilog.iter.check113

vec.epilog.iter.check113:                         ; preds = %middle.block95
  %n.vec.remaining114 = and i64 %1, 24
  %min.epilog.iters.check115 = icmp eq i64 %n.vec.remaining114, 0
  br i1 %min.epilog.iters.check115, label %.lr.ph68.preheader, label %vec.epilog.ph112

.lr.ph68.preheader:                               ; preds = %vec.epilog.middle.block110, %vector.memcheck93, %iter.check98, %vec.epilog.iter.check113
  %.15267.ph = phi i64 [ 0, %iter.check98 ], [ 0, %vector.memcheck93 ], [ %n.vec103, %vec.epilog.iter.check113 ], [ %n.vec118, %vec.epilog.middle.block110 ]
  %xtraiter = and i64 %1, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph68.prol.loopexit, label %.lr.ph68.prol

.lr.ph68.prol:                                    ; preds = %.lr.ph68.preheader, %.lr.ph68.prol
  %.15267.prol = phi i64 [ %53, %.lr.ph68.prol ], [ %.15267.ph, %.lr.ph68.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph68.prol ], [ 0, %.lr.ph68.preheader ]
  %51 = getelementptr inbounds i8, ptr %2, i64 %.15267.prol
  %52 = load i8, ptr %51, align 1, !tbaa !14
  %gep.prol = getelementptr i8, ptr %invariant.gep, i64 %.15267.prol
  store i8 %52, ptr %gep.prol, align 1, !tbaa !14
  %53 = add nuw nsw i64 %.15267.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.ph68.prol.loopexit, label %.lr.ph68.prol, !llvm.loop !21

.lr.ph68.prol.loopexit:                           ; preds = %.lr.ph68.prol, %.lr.ph68.preheader
  %.15267.unr = phi i64 [ %.15267.ph, %.lr.ph68.preheader ], [ %53, %.lr.ph68.prol ]
  %54 = sub nsw i64 %.15267.ph, %1
  %55 = icmp ugt i64 %54, -4
  br i1 %55, label %._crit_edge, label %.lr.ph68

vec.epilog.ph112:                                 ; preds = %vector.main.loop.iter.check100, %vec.epilog.iter.check113
  %vec.epilog.resume.val116 = phi i64 [ %n.vec103, %vec.epilog.iter.check113 ], [ 0, %vector.main.loop.iter.check100 ]
  %n.vec118 = and i64 %1, 9223372036854775800
  br label %vec.epilog.vector.body120

vec.epilog.vector.body120:                        ; preds = %vec.epilog.vector.body120, %vec.epilog.ph112
  %index121 = phi i64 [ %vec.epilog.resume.val116, %vec.epilog.ph112 ], [ %index.next123, %vec.epilog.vector.body120 ]
  %56 = getelementptr inbounds i8, ptr %2, i64 %index121
  %wide.load122 = load <8 x i8>, ptr %56, align 1, !tbaa !14
  %57 = getelementptr i8, ptr %invariant.gep, i64 %index121
  store <8 x i8> %wide.load122, ptr %57, align 1, !tbaa !14
  %index.next123 = add nuw i64 %index121, 8
  %58 = icmp eq i64 %index.next123, %n.vec118
  br i1 %58, label %vec.epilog.middle.block110, label %vec.epilog.vector.body120, !llvm.loop !23

vec.epilog.middle.block110:                       ; preds = %vec.epilog.vector.body120
  %cmp.n124 = icmp eq i64 %n.vec118, %1
  br i1 %cmp.n124, label %._crit_edge, label %.lr.ph68.preheader

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.05166 = phi i64 [ %.051, %.lr.ph ], [ %.05166.ph, %.lr.ph.preheader ]
  %59 = sub i64 %.05166, %1
  %60 = getelementptr inbounds i8, ptr %16, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !14
  %62 = getelementptr inbounds i8, ptr %16, i64 %.05166
  store i8 %61, ptr %62, align 1, !tbaa !14
  %.051 = add i64 %.05166, -1
  %.not60 = icmp slt i64 %.051, %0
  br i1 %.not60, label %.preheader, label %.lr.ph, !llvm.loop !24

.lr.ph68:                                         ; preds = %.lr.ph68.prol.loopexit, %.lr.ph68
  %.15267 = phi i64 [ %74, %.lr.ph68 ], [ %.15267.unr, %.lr.ph68.prol.loopexit ]
  %63 = getelementptr inbounds i8, ptr %2, i64 %.15267
  %64 = load i8, ptr %63, align 1, !tbaa !14
  %gep = getelementptr i8, ptr %invariant.gep, i64 %.15267
  store i8 %64, ptr %gep, align 1, !tbaa !14
  %65 = add nuw nsw i64 %.15267, 1
  %66 = getelementptr inbounds i8, ptr %2, i64 %65
  %67 = load i8, ptr %66, align 1, !tbaa !14
  %gep.1 = getelementptr i8, ptr %invariant.gep, i64 %65
  store i8 %67, ptr %gep.1, align 1, !tbaa !14
  %68 = add nuw nsw i64 %.15267, 2
  %69 = getelementptr inbounds i8, ptr %2, i64 %68
  %70 = load i8, ptr %69, align 1, !tbaa !14
  %gep.2 = getelementptr i8, ptr %invariant.gep, i64 %68
  store i8 %70, ptr %gep.2, align 1, !tbaa !14
  %71 = add nuw nsw i64 %.15267, 3
  %72 = getelementptr inbounds i8, ptr %2, i64 %71
  %73 = load i8, ptr %72, align 1, !tbaa !14
  %gep.3 = getelementptr i8, ptr %invariant.gep, i64 %71
  store i8 %73, ptr %gep.3, align 1, !tbaa !14
  %74 = add nuw nsw i64 %.15267, 4
  %exitcond.not.3 = icmp eq i64 %74, %1
  br i1 %exitcond.not.3, label %._crit_edge, label %.lr.ph68, !llvm.loop !25

._crit_edge:                                      ; preds = %.lr.ph68.prol.loopexit, %.lr.ph68, %middle.block95, %vec.epilog.middle.block110, %.preheader
  %75 = tail call i64 @HBufferImageFreeLines()
  %76 = tail call i64 @HBufferImageBufferToList(ptr noundef nonnull %16, i64 noundef %15)
  tail call void @FreePool(ptr noundef nonnull %16) #3
  %77 = load ptr, ptr @HMainEditor, align 8, !tbaa !26
  %78 = load ptr, ptr %77, align 8, !tbaa !28
  %79 = sdiv i64 %.0, 16
  %smax = tail call i64 @llvm.smax.i64(i64 %79, i64 0)
  %80 = add nuw nsw i64 %smax, 1
  %xtraiter125 = and i64 %80, 7
  %81 = icmp slt i64 %.0, 112
  br i1 %81, label %.unr-lcssa, label %._crit_edge.new

._crit_edge.new:                                  ; preds = %._crit_edge
  %unroll_iter = and i64 %80, 1152921504606846968
  br label %82

82:                                               ; preds = %82, %._crit_edge.new
  %.053.in = phi ptr [ %78, %._crit_edge.new ], [ %.053.7, %82 ]
  %niter = phi i64 [ 0, %._crit_edge.new ], [ %niter.next.7, %82 ]
  %.053 = load ptr, ptr %.053.in, align 8, !tbaa !29
  %.053.1 = load ptr, ptr %.053, align 8, !tbaa !29
  %.053.2 = load ptr, ptr %.053.1, align 8, !tbaa !29
  %.053.3 = load ptr, ptr %.053.2, align 8, !tbaa !29
  %.053.4 = load ptr, ptr %.053.3, align 8, !tbaa !29
  %.053.5 = load ptr, ptr %.053.4, align 8, !tbaa !29
  %.053.6 = load ptr, ptr %.053.5, align 8, !tbaa !29
  %.053.7 = load ptr, ptr %.053.6, align 8, !tbaa !29
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %.unr-lcssa, label %82, !llvm.loop !31

.unr-lcssa:                                       ; preds = %82, %._crit_edge
  %.053.lcssa.ph = phi ptr [ poison, %._crit_edge ], [ %.053.7, %82 ]
  %.053.in.unr = phi ptr [ %78, %._crit_edge ], [ %.053.7, %82 ]
  %lcmp.mod126.not = icmp eq i64 %xtraiter125, 0
  br i1 %lcmp.mod126.not, label %.epilog-lcssa, label %.epil.preheader

.epil.preheader:                                  ; preds = %.unr-lcssa, %.epil.preheader
  %.053.in.epil = phi ptr [ %.053.epil, %.epil.preheader ], [ %.053.in.unr, %.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %.unr-lcssa ]
  %.053.epil = load ptr, ptr %.053.in.epil, align 8, !tbaa !29
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter125
  br i1 %epil.iter.cmp.not, label %.epilog-lcssa, label %.epil.preheader, !llvm.loop !32

.epilog-lcssa:                                    ; preds = %.epil.preheader, %.unr-lcssa
  %.053.lcssa = phi ptr [ %.053.lcssa.ph, %.unr-lcssa ], [ %.053.epil, %.epil.preheader ]
  %83 = tail call zeroext i8 @DebugAssertEnabled() #3
  %.not61 = icmp eq i8 %83, 0
  %.pre = ptrtoint ptr %.053.lcssa to i64
  %.pre72 = add i64 %.pre, -32
  %.pre74 = inttoptr i64 %.pre72 to ptr
  br i1 %.not61, label %._crit_edge71, label %84

84:                                               ; preds = %.epilog-lcssa
  %85 = load i64, ptr %.pre74, align 8, !tbaa !33
  %.not62 = icmp eq i64 %85, 1819043173
  br i1 %.not62, label %._crit_edge71, label %86

86:                                               ; preds = %84
  tail call void @DebugAssert(ptr noundef nonnull @.str.10, i64 noundef 2102, ptr noundef nonnull @.str.11) #3
  br label %._crit_edge71

._crit_edge71:                                    ; preds = %.epilog-lcssa, %84, %86
  %87 = phi ptr [ %.053.lcssa, %86 ], [ %.pre74, %84 ], [ %.pre74, %.epilog-lcssa ]
  store ptr %87, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 24), align 8, !tbaa !35
  %.not63 = icmp ult i64 %10, %0
  %88 = select i1 %.not63, i64 0, i64 %1
  %.1 = add i64 %88, %10
  %89 = lshr i64 %.1, 4
  %90 = add nuw nsw i64 %89, 1
  %91 = and i64 %.1, 15
  %92 = add nuw nsw i64 %91, 1
  tail call void @HBufferImageMovePosition(i64 noundef %90, i64 noundef %92, i8 noundef zeroext 1)
  br label %93

93:                                               ; preds = %3, %._crit_edge71
  %.050 = phi i64 [ 0, %._crit_edge71 ], [ -9223372036854775799, %3 ]
  ret i64 %.050
}

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #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 speculatable willreturn memory(none) }
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, !10, i64 64}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !11, i64 32, !11, i64 48, !11, i64 64, !10, i64 80, !8, i64 88, !8, i64 89, !12, i64 92, !7, i64 96, !7, i64 104, !7, i64 112}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!"", !10, i64 0, !10, i64 8}
!12 = !{!"int", !8, i64 0}
!13 = !{!6, !10, i64 72}
!14 = !{!8, !8, i64 0}
!15 = distinct !{!15, !16, !17, !18}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!"llvm.loop.isvectorized", i32 1}
!18 = !{!"llvm.loop.unroll.runtime.disable"}
!19 = distinct !{!19, !16, !17, !18}
!20 = distinct !{!20, !16, !17, !18}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.unroll.disable"}
!23 = distinct !{!23, !16, !17, !18}
!24 = distinct !{!24, !16, !17}
!25 = distinct !{!25, !16, !17}
!26 = !{!27, !7, i64 0}
!27 = !{!"", !7, i64 0, !8, i64 8, !11, i64 16, !8, i64 32, !7, i64 40, !12, i64 48, !12, i64 52, !10, i64 56, !10, i64 64}
!28 = !{!6, !7, i64 0}
!29 = !{!30, !7, i64 0}
!30 = !{!"_LIST_ENTRY", !7, i64 0, !7, i64 8}
!31 = distinct !{!31, !16}
!32 = distinct !{!32, !22}
!33 = !{!34, !10, i64 0}
!34 = !{!"_HEFI_EDITOR_LINE", !10, i64 0, !8, i64 8, !10, i64 24, !30, i64 32}
!35 = !{!6, !7, i64 24}


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