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

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

@HMainEditor = external global %struct.HEFI_EDITOR_GLOBAL_EDITOR, align 8
@.str = external hidden unnamed_addr constant [160 x i8], align 1
@.str.1 = 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 zeroext i8 @DebugAssertEnabled() #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr 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
define dso_local ptr @HLineRetreat(i64 noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store i64 %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
  %7 = load ptr, ptr @HMainEditor, align 8, !tbaa !9
  %8 = getelementptr inbounds %struct.HEFI_EDITOR_BUFFER_IMAGE, ptr %7, i32 0, i32 3
  %9 = load ptr, ptr %8, align 8, !tbaa !14
  store ptr %9, ptr %5, align 8, !tbaa !16
  %10 = load ptr, ptr %5, align 8, !tbaa !16
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %63

13:                                               ; preds = %1
  store i64 0, ptr %4, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %58, %13
  %15 = load i64, ptr %4, align 8, !tbaa !5
  %16 = load i64, ptr %3, align 8, !tbaa !5
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %18, label %61

18:                                               ; preds = %14
  %19 = load ptr, ptr %5, align 8, !tbaa !16
  %20 = getelementptr inbounds %struct._HEFI_EDITOR_LINE, ptr %19, i32 0, i32 3
  %21 = getelementptr inbounds %struct._LIST_ENTRY, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  %23 = load ptr, ptr @HMainEditor, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.HEFI_EDITOR_BUFFER_IMAGE, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !20
  %26 = icmp eq ptr %22, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %18
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %63

28:                                               ; preds = %18
  %29 = call zeroext i8 @DebugAssertEnabled()
  %30 = zext i8 %29 to i32
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %48

32:                                               ; preds = %28
  %33 = load ptr, ptr %5, align 8, !tbaa !16
  %34 = getelementptr inbounds %struct._HEFI_EDITOR_LINE, ptr %33, i32 0, i32 3
  %35 = getelementptr inbounds %struct._LIST_ENTRY, ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !17
  %37 = ptrtoint ptr %36 to i64
  %38 = sub i64 %37, ptrtoint (ptr getelementptr inbounds (%struct._HEFI_EDITOR_LINE, ptr null, i32 0, i32 3) to i64)
  %39 = inttoptr i64 %38 to ptr
  %40 = getelementptr inbounds %struct._HEFI_EDITOR_LINE, ptr %39, i32 0, i32 0
  %41 = load i64, ptr %40, align 8, !tbaa !21
  %42 = icmp ne i64 %41, 1819043173
  br i1 %42, label %43, label %48

43:                                               ; preds = %32
  call void @DebugAssert(ptr noundef @.str, i64 noundef 101, ptr noundef @.str.1)
  %44 = load ptr, ptr %5, align 8, !tbaa !16
  %45 = getelementptr inbounds %struct._HEFI_EDITOR_LINE, ptr %44, i32 0, i32 3
  %46 = getelementptr inbounds %struct._LIST_ENTRY, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !17
  br label %56

48:                                               ; preds = %32, %28
  %49 = load ptr, ptr %5, align 8, !tbaa !16
  %50 = getelementptr inbounds %struct._HEFI_EDITOR_LINE, ptr %49, i32 0, i32 3
  %51 = getelementptr inbounds %struct._LIST_ENTRY, ptr %50, i32 0, i32 1
  %52 = load ptr, ptr %51, align 8, !tbaa !17
  %53 = ptrtoint ptr %52 to i64
  %54 = sub i64 %53, ptrtoint (ptr getelementptr inbounds (%struct._HEFI_EDITOR_LINE, ptr null, i32 0, i32 3) to i64)
  %55 = inttoptr i64 %54 to ptr
  br label %56

56:                                               ; preds = %48, %43
  %57 = phi ptr [ %47, %43 ], [ %55, %48 ]
  store ptr %57, ptr %5, align 8, !tbaa !16
  br label %58

58:                                               ; preds = %56
  %59 = load i64, ptr %4, align 8, !tbaa !5
  %60 = add i64 %59, 1
  store i64 %60, ptr %4, align 8, !tbaa !5
  br label %14, !llvm.loop !22

61:                                               ; preds = %14
  %62 = load ptr, ptr %5, align 8, !tbaa !16
  store ptr %62, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %63

63:                                               ; preds = %61, %27, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %64 = load ptr, ptr %2, align 8
  ret ptr %64
}

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, !11, i64 0}
!10 = !{!"", !11, i64 0, !7, i64 8, !12, i64 16, !7, i64 32, !11, i64 40, !13, i64 48, !13, i64 52, !6, i64 56, !6, i64 64}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !11, i64 24}
!15 = !{!"", !11, i64 0, !11, i64 8, !6, i64 16, !11, i64 24, !12, i64 32, !12, i64 48, !12, i64 64, !6, i64 80, !7, i64 88, !7, i64 89, !13, i64 92, !11, i64 96, !11, i64 104, !11, i64 112}
!16 = !{!11, !11, i64 0}
!17 = !{!18, !11, i64 40}
!18 = !{!"_HEFI_EDITOR_LINE", !6, i64 0, !7, i64 8, !6, i64 24, !19, i64 32}
!19 = !{!"_LIST_ENTRY", !11, i64 0, !11, i64 8}
!20 = !{!15, !11, i64 0}
!21 = !{!18, !6, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"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_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.HEFI_EDITOR_POSITION = type { i64, i64 }

@HMainEditor = external local_unnamed_addr global %struct.HEFI_EDITOR_GLOBAL_EDITOR, align 8
@.str = external hidden unnamed_addr constant [160 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1

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
define dso_local ptr @HLineRetreat(i64 noundef %0) local_unnamed_addr #1 {
  %2 = load ptr, ptr @HMainEditor, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 24
  %4 = load ptr, ptr %3, align 8, !tbaa !13
  %5 = icmp eq ptr %4, null
  br i1 %5, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %1
  %.not17 = icmp eq i64 %0, 0
  br i1 %.not17, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %._crit_edge
  %.014 = phi ptr [ %17, %._crit_edge ], [ %4, %.preheader ]
  %.0913 = phi i64 [ %18, %._crit_edge ], [ 0, %.preheader ]
  %6 = getelementptr inbounds i8, ptr %.014, i64 40
  %7 = load ptr, ptr %6, align 8, !tbaa !15
  %8 = load ptr, ptr @HMainEditor, align 8, !tbaa !5
  %9 = load ptr, ptr %8, align 8, !tbaa !18
  %10 = icmp eq ptr %7, %9
  br i1 %10, label %.loopexit, label %11

11:                                               ; preds = %.lr.ph
  %12 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %12, 0
  %.pre = load ptr, ptr %6, align 8, !tbaa !15
  %.pre18 = ptrtoint ptr %.pre to i64
  %.pre19 = add i64 %.pre18, -32
  %.pre21 = inttoptr i64 %.pre19 to ptr
  br i1 %.not, label %._crit_edge, label %13

13:                                               ; preds = %11
  %14 = load i64, ptr %.pre21, align 8, !tbaa !19
  %.not12 = icmp eq i64 %14, 1819043173
  br i1 %.not12, label %._crit_edge, label %15

15:                                               ; preds = %13
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 101, ptr noundef nonnull @.str.1) #2
  %16 = load ptr, ptr %6, align 8, !tbaa !15
  br label %._crit_edge

._crit_edge:                                      ; preds = %11, %13, %15
  %17 = phi ptr [ %16, %15 ], [ %.pre21, %13 ], [ %.pre21, %11 ]
  %18 = add nuw i64 %.0913, 1
  %exitcond.not = icmp eq i64 %18, %0
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !20

.loopexit:                                        ; preds = %.lr.ph, %._crit_edge, %.preheader, %1
  %.010 = phi ptr [ null, %1 ], [ %4, %.preheader ], [ null, %.lr.ph ], [ %17, %._crit_edge ]
  ret ptr %.010
}

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


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass