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

; 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_GLOBAL_EDITOR = type { ptr, %union.EFI_EDITOR_COLOR_UNION, %struct.EFI_EDITOR_POSITION, ptr, i8, ptr, i32, i32 }
%union.EFI_EDITOR_COLOR_UNION = type { i64 }
%struct.EFI_EDITOR_POSITION = type { i64, i64 }
%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 }

@MainEditor = external global %struct.EFI_EDITOR_GLOBAL_EDITOR, align 8

; Function Attrs: nounwind uwtable
declare dso_local ptr @InternalEditorMiscLineAdvance(i64 noundef, ptr noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @InternalEditorMiscLineRetreat(i64 noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local ptr @MoveCurrentLine(i64 noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, 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) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %7 = load i64, ptr %3, align 8, !tbaa !5
  %8 = icmp sle i64 %7, 0
  br i1 %8, label %9, label %27

9:                                                ; preds = %1
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = icmp slt i64 %10, 0
  br i1 %11, label %12, label %15

12:                                               ; preds = %9
  %13 = load i64, ptr %3, align 8, !tbaa !5
  %14 = sub nsw i64 0, %13
  br label %17

15:                                               ; preds = %9
  %16 = load i64, ptr %3, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %15, %12
  %18 = phi i64 [ %14, %12 ], [ %16, %15 ]
  store i64 %18, ptr %5, align 8, !tbaa !5
  %19 = load i64, ptr %5, align 8, !tbaa !5
  %20 = load ptr, ptr @MainEditor, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.EFI_EDITOR_FILE_BUFFER, ptr %20, i32 0, i32 12
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  %23 = load ptr, ptr @MainEditor, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.EFI_EDITOR_FILE_BUFFER, ptr %23, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  %26 = call ptr @InternalEditorMiscLineRetreat(i64 noundef %19, ptr noundef %22, ptr noundef %25)
  store ptr %26, ptr %4, align 8, !tbaa !17
  br label %36

27:                                               ; preds = %1
  %28 = load i64, ptr %3, align 8, !tbaa !5
  %29 = load ptr, ptr @MainEditor, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.EFI_EDITOR_FILE_BUFFER, ptr %29, i32 0, i32 12
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  %32 = load ptr, ptr @MainEditor, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.EFI_EDITOR_FILE_BUFFER, ptr %32, i32 0, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  %35 = call ptr @InternalEditorMiscLineAdvance(i64 noundef %28, ptr noundef %31, ptr noundef %34)
  store ptr %35, ptr %4, align 8, !tbaa !17
  br label %36

36:                                               ; preds = %27, %17
  %37 = load ptr, ptr %4, align 8, !tbaa !17
  %38 = icmp eq ptr %37, null
  br i1 %38, label %39, label %40

39:                                               ; preds = %36
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %45

40:                                               ; preds = %36
  %41 = load ptr, ptr %4, align 8, !tbaa !17
  %42 = load ptr, ptr @MainEditor, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.EFI_EDITOR_FILE_BUFFER, ptr %42, i32 0, i32 12
  store ptr %41, ptr %43, align 8, !tbaa !14
  %44 = load ptr, ptr %4, align 8, !tbaa !17
  store ptr %44, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %45

45:                                               ; preds = %40, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %46 = load ptr, ptr %2, align 8
  ret ptr %46
}

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 = { 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, !11, i64 32, !7, i64 40, !11, i64 48, !13, i64 56, !13, i64 60}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !11, i64 112}
!15 = !{!"", !11, i64 0, !13, i64 8, !11, i64 16, !11, i64 24, !6, i64 32, !12, i64 40, !12, i64 56, !12, i64 72, !12, i64 88, !7, i64 104, !7, i64 105, !7, i64 106, !11, i64 112}
!16 = !{!15, !11, i64 16}
!17 = !{!11, !11, i64 0}


; 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_GLOBAL_EDITOR = type { ptr, %union.EFI_EDITOR_COLOR_UNION, %struct.EFI_EDITOR_POSITION, ptr, i8, ptr, i32, i32 }
%union.EFI_EDITOR_COLOR_UNION = type { i64 }
%struct.EFI_EDITOR_POSITION = type { i64, i64 }

@MainEditor = external local_unnamed_addr global %struct.EFI_EDITOR_GLOBAL_EDITOR, align 8

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @MoveCurrentLine(i64 noundef %0) local_unnamed_addr #0 {
  %2 = icmp slt i64 %0, 1
  br i1 %2, label %3, label %11

3:                                                ; preds = %1
  %4 = sub nsw i64 0, %0
  %5 = load ptr, ptr @MainEditor, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 112
  %7 = load ptr, ptr %6, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %5, i64 16
  %9 = load ptr, ptr %8, align 8, !tbaa !15
  %10 = tail call ptr @InternalEditorMiscLineRetreat(i64 noundef %4, ptr noundef %7, ptr noundef %9)
  br label %18

11:                                               ; preds = %1
  %12 = load ptr, ptr @MainEditor, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i64 112
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %12, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  %17 = tail call ptr @InternalEditorMiscLineAdvance(i64 noundef %0, ptr noundef %14, ptr noundef %16)
  br label %18

18:                                               ; preds = %11, %3
  %.09 = phi ptr [ %10, %3 ], [ %17, %11 ]
  %19 = icmp eq ptr %.09, null
  br i1 %19, label %23, label %20

20:                                               ; preds = %18
  %21 = load ptr, ptr @MainEditor, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 112
  store ptr %.09, ptr %22, align 8, !tbaa !13
  br label %23

23:                                               ; preds = %18, %20
  ret ptr %.09
}

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 0}
!6 = !{!"", !7, i64 0, !8, i64 8, !10, i64 16, !7, i64 32, !8, i64 40, !7, i64 48, !12, i64 56, !12, i64 60}
!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 112}
!14 = !{!"", !7, i64 0, !12, i64 8, !7, i64 16, !7, i64 24, !11, i64 32, !10, i64 40, !10, i64 56, !10, i64 72, !10, i64 88, !8, i64 104, !8, i64 105, !8, i64 106, !7, i64 112}
!15 = !{!14, !7, i64 16}


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