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

; 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
define dso_local i64 @HBufferImageDeleteCharacterFromBuffer(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 i64, align 8
  %19 = 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  %20 = call i64 @HBufferImageGetTotalSize()
  store i64 %20, ptr %11, align 8, !tbaa !5
  %21 = load i64, ptr %11, align 8, !tbaa !5
  %22 = load i64, ptr %6, align 8, !tbaa !5
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %3
  store i64 -9223372036854775807, ptr %4, align 8
  store i32 1, ptr %19, align 4
  br label %185

25:                                               ; preds = %3
  %26 = load i64, ptr %11, align 8, !tbaa !5
  %27 = icmp eq i64 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %25
  store i64 0, ptr %4, align 8
  store i32 1, ptr %19, align 4
  br label %185

29:                                               ; preds = %25
  %30 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 6), align 8, !tbaa !11
  store i64 %30, ptr %15, align 8, !tbaa !5
  %31 = 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 %31, ptr %14, align 8, !tbaa !5
  %32 = load i64, ptr %15, align 8, !tbaa !5
  %33 = sub i64 %32, 1
  %34 = mul i64 %33, 16
  %35 = load i64, ptr %14, align 8, !tbaa !5
  %36 = add i64 %34, %35
  %37 = sub i64 %36, 1
  store i64 %37, ptr %16, align 8, !tbaa !5
  %38 = load i64, ptr %5, align 8, !tbaa !5
  %39 = icmp ugt i64 %38, 0
  br i1 %39, label %40, label %43

40:                                               ; preds = %29
  %41 = load i64, ptr %5, align 8, !tbaa !5
  %42 = sub i64 %41, 1
  store i64 %42, ptr %17, align 8, !tbaa !5
  br label %44

43:                                               ; preds = %29
  store i64 0, ptr %17, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %43, %40
  %45 = load i64, ptr %17, align 8, !tbaa !5
  %46 = udiv i64 %45, 16
  %47 = add i64 %46, 1
  %48 = load i64, ptr %17, align 8, !tbaa !5
  %49 = urem i64 %48, 16
  %50 = add i64 %49, 1
  call void @HBufferImageMovePosition(i64 noundef %47, i64 noundef %50, i8 noundef zeroext 1)
  %51 = load i64, ptr %11, align 8, !tbaa !5
  %52 = call ptr @AllocateZeroPool(i64 noundef %51)
  store ptr %52, ptr %9, align 8, !tbaa !9
  %53 = load ptr, ptr %9, align 8, !tbaa !9
  %54 = icmp eq ptr %53, null
  br i1 %54, label %55, label %56

55:                                               ; preds = %44
  store i64 -9223372036854775799, ptr %4, align 8
  store i32 1, ptr %19, align 4
  br label %185

56:                                               ; preds = %44
  %57 = load ptr, ptr %9, align 8, !tbaa !9
  %58 = load i64, ptr %11, align 8, !tbaa !5
  %59 = call i64 @HBufferImageListToBuffer(ptr noundef %57, i64 noundef %58)
  %60 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %60, ptr %10, align 8, !tbaa !9
  %61 = load ptr, ptr %7, align 8, !tbaa !9
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %82

63:                                               ; preds = %56
  store i64 0, ptr %8, align 8, !tbaa !5
  br label %64

64:                                               ; preds = %78, %63
  %65 = load i64, ptr %8, align 8, !tbaa !5
  %66 = load i64, ptr %6, align 8, !tbaa !5
  %67 = icmp ult i64 %65, %66
  br i1 %67, label %68, label %81

68:                                               ; preds = %64
  %69 = load ptr, ptr %10, align 8, !tbaa !9
  %70 = load i64, ptr %5, align 8, !tbaa !5
  %71 = load i64, ptr %8, align 8, !tbaa !5
  %72 = add i64 %70, %71
  %73 = getelementptr inbounds i8, ptr %69, i64 %72
  %74 = load i8, ptr %73, align 1, !tbaa !16
  %75 = load ptr, ptr %7, align 8, !tbaa !9
  %76 = load i64, ptr %8, align 8, !tbaa !5
  %77 = getelementptr inbounds i8, ptr %75, i64 %76
  store i8 %74, ptr %77, align 1, !tbaa !16
  br label %78

78:                                               ; preds = %68
  %79 = load i64, ptr %8, align 8, !tbaa !5
  %80 = add i64 %79, 1
  store i64 %80, ptr %8, align 8, !tbaa !5
  br label %64, !llvm.loop !17

81:                                               ; preds = %64
  br label %82

82:                                               ; preds = %81, %56
  %83 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %83, ptr %8, align 8, !tbaa !5
  br label %84

84:                                               ; preds = %100, %82
  %85 = load i64, ptr %8, align 8, !tbaa !5
  %86 = load i64, ptr %11, align 8, !tbaa !5
  %87 = load i64, ptr %6, align 8, !tbaa !5
  %88 = sub i64 %86, %87
  %89 = icmp ult i64 %85, %88
  br i1 %89, label %90, label %103

90:                                               ; preds = %84
  %91 = load ptr, ptr %10, align 8, !tbaa !9
  %92 = load i64, ptr %8, align 8, !tbaa !5
  %93 = load i64, ptr %6, align 8, !tbaa !5
  %94 = add i64 %92, %93
  %95 = getelementptr inbounds i8, ptr %91, i64 %94
  %96 = load i8, ptr %95, align 1, !tbaa !16
  %97 = load ptr, ptr %10, align 8, !tbaa !9
  %98 = load i64, ptr %8, align 8, !tbaa !5
  %99 = getelementptr inbounds i8, ptr %97, i64 %98
  store i8 %96, ptr %99, align 1, !tbaa !16
  br label %100

100:                                              ; preds = %90
  %101 = load i64, ptr %8, align 8, !tbaa !5
  %102 = add i64 %101, 1
  store i64 %102, ptr %8, align 8, !tbaa !5
  br label %84, !llvm.loop !19

103:                                              ; preds = %84
  %104 = load i64, ptr %6, align 8, !tbaa !5
  %105 = load i64, ptr %11, align 8, !tbaa !5
  %106 = sub i64 %105, %104
  store i64 %106, ptr %11, align 8, !tbaa !5
  %107 = call i64 @HBufferImageFreeLines()
  %108 = load ptr, ptr %9, align 8, !tbaa !9
  %109 = load i64, ptr %11, align 8, !tbaa !5
  %110 = call i64 @HBufferImageBufferToList(ptr noundef %108, i64 noundef %109)
  store i64 %110, ptr %18, align 8, !tbaa !5
  %111 = load ptr, ptr %9, align 8, !tbaa !9
  call void @FreePool(ptr noundef %111)
  %112 = load i64, ptr %18, align 8, !tbaa !5
  %113 = icmp slt i64 %112, 0
  br i1 %113, label %114, label %116

114:                                              ; preds = %103
  %115 = load i64, ptr %18, align 8, !tbaa !5
  store i64 %115, ptr %4, align 8
  store i32 1, ptr %19, align 4
  br label %185

116:                                              ; preds = %103
  %117 = load ptr, ptr @HMainEditor, align 8, !tbaa !20
  %118 = getelementptr inbounds %struct.HEFI_EDITOR_BUFFER_IMAGE, ptr %117, i32 0, i32 0
  %119 = load ptr, ptr %118, align 8, !tbaa !22
  %120 = getelementptr inbounds %struct._LIST_ENTRY, ptr %119, i32 0, i32 0
  %121 = load ptr, ptr %120, align 8, !tbaa !23
  store ptr %121, ptr %13, align 8, !tbaa !9
  store i64 0, ptr %8, align 8, !tbaa !5
  br label %122

122:                                              ; preds = %131, %116
  %123 = load i64, ptr %8, align 8, !tbaa !5
  %124 = load i64, ptr %17, align 8, !tbaa !5
  %125 = udiv i64 %124, 16
  %126 = icmp ult i64 %123, %125
  br i1 %126, label %127, label %134

127:                                              ; preds = %122
  %128 = load ptr, ptr %13, align 8, !tbaa !9
  %129 = getelementptr inbounds %struct._LIST_ENTRY, ptr %128, i32 0, i32 0
  %130 = load ptr, ptr %129, align 8, !tbaa !23
  store ptr %130, ptr %13, align 8, !tbaa !9
  br label %131

131:                                              ; preds = %127
  %132 = load i64, ptr %8, align 8, !tbaa !5
  %133 = add i64 %132, 1
  store i64 %133, ptr %8, align 8, !tbaa !5
  br label %122, !llvm.loop !25

134:                                              ; preds = %122
  %135 = call zeroext i8 @DebugAssertEnabled()
  %136 = zext i8 %135 to i32
  %137 = icmp ne i32 %136, 0
  br i1 %137, label %138, label %148

138:                                              ; preds = %134
  %139 = load ptr, ptr %13, align 8, !tbaa !9
  %140 = ptrtoint ptr %139 to i64
  %141 = sub i64 %140, ptrtoint (ptr getelementptr inbounds (%struct._HEFI_EDITOR_LINE, ptr null, i32 0, i32 3) to i64)
  %142 = inttoptr i64 %141 to ptr
  %143 = getelementptr inbounds %struct._HEFI_EDITOR_LINE, ptr %142, i32 0, i32 0
  %144 = load i64, ptr %143, align 8, !tbaa !26
  %145 = icmp ne i64 %144, 1819043173
  br i1 %145, label %146, label %148

146:                                              ; preds = %138
  call void @DebugAssert(ptr noundef @.str.10, i64 noundef 1993, ptr noundef @.str.11)
  %147 = load ptr, ptr %13, align 8, !tbaa !9
  br label %153

148:                                              ; preds = %138, %134
  %149 = load ptr, ptr %13, align 8, !tbaa !9
  %150 = ptrtoint ptr %149 to i64
  %151 = sub i64 %150, ptrtoint (ptr getelementptr inbounds (%struct._HEFI_EDITOR_LINE, ptr null, i32 0, i32 3) to i64)
  %152 = inttoptr i64 %151 to ptr
  br label %153

153:                                              ; preds = %148, %146
  %154 = phi ptr [ %147, %146 ], [ %152, %148 ]
  store ptr %154, ptr %12, align 8, !tbaa !9
  %155 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %155, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 3), align 8, !tbaa !28
  %156 = load i64, ptr %16, align 8, !tbaa !5
  %157 = load i64, ptr %5, align 8, !tbaa !5
  %158 = icmp uge i64 %156, %157
  br i1 %158, label %159, label %167

159:                                              ; preds = %153
  %160 = load i64, ptr %16, align 8, !tbaa !5
  %161 = load i64, ptr %5, align 8, !tbaa !5
  %162 = load i64, ptr %6, align 8, !tbaa !5
  %163 = add i64 %161, %162
  %164 = icmp ult i64 %160, %163
  br i1 %164, label %165, label %167

165:                                              ; preds = %159
  %166 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %166, ptr %17, align 8, !tbaa !5
  br label %178

167:                                              ; preds = %159, %153
  %168 = load i64, ptr %16, align 8, !tbaa !5
  %169 = load i64, ptr %5, align 8, !tbaa !5
  %170 = icmp ult i64 %168, %169
  br i1 %170, label %171, label %173

171:                                              ; preds = %167
  %172 = load i64, ptr %16, align 8, !tbaa !5
  store i64 %172, ptr %17, align 8, !tbaa !5
  br label %177

173:                                              ; preds = %167
  %174 = load i64, ptr %16, align 8, !tbaa !5
  %175 = load i64, ptr %6, align 8, !tbaa !5
  %176 = sub i64 %174, %175
  store i64 %176, ptr %17, align 8, !tbaa !5
  br label %177

177:                                              ; preds = %173, %171
  br label %178

178:                                              ; preds = %177, %165
  %179 = load i64, ptr %17, align 8, !tbaa !5
  %180 = udiv i64 %179, 16
  %181 = add i64 %180, 1
  %182 = load i64, ptr %17, align 8, !tbaa !5
  %183 = urem i64 %182, 16
  %184 = add i64 %183, 1
  call void @HBufferImageMovePosition(i64 noundef %181, i64 noundef %184, i8 noundef zeroext 1)
  store i64 0, ptr %4, align 8
  store i32 1, ptr %19, align 4
  br label %185

185:                                              ; preds = %178, %114, %55, %28, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  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
  %186 = load i64, ptr %4, align 8
  ret i64 %186
}

; 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

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
define dso_local range(i64 -9223372036854775808, 1) i64 @HBufferImageDeleteCharacterFromBuffer(i64 noundef %0, i64 noundef %1, ptr noundef writeonly %2) local_unnamed_addr #1 {
  %4 = ptrtoint ptr %2 to i64
  %5 = tail call i64 @HBufferImageGetTotalSize()
  %6 = icmp ult i64 %5, %1
  br i1 %6, label %89, label %7

7:                                                ; preds = %3
  %8 = icmp eq i64 %5, 0
  br i1 %8, label %89, label %9

9:                                                ; preds = %7
  %10 = load i64, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 64), align 8, !tbaa !5
  %11 = load i64, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 72), align 8, !tbaa !13
  %12 = shl i64 %10, 4
  %13 = add i64 %12, -17
  %14 = add i64 %13, %11
  %.061 = tail call i64 @llvm.usub.sat.i64(i64 %0, i64 1)
  %15 = lshr i64 %.061, 4
  %16 = add nuw nsw i64 %15, 1
  %17 = and i64 %.061, 15
  %18 = add nuw nsw i64 %17, 1
  tail call void @HBufferImageMovePosition(i64 noundef %16, i64 noundef %18, i8 noundef zeroext 1)
  %19 = tail call ptr @AllocateZeroPool(i64 noundef %5) #3
  %20 = ptrtoint ptr %19 to i64
  %21 = icmp eq ptr %19, null
  br i1 %21, label %89, label %22

22:                                               ; preds = %9
  %23 = tail call i64 @HBufferImageListToBuffer(ptr noundef nonnull %19, i64 noundef %5)
  %.not76 = icmp eq ptr %2, null
  br i1 %.not76, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %22
  %invariant.gep = getelementptr i8, ptr %19, i64 %0
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %.loopexit, label %iter.check

iter.check:                                       ; preds = %.preheader
  %min.iters.check = icmp ult i64 %1, 8
  br i1 %min.iters.check, label %.lr.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %iter.check
  %24 = add i64 %20, %0
  %25 = sub i64 %4, %24
  %diff.check = icmp ult i64 %25, 32
  br i1 %diff.check, label %.lr.ph.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %vector.memcheck
  %min.iters.check91 = icmp ult i64 %1, 32
  br i1 %min.iters.check91, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %1, -32
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %26 = getelementptr i8, ptr %invariant.gep, i64 %index
  %27 = getelementptr i8, ptr %26, i64 16
  %wide.load = load <16 x i8>, ptr %26, align 1, !tbaa !14
  %wide.load92 = load <16 x i8>, ptr %27, align 1, !tbaa !14
  %28 = getelementptr inbounds i8, ptr %2, i64 %index
  %29 = getelementptr inbounds i8, ptr %28, i64 16
  store <16 x i8> %wide.load, ptr %28, align 1, !tbaa !14
  store <16 x i8> %wide.load92, ptr %29, align 1, !tbaa !14
  %index.next = add nuw i64 %index, 32
  %30 = icmp eq i64 %index.next, %n.vec
  br i1 %30, label %middle.block, label %vector.body, !llvm.loop !15

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

vec.epilog.iter.check:                            ; preds = %middle.block
  %n.vec.remaining = and i64 %1, 24
  %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

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.vec94 = and i64 %1, -8
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index95 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next97, %vec.epilog.vector.body ]
  %31 = getelementptr i8, ptr %invariant.gep, i64 %index95
  %wide.load96 = load <8 x i8>, ptr %31, align 1, !tbaa !14
  %32 = getelementptr inbounds i8, ptr %2, i64 %index95
  store <8 x i8> %wide.load96, ptr %32, align 1, !tbaa !14
  %index.next97 = add nuw i64 %index95, 8
  %33 = icmp eq i64 %index.next97, %n.vec94
  br i1 %33, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !19

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %cmp.n98 = icmp eq i64 %n.vec94, %1
  br i1 %cmp.n98, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %vec.epilog.middle.block, %vector.memcheck, %iter.check, %vec.epilog.iter.check
  %.06281.ph = phi i64 [ 0, %iter.check ], [ 0, %vector.memcheck ], [ %n.vec, %vec.epilog.iter.check ], [ %n.vec94, %vec.epilog.middle.block ]
  %xtraiter = and i64 %1, 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.preheader, %.lr.ph.prol
  %.06281.prol = phi i64 [ %36, %.lr.ph.prol ], [ %.06281.ph, %.lr.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %gep.prol = getelementptr i8, ptr %invariant.gep, i64 %.06281.prol
  %34 = load i8, ptr %gep.prol, align 1, !tbaa !14
  %35 = getelementptr inbounds i8, ptr %2, i64 %.06281.prol
  store i8 %34, ptr %35, align 1, !tbaa !14
  %36 = add nuw i64 %.06281.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 !20

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.06281.unr = phi i64 [ %.06281.ph, %.lr.ph.preheader ], [ %36, %.lr.ph.prol ]
  %37 = sub i64 %.06281.ph, %1
  %38 = icmp ugt i64 %37, -4
  br i1 %38, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.06281 = phi i64 [ %50, %.lr.ph ], [ %.06281.unr, %.lr.ph.prol.loopexit ]
  %gep = getelementptr i8, ptr %invariant.gep, i64 %.06281
  %39 = load i8, ptr %gep, align 1, !tbaa !14
  %40 = getelementptr inbounds i8, ptr %2, i64 %.06281
  store i8 %39, ptr %40, align 1, !tbaa !14
  %41 = add nuw i64 %.06281, 1
  %gep.1 = getelementptr i8, ptr %invariant.gep, i64 %41
  %42 = load i8, ptr %gep.1, align 1, !tbaa !14
  %43 = getelementptr inbounds i8, ptr %2, i64 %41
  store i8 %42, ptr %43, align 1, !tbaa !14
  %44 = add nuw i64 %.06281, 2
  %gep.2 = getelementptr i8, ptr %invariant.gep, i64 %44
  %45 = load i8, ptr %gep.2, align 1, !tbaa !14
  %46 = getelementptr inbounds i8, ptr %2, i64 %44
  store i8 %45, ptr %46, align 1, !tbaa !14
  %47 = add nuw i64 %.06281, 3
  %gep.3 = getelementptr i8, ptr %invariant.gep, i64 %47
  %48 = load i8, ptr %gep.3, align 1, !tbaa !14
  %49 = getelementptr inbounds i8, ptr %2, i64 %47
  store i8 %48, ptr %49, align 1, !tbaa !14
  %50 = add nuw i64 %.06281, 4
  %exitcond.not.3 = icmp eq i64 %50, %1
  br i1 %exitcond.not.3, label %.loopexit, label %.lr.ph, !llvm.loop !22

.loopexit:                                        ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block, %vec.epilog.middle.block, %.preheader, %22
  %51 = sub i64 %5, %1
  %52 = icmp ugt i64 %51, %0
  br i1 %52, label %iter.check104, label %._crit_edge

iter.check104:                                    ; preds = %.loopexit
  %53 = add i64 %1, %0
  %54 = sub i64 %5, %53
  %min.iters.check102 = icmp ult i64 %54, 8
  %55 = add i64 %1, 31
  %diff.check100 = icmp ult i64 %55, 32
  %or.cond133 = or i1 %min.iters.check102, %diff.check100
  br i1 %or.cond133, label %.lr.ph83.preheader, label %vector.main.loop.iter.check106

vector.main.loop.iter.check106:                   ; preds = %iter.check104
  %min.iters.check105 = icmp ult i64 %54, 32
  br i1 %min.iters.check105, label %vec.epilog.ph118, label %vector.ph107

vector.ph107:                                     ; preds = %vector.main.loop.iter.check106
  %n.vec109 = and i64 %54, -32
  %invariant.gep137 = getelementptr i8, ptr %19, i64 %0
  br label %vector.body110

vector.body110:                                   ; preds = %vector.body110, %vector.ph107
  %index111 = phi i64 [ 0, %vector.ph107 ], [ %index.next114, %vector.body110 ]
  %gep138 = getelementptr i8, ptr %invariant.gep137, i64 %index111
  %56 = getelementptr i8, ptr %gep138, i64 %1
  %57 = getelementptr i8, ptr %56, i64 16
  %wide.load112 = load <16 x i8>, ptr %56, align 1, !tbaa !14
  %wide.load113 = load <16 x i8>, ptr %57, align 1, !tbaa !14
  %58 = getelementptr i8, ptr %gep138, i64 16
  store <16 x i8> %wide.load112, ptr %gep138, align 1, !tbaa !14
  store <16 x i8> %wide.load113, ptr %58, align 1, !tbaa !14
  %index.next114 = add nuw i64 %index111, 32
  %59 = icmp eq i64 %index.next114, %n.vec109
  br i1 %59, label %middle.block101, label %vector.body110, !llvm.loop !23

middle.block101:                                  ; preds = %vector.body110
  %cmp.n115 = icmp eq i64 %54, %n.vec109
  br i1 %cmp.n115, label %._crit_edge, label %vec.epilog.iter.check119

vec.epilog.iter.check119:                         ; preds = %middle.block101
  %ind.end125 = add i64 %n.vec109, %0
  %n.vec.remaining120 = and i64 %54, 24
  %min.epilog.iters.check121 = icmp eq i64 %n.vec.remaining120, 0
  br i1 %min.epilog.iters.check121, label %.lr.ph83.preheader, label %vec.epilog.ph118

vec.epilog.ph118:                                 ; preds = %vector.main.loop.iter.check106, %vec.epilog.iter.check119
  %vec.epilog.resume.val122 = phi i64 [ %n.vec109, %vec.epilog.iter.check119 ], [ 0, %vector.main.loop.iter.check106 ]
  %n.vec124 = and i64 %54, -8
  %ind.end = add i64 %n.vec124, %0
  %invariant.gep139 = getelementptr i8, ptr %19, i64 %0
  br label %vec.epilog.vector.body127

vec.epilog.vector.body127:                        ; preds = %vec.epilog.vector.body127, %vec.epilog.ph118
  %index128 = phi i64 [ %vec.epilog.resume.val122, %vec.epilog.ph118 ], [ %index.next131, %vec.epilog.vector.body127 ]
  %gep140 = getelementptr i8, ptr %invariant.gep139, i64 %index128
  %60 = getelementptr i8, ptr %gep140, i64 %1
  %wide.load130 = load <8 x i8>, ptr %60, align 1, !tbaa !14
  store <8 x i8> %wide.load130, ptr %gep140, align 1, !tbaa !14
  %index.next131 = add nuw i64 %index128, 8
  %61 = icmp eq i64 %index.next131, %n.vec124
  br i1 %61, label %vec.epilog.middle.block116, label %vec.epilog.vector.body127, !llvm.loop !24

vec.epilog.middle.block116:                       ; preds = %vec.epilog.vector.body127
  %cmp.n132 = icmp eq i64 %54, %n.vec124
  br i1 %cmp.n132, label %._crit_edge, label %.lr.ph83.preheader

.lr.ph83.preheader:                               ; preds = %vec.epilog.middle.block116, %iter.check104, %vec.epilog.iter.check119
  %.16382.ph = phi i64 [ %0, %iter.check104 ], [ %ind.end125, %vec.epilog.iter.check119 ], [ %ind.end, %vec.epilog.middle.block116 ]
  br label %.lr.ph83

.lr.ph83:                                         ; preds = %.lr.ph83.preheader, %.lr.ph83
  %.16382 = phi i64 [ %65, %.lr.ph83 ], [ %.16382.ph, %.lr.ph83.preheader ]
  %62 = getelementptr i8, ptr %19, i64 %.16382
  %63 = getelementptr i8, ptr %62, i64 %1
  %64 = load i8, ptr %63, align 1, !tbaa !14
  store i8 %64, ptr %62, align 1, !tbaa !14
  %65 = add nuw i64 %.16382, 1
  %66 = icmp ult i64 %65, %51
  br i1 %66, label %.lr.ph83, label %._crit_edge, !llvm.loop !25

._crit_edge:                                      ; preds = %.lr.ph83, %middle.block101, %vec.epilog.middle.block116, %.loopexit
  %67 = tail call i64 @HBufferImageFreeLines()
  %68 = tail call i64 @HBufferImageBufferToList(ptr noundef nonnull %19, i64 noundef %51)
  tail call void @FreePool(ptr noundef nonnull %19) #3
  %69 = icmp slt i64 %68, 0
  br i1 %69, label %89, label %70

70:                                               ; preds = %._crit_edge
  %71 = load ptr, ptr @HMainEditor, align 8, !tbaa !26
  %72 = load ptr, ptr %71, align 8, !tbaa !28
  %73 = add nuw nsw i64 %15, 1
  %xtraiter134 = and i64 %73, 7
  %74 = icmp ult i64 %.061, 112
  br i1 %74, label %.unr-lcssa, label %.new

.new:                                             ; preds = %70
  %unroll_iter = and i64 %73, 2305843009213693944
  br label %75

75:                                               ; preds = %75, %.new
  %.064.in = phi ptr [ %72, %.new ], [ %.064.7, %75 ]
  %niter = phi i64 [ 0, %.new ], [ %niter.next.7, %75 ]
  %.064 = load ptr, ptr %.064.in, align 8, !tbaa !29
  %.064.1 = load ptr, ptr %.064, align 8, !tbaa !29
  %.064.2 = load ptr, ptr %.064.1, align 8, !tbaa !29
  %.064.3 = load ptr, ptr %.064.2, align 8, !tbaa !29
  %.064.4 = load ptr, ptr %.064.3, align 8, !tbaa !29
  %.064.5 = load ptr, ptr %.064.4, align 8, !tbaa !29
  %.064.6 = load ptr, ptr %.064.5, align 8, !tbaa !29
  %.064.7 = load ptr, ptr %.064.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 %75, !llvm.loop !31

.unr-lcssa:                                       ; preds = %75, %70
  %.064.lcssa.ph = phi ptr [ poison, %70 ], [ %.064.7, %75 ]
  %.064.in.unr = phi ptr [ %72, %70 ], [ %.064.7, %75 ]
  %lcmp.mod135.not = icmp eq i64 %xtraiter134, 0
  br i1 %lcmp.mod135.not, label %.epilog-lcssa, label %.epil.preheader

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

.epilog-lcssa:                                    ; preds = %.epil.preheader, %.unr-lcssa
  %.064.lcssa = phi ptr [ %.064.lcssa.ph, %.unr-lcssa ], [ %.064.epil, %.epil.preheader ]
  %76 = tail call zeroext i8 @DebugAssertEnabled() #3
  %.not77 = icmp eq i8 %76, 0
  %.pre = ptrtoint ptr %.064.lcssa to i64
  %.pre87 = add i64 %.pre, -32
  %.pre89 = inttoptr i64 %.pre87 to ptr
  br i1 %.not77, label %._crit_edge86, label %77

77:                                               ; preds = %.epilog-lcssa
  %78 = load i64, ptr %.pre89, align 8, !tbaa !33
  %.not78 = icmp eq i64 %78, 1819043173
  br i1 %.not78, label %._crit_edge86, label %79

79:                                               ; preds = %77
  tail call void @DebugAssert(ptr noundef nonnull @.str.10, i64 noundef 1993, ptr noundef nonnull @.str.11) #3
  br label %._crit_edge86

._crit_edge86:                                    ; preds = %.epilog-lcssa, %77, %79
  %80 = phi ptr [ %.064.lcssa, %79 ], [ %.pre89, %77 ], [ %.pre89, %.epilog-lcssa ]
  store ptr %80, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 24), align 8, !tbaa !35
  %.not79 = icmp uge i64 %14, %0
  %81 = add i64 %1, %0
  %82 = icmp ult i64 %14, %81
  %or.cond = and i1 %.not79, %82
  %83 = icmp ult i64 %14, %0
  %84 = select i1 %83, i64 0, i64 %1
  %spec.select = sub i64 %14, %84
  %.1 = select i1 %or.cond, i64 %0, i64 %spec.select
  %85 = lshr i64 %.1, 4
  %86 = add nuw nsw i64 %85, 1
  %87 = and i64 %.1, 15
  %88 = add nuw nsw i64 %87, 1
  tail call void @HBufferImageMovePosition(i64 noundef %86, i64 noundef %88, i8 noundef zeroext 1)
  br label %89

89:                                               ; preds = %._crit_edge, %9, %7, %3, %._crit_edge86
  %.0 = phi i64 [ 0, %._crit_edge86 ], [ -9223372036854775807, %3 ], [ 0, %7 ], [ -9223372036854775799, %9 ], [ %68, %._crit_edge ]
  ret i64 %.0
}

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.usub.sat.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, !21}
!21 = !{!"llvm.loop.unroll.disable"}
!22 = distinct !{!22, !16, !17}
!23 = distinct !{!23, !16, !17, !18}
!24 = distinct !{!24, !16, !17, !18}
!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, !21}
!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,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass