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

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

@FileBuffer = external dso_local global %struct.EFI_EDITOR_FILE_BUFFER, align 8
@.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: 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 i64 @FileBufferScrollLeft() #2 {
  %1 = alloca i64, align 8
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %6 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 12), align 8, !tbaa !5
  store ptr %6, ptr %2, align 8, !tbaa !13
  %7 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 6), align 8, !tbaa !14
  store i64 %7, ptr %3, align 8, !tbaa !15
  %8 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 6), i32 0, i32 1), align 8, !tbaa !16
  store i64 %8, ptr %4, align 8, !tbaa !15
  %9 = load i64, ptr %4, align 8, !tbaa !15
  %10 = icmp ule i64 %9, 1
  br i1 %10, label %11, label %56

11:                                               ; preds = %0
  %12 = load ptr, ptr %2, align 8, !tbaa !13
  %13 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %12, i32 0, i32 5
  %14 = getelementptr inbounds %struct._LIST_ENTRY, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !17
  %16 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 2), align 8, !tbaa !20
  %17 = icmp ne ptr %15, %16
  br i1 %17, label %18, label %54

18:                                               ; preds = %11
  %19 = load i64, ptr %3, align 8, !tbaa !15
  %20 = add i64 %19, -1
  store i64 %20, ptr %3, align 8, !tbaa !15
  %21 = call zeroext i8 @DebugAssertEnabled()
  %22 = zext i8 %21 to i32
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %40

24:                                               ; preds = %18
  %25 = load ptr, ptr %2, align 8, !tbaa !13
  %26 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %25, i32 0, i32 5
  %27 = getelementptr inbounds %struct._LIST_ENTRY, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  %29 = ptrtoint ptr %28 to i64
  %30 = sub i64 %29, ptrtoint (ptr getelementptr inbounds (%struct._EFI_EDITOR_LINE, ptr null, i32 0, i32 5) to i64)
  %31 = inttoptr i64 %30 to ptr
  %32 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %31, i32 0, i32 0
  %33 = load i64, ptr %32, align 8, !tbaa !21
  %34 = icmp ne i64 %33, 1819043173
  br i1 %34, label %35, label %40

35:                                               ; preds = %24
  call void @DebugAssert(ptr noundef @.str.1, i64 noundef 1683, ptr noundef @.str.2)
  %36 = load ptr, ptr %2, align 8, !tbaa !13
  %37 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %36, i32 0, i32 5
  %38 = getelementptr inbounds %struct._LIST_ENTRY, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !17
  br label %48

40:                                               ; preds = %24, %18
  %41 = load ptr, ptr %2, align 8, !tbaa !13
  %42 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %41, i32 0, i32 5
  %43 = getelementptr inbounds %struct._LIST_ENTRY, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !17
  %45 = ptrtoint ptr %44 to i64
  %46 = sub i64 %45, ptrtoint (ptr getelementptr inbounds (%struct._EFI_EDITOR_LINE, ptr null, i32 0, i32 5) to i64)
  %47 = inttoptr i64 %46 to ptr
  br label %48

48:                                               ; preds = %40, %35
  %49 = phi ptr [ %39, %35 ], [ %47, %40 ]
  store ptr %49, ptr %2, align 8, !tbaa !13
  %50 = load ptr, ptr %2, align 8, !tbaa !13
  %51 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %50, i32 0, i32 2
  %52 = load i64, ptr %51, align 8, !tbaa !22
  %53 = add i64 %52, 1
  store i64 %53, ptr %4, align 8, !tbaa !15
  br label %55

54:                                               ; preds = %11
  store i64 0, ptr %1, align 8
  store i32 1, ptr %5, align 4
  br label %62

55:                                               ; preds = %48
  br label %59

56:                                               ; preds = %0
  %57 = load i64, ptr %4, align 8, !tbaa !15
  %58 = add i64 %57, -1
  store i64 %58, ptr %4, align 8, !tbaa !15
  br label %59

59:                                               ; preds = %56, %55
  %60 = load i64, ptr %3, align 8, !tbaa !15
  %61 = load i64, ptr %4, align 8, !tbaa !15
  call void @FileBufferMovePosition(i64 noundef %60, i64 noundef %61)
  store i64 0, ptr %1, align 8
  store i32 1, ptr %5, align 4
  br label %62

62:                                               ; preds = %59, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %63 = load i64, ptr %1, align 8
  ret i64 %63
}

; Function Attrs: nounwind uwtable
declare dso_local void @FileBufferMovePosition(i64 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, !7, i64 112}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !11, i64 32, !12, i64 40, !12, i64 56, !12, i64 72, !12, i64 88, !8, i64 104, !8, i64 105, !8, i64 106, !7, i64 112}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long long", !8, i64 0}
!12 = !{!"", !11, i64 0, !11, i64 8}
!13 = !{!7, !7, i64 0}
!14 = !{!6, !11, i64 56}
!15 = !{!11, !11, i64 0}
!16 = !{!6, !11, i64 64}
!17 = !{!18, !7, i64 48}
!18 = !{!"_EFI_EDITOR_LINE", !11, i64 0, !7, i64 8, !11, i64 16, !11, i64 24, !10, i64 32, !19, i64 40}
!19 = !{!"_LIST_ENTRY", !7, i64 0, !7, i64 8}
!20 = !{!6, !7, i64 16}
!21 = !{!18, !11, i64 0}
!22 = !{!18, !11, i64 16}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.EFI_EDITOR_FILE_BUFFER = type { ptr, i32, ptr, ptr, i64, %struct.EFI_EDITOR_POSITION, %struct.EFI_EDITOR_POSITION, %struct.EFI_EDITOR_POSITION, %struct.EFI_EDITOR_POSITION, i8, i8, i8, ptr }
%struct.EFI_EDITOR_POSITION = type { i64, i64 }

@FileBuffer = external dso_local local_unnamed_addr global %struct.EFI_EDITOR_FILE_BUFFER, align 8
@.str.1 = external hidden unnamed_addr constant [163 x i8], align 1
@.str.2 = 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 noundef i64 @FileBufferScrollLeft() local_unnamed_addr #1 {
  %1 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 56), align 8, !tbaa !5
  %2 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 64), align 8, !tbaa !13
  %3 = icmp ult i64 %2, 2
  br i1 %3, label %4, label %20

4:                                                ; preds = %0
  %5 = load ptr, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 112), align 8, !tbaa !14
  %6 = getelementptr inbounds i8, ptr %5, i64 48
  %7 = load ptr, ptr %6, align 8, !tbaa !15
  %8 = load ptr, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 16), align 8, !tbaa !18
  %.not = icmp eq ptr %7, %8
  br i1 %.not, label %23, label %9

9:                                                ; preds = %4
  %10 = add i64 %1, -1
  %11 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not13 = icmp eq i8 %11, 0
  %.pre = load ptr, ptr %6, align 8, !tbaa !15
  %.pre15 = ptrtoint ptr %.pre to i64
  %.pre16 = add i64 %.pre15, -40
  %.pre18 = inttoptr i64 %.pre16 to ptr
  br i1 %.not13, label %._crit_edge, label %12

12:                                               ; preds = %9
  %13 = load i64, ptr %.pre18, align 8, !tbaa !19
  %.not14 = icmp eq i64 %13, 1819043173
  br i1 %.not14, label %._crit_edge, label %14

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

._crit_edge:                                      ; preds = %9, %12, %14
  %16 = phi ptr [ %15, %14 ], [ %.pre18, %12 ], [ %.pre18, %9 ]
  %17 = getelementptr inbounds i8, ptr %16, i64 16
  %18 = load i64, ptr %17, align 8, !tbaa !20
  %19 = add i64 %18, 1
  br label %22

20:                                               ; preds = %0
  %21 = add i64 %2, -1
  br label %22

22:                                               ; preds = %20, %._crit_edge
  %.010 = phi i64 [ %10, %._crit_edge ], [ %1, %20 ]
  %.0 = phi i64 [ %19, %._crit_edge ], [ %21, %20 ]
  tail call void @FileBufferMovePosition(i64 noundef %.010, i64 noundef %.0)
  br label %23

23:                                               ; preds = %4, %22
  ret i64 0
}

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

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, !11, i64 56}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !11, i64 32, !12, i64 40, !12, i64 56, !12, i64 72, !12, i64 88, !8, i64 104, !8, i64 105, !8, i64 106, !7, i64 112}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long long", !8, i64 0}
!12 = !{!"", !11, i64 0, !11, i64 8}
!13 = !{!6, !11, i64 64}
!14 = !{!6, !7, i64 112}
!15 = !{!16, !7, i64 48}
!16 = !{!"_EFI_EDITOR_LINE", !11, i64 0, !7, i64 8, !11, i64 16, !11, i64 24, !10, i64 32, !17, i64 40}
!17 = !{!"_LIST_ENTRY", !7, i64 0, !7, i64 8}
!18 = !{!6, !7, i64 16}
!19 = !{!16, !11, i64 0}
!20 = !{!16, !11, i64 16}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass