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

; 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._EFI_EDITOR_LINE = type { i64, ptr, i64, i64, i32, %struct._LIST_ENTRY }
%struct._LIST_ENTRY = type { ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [163 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @InternalEditorMiscLineAdvance(i64 noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store i64 %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  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
  %11 = load ptr, ptr %6, align 8, !tbaa !9
  %12 = icmp eq ptr %11, null
  br i1 %12, label %16, label %13

13:                                               ; preds = %3
  %14 = load ptr, ptr %7, align 8, !tbaa !9
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %13, %3
  store ptr null, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %66

17:                                               ; preds = %13
  %18 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %18, ptr %9, align 8, !tbaa !9
  store i64 0, ptr %8, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %61, %17
  %20 = load i64, ptr %8, align 8, !tbaa !5
  %21 = load i64, ptr %5, align 8, !tbaa !5
  %22 = icmp ult i64 %20, %21
  br i1 %22, label %23, label %64

23:                                               ; preds = %19
  %24 = load ptr, ptr %9, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %24, i32 0, i32 5
  %26 = getelementptr inbounds %struct._LIST_ENTRY, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = load ptr, ptr %7, align 8, !tbaa !9
  %29 = icmp eq ptr %27, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %23
  store ptr null, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %66

31:                                               ; preds = %23
  %32 = call zeroext i8 @DebugAssertEnabled()
  %33 = zext i8 %32 to i32
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %51

35:                                               ; preds = %31
  %36 = load ptr, ptr %9, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %36, i32 0, i32 5
  %38 = getelementptr inbounds %struct._LIST_ENTRY, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  %40 = ptrtoint ptr %39 to i64
  %41 = sub i64 %40, ptrtoint (ptr getelementptr inbounds (%struct._EFI_EDITOR_LINE, ptr null, i32 0, i32 5) to i64)
  %42 = inttoptr i64 %41 to ptr
  %43 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %42, i32 0, i32 0
  %44 = load i64, ptr %43, align 8, !tbaa !15
  %45 = icmp ne i64 %44, 1819043173
  br i1 %45, label %46, label %51

46:                                               ; preds = %35
  call void @DebugAssert(ptr noundef @.str.1, i64 noundef 181, ptr noundef @.str.2)
  %47 = load ptr, ptr %9, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %47, i32 0, i32 5
  %49 = getelementptr inbounds %struct._LIST_ENTRY, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  br label %59

51:                                               ; preds = %35, %31
  %52 = load ptr, ptr %9, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %52, i32 0, i32 5
  %54 = getelementptr inbounds %struct._LIST_ENTRY, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !11
  %56 = ptrtoint ptr %55 to i64
  %57 = sub i64 %56, ptrtoint (ptr getelementptr inbounds (%struct._EFI_EDITOR_LINE, ptr null, i32 0, i32 5) to i64)
  %58 = inttoptr i64 %57 to ptr
  br label %59

59:                                               ; preds = %51, %46
  %60 = phi ptr [ %50, %46 ], [ %58, %51 ]
  store ptr %60, ptr %9, align 8, !tbaa !9
  br label %61

61:                                               ; preds = %59
  %62 = load i64, ptr %8, align 8, !tbaa !5
  %63 = add i64 %62, 1
  store i64 %63, ptr %8, align 8, !tbaa !5
  br label %19, !llvm.loop !16

64:                                               ; preds = %19
  %65 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %65, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %66

66:                                               ; preds = %64, %30, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %67 = load ptr, ptr %4, align 8
  ret ptr %67
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare zeroext i8 @DebugAssertEnabled() #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 willreturn memory(argmem: readwrite) }
attributes #2 = { "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, !10, i64 40}
!12 = !{!"_EFI_EDITOR_LINE", !6, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !14, i64 40}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!15 = !{!12, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [163 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @InternalEditorMiscLineAdvance(i64 noundef %0, ptr noundef readonly %1, ptr noundef readnone %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %1, null
  %5 = icmp eq ptr %2, null
  %or.cond = or i1 %4, %5
  br i1 %or.cond, label %.loopexit, label %.preheader

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

.lr.ph:                                           ; preds = %.preheader, %._crit_edge
  %.019 = phi ptr [ %15, %._crit_edge ], [ %1, %.preheader ]
  %.01318 = phi i64 [ %16, %._crit_edge ], [ 0, %.preheader ]
  %6 = getelementptr inbounds i8, ptr %.019, i64 40
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = icmp eq ptr %7, %2
  br i1 %8, label %.loopexit, label %9

9:                                                ; preds = %.lr.ph
  %10 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %10, 0
  %.pre = load ptr, ptr %6, align 8, !tbaa !5
  %.pre23 = ptrtoint ptr %.pre to i64
  %.pre24 = add i64 %.pre23, -40
  %.pre26 = inttoptr i64 %.pre24 to ptr
  br i1 %.not, label %._crit_edge, label %11

11:                                               ; preds = %9
  %12 = load i64, ptr %.pre26, align 8, !tbaa !13
  %.not17 = icmp eq i64 %12, 1819043173
  br i1 %.not17, label %._crit_edge, label %13

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

._crit_edge:                                      ; preds = %9, %11, %13
  %15 = phi ptr [ %14, %13 ], [ %.pre26, %11 ], [ %.pre26, %9 ]
  %16 = add nuw i64 %.01318, 1
  %exitcond.not = icmp eq i64 %16, %0
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !14

.loopexit:                                        ; preds = %.lr.ph, %._crit_edge, %.preheader, %3
  %.014 = phi ptr [ null, %3 ], [ %1, %.preheader ], [ null, %.lr.ph ], [ %15, %._crit_edge ]
  ret ptr %.014
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #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 = { "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, !10, i64 40}
!6 = !{!"_EFI_EDITOR_LINE", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !11, i64 32, !12, i64 40}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!13 = !{!6, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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