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

; 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

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

; 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 void @FileBufferMovePosition(i64 noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @FileBufferScrollRight() #1 {
  %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) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %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 ptr, ptr %2, align 8, !tbaa !13
  %8 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %7, i32 0, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !14
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %12

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

12:                                               ; preds = %0
  %13 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 6), align 8, !tbaa !17
  store i64 %13, ptr %3, align 8, !tbaa !18
  %14 = 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 !19
  store i64 %14, ptr %4, align 8, !tbaa !18
  %15 = load i64, ptr %4, align 8, !tbaa !18
  %16 = load ptr, ptr %2, align 8, !tbaa !13
  %17 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %16, i32 0, i32 2
  %18 = load i64, ptr %17, align 8, !tbaa !20
  %19 = icmp ugt i64 %15, %18
  br i1 %19, label %20, label %32

20:                                               ; preds = %12
  %21 = load ptr, ptr %2, align 8, !tbaa !13
  %22 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %21, i32 0, i32 5
  %23 = getelementptr inbounds %struct._LIST_ENTRY, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !21
  %25 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 2), align 8, !tbaa !22
  %26 = icmp ne ptr %24, %25
  br i1 %26, label %27, label %30

27:                                               ; preds = %20
  %28 = load i64, ptr %3, align 8, !tbaa !18
  %29 = add i64 %28, 1
  store i64 %29, ptr %3, align 8, !tbaa !18
  store i64 1, ptr %4, align 8, !tbaa !18
  br label %31

30:                                               ; preds = %20
  store i64 0, ptr %1, align 8
  store i32 1, ptr %5, align 4
  br label %38

31:                                               ; preds = %27
  br label %35

32:                                               ; preds = %12
  %33 = load i64, ptr %4, align 8, !tbaa !18
  %34 = add i64 %33, 1
  store i64 %34, ptr %4, align 8, !tbaa !18
  br label %35

35:                                               ; preds = %32, %31
  %36 = load i64, ptr %3, align 8, !tbaa !18
  %37 = load i64, ptr %4, align 8, !tbaa !18
  call void @FileBufferMovePosition(i64 noundef %36, i64 noundef %37)
  store i64 0, ptr %1, align 8
  store i32 1, ptr %5, align 4
  br label %38

38:                                               ; preds = %35, %30, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  %39 = load i64, ptr %1, align 8
  ret i64 %39
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = !{!15, !7, i64 8}
!15 = !{!"_EFI_EDITOR_LINE", !11, i64 0, !7, i64 8, !11, i64 16, !11, i64 24, !10, i64 32, !16, i64 40}
!16 = !{!"_LIST_ENTRY", !7, i64 0, !7, i64 8}
!17 = !{!6, !11, i64 56}
!18 = !{!11, !11, i64 0}
!19 = !{!6, !11, i64 64}
!20 = !{!15, !11, i64 16}
!21 = !{!15, !7, i64 40}
!22 = !{!6, !7, 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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i64 @FileBufferScrollRight() local_unnamed_addr #0 {
  %1 = load ptr, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 112), align 8, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %1, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !13
  %4 = icmp eq ptr %3, null
  br i1 %4, label %20, label %5

5:                                                ; preds = %0
  %6 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 56), align 8, !tbaa !16
  %7 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 64), align 8, !tbaa !17
  %8 = getelementptr inbounds i8, ptr %1, i64 16
  %9 = load i64, ptr %8, align 8, !tbaa !18
  %10 = icmp ugt i64 %7, %9
  br i1 %10, label %11, label %17

11:                                               ; preds = %5
  %12 = getelementptr inbounds i8, ptr %1, i64 40
  %13 = load ptr, ptr %12, align 8, !tbaa !19
  %14 = load ptr, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 16), align 8, !tbaa !20
  %.not = icmp eq ptr %13, %14
  br i1 %.not, label %20, label %15

15:                                               ; preds = %11
  %16 = add i64 %6, 1
  br label %19

17:                                               ; preds = %5
  %18 = add i64 %7, 1
  br label %19

19:                                               ; preds = %17, %15
  %.08 = phi i64 [ %16, %15 ], [ %6, %17 ]
  %.0 = phi i64 [ 1, %15 ], [ %18, %17 ]
  tail call void @FileBufferMovePosition(i64 noundef %.08, i64 noundef %.0)
  br label %20

20:                                               ; preds = %11, %0, %19
  ret i64 0
}

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" }

!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 = !{!14, !7, i64 8}
!14 = !{!"_EFI_EDITOR_LINE", !11, i64 0, !7, i64 8, !11, i64 16, !11, i64 24, !10, i64 32, !15, i64 40}
!15 = !{!"_LIST_ENTRY", !7, i64 0, !7, i64 8}
!16 = !{!6, !11, i64 56}
!17 = !{!6, !11, i64 64}
!18 = !{!14, !11, i64 16}
!19 = !{!14, !7, i64 40}
!20 = !{!6, !7, i64 16}


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