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

; 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: 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
define dso_local void @GetNewLine(i32 noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  store i8 0, ptr %7, align 1, !tbaa !11
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = icmp ne i32 %9, 1
  br i1 %10, label %11, label %22

11:                                               ; preds = %3
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = icmp ne i32 %12, 2
  br i1 %13, label %14, label %22

14:                                               ; preds = %11
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = icmp ne i32 %15, 3
  br i1 %16, label %17, label %22

17:                                               ; preds = %14
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = icmp ne i32 %18, 4
  br i1 %19, label %20, label %22

20:                                               ; preds = %17
  %21 = load ptr, ptr %6, align 8, !tbaa !9
  store i8 0, ptr %21, align 1, !tbaa !11
  store i32 1, ptr %8, align 4
  br label %111

22:                                               ; preds = %17, %14, %11, %3
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = icmp eq i32 %23, 2
  br i1 %24, label %25, label %41

25:                                               ; preds = %22
  %26 = load ptr, ptr @MainEditor, align 8, !tbaa !12
  %27 = getelementptr inbounds %struct.EFI_EDITOR_FILE_BUFFER, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 8, !tbaa !16
  %29 = icmp eq i32 %28, 2
  br i1 %29, label %30, label %35

30:                                               ; preds = %25
  %31 = load ptr, ptr %5, align 8, !tbaa !9
  %32 = getelementptr inbounds i8, ptr %31, i64 0
  store i8 13, ptr %32, align 1, !tbaa !11
  %33 = load ptr, ptr %5, align 8, !tbaa !9
  %34 = getelementptr inbounds i8, ptr %33, i64 1
  store i8 0, ptr %34, align 1, !tbaa !11
  store i8 2, ptr %7, align 1, !tbaa !11
  br label %38

35:                                               ; preds = %25
  %36 = load ptr, ptr %5, align 8, !tbaa !9
  %37 = getelementptr inbounds i8, ptr %36, i64 0
  store i8 13, ptr %37, align 1, !tbaa !11
  store i8 1, ptr %7, align 1, !tbaa !11
  br label %38

38:                                               ; preds = %35, %30
  %39 = load i8, ptr %7, align 1, !tbaa !11
  %40 = load ptr, ptr %6, align 8, !tbaa !9
  store i8 %39, ptr %40, align 1, !tbaa !11
  store i32 1, ptr %8, align 4
  br label %111

41:                                               ; preds = %22
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = icmp eq i32 %42, 1
  br i1 %43, label %44, label %60

44:                                               ; preds = %41
  %45 = load ptr, ptr @MainEditor, align 8, !tbaa !12
  %46 = getelementptr inbounds %struct.EFI_EDITOR_FILE_BUFFER, ptr %45, i32 0, i32 1
  %47 = load i32, ptr %46, align 8, !tbaa !16
  %48 = icmp eq i32 %47, 2
  br i1 %48, label %49, label %54

49:                                               ; preds = %44
  %50 = load ptr, ptr %5, align 8, !tbaa !9
  %51 = getelementptr inbounds i8, ptr %50, i64 0
  store i8 10, ptr %51, align 1, !tbaa !11
  %52 = load ptr, ptr %5, align 8, !tbaa !9
  %53 = getelementptr inbounds i8, ptr %52, i64 1
  store i8 0, ptr %53, align 1, !tbaa !11
  store i8 2, ptr %7, align 1, !tbaa !11
  br label %57

54:                                               ; preds = %44
  %55 = load ptr, ptr %5, align 8, !tbaa !9
  %56 = getelementptr inbounds i8, ptr %55, i64 0
  store i8 10, ptr %56, align 1, !tbaa !11
  store i8 1, ptr %7, align 1, !tbaa !11
  br label %57

57:                                               ; preds = %54, %49
  %58 = load i8, ptr %7, align 1, !tbaa !11
  %59 = load ptr, ptr %6, align 8, !tbaa !9
  store i8 %58, ptr %59, align 1, !tbaa !11
  store i32 1, ptr %8, align 4
  br label %111

60:                                               ; preds = %41
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = icmp eq i32 %61, 3
  br i1 %62, label %63, label %85

63:                                               ; preds = %60
  %64 = load ptr, ptr @MainEditor, align 8, !tbaa !12
  %65 = getelementptr inbounds %struct.EFI_EDITOR_FILE_BUFFER, ptr %64, i32 0, i32 1
  %66 = load i32, ptr %65, align 8, !tbaa !16
  %67 = icmp eq i32 %66, 2
  br i1 %67, label %68, label %77

68:                                               ; preds = %63
  %69 = load ptr, ptr %5, align 8, !tbaa !9
  %70 = getelementptr inbounds i8, ptr %69, i64 0
  store i8 13, ptr %70, align 1, !tbaa !11
  %71 = load ptr, ptr %5, align 8, !tbaa !9
  %72 = getelementptr inbounds i8, ptr %71, i64 1
  store i8 0, ptr %72, align 1, !tbaa !11
  %73 = load ptr, ptr %5, align 8, !tbaa !9
  %74 = getelementptr inbounds i8, ptr %73, i64 2
  store i8 10, ptr %74, align 1, !tbaa !11
  %75 = load ptr, ptr %5, align 8, !tbaa !9
  %76 = getelementptr inbounds i8, ptr %75, i64 3
  store i8 0, ptr %76, align 1, !tbaa !11
  store i8 4, ptr %7, align 1, !tbaa !11
  br label %82

77:                                               ; preds = %63
  %78 = load ptr, ptr %5, align 8, !tbaa !9
  %79 = getelementptr inbounds i8, ptr %78, i64 0
  store i8 13, ptr %79, align 1, !tbaa !11
  %80 = load ptr, ptr %5, align 8, !tbaa !9
  %81 = getelementptr inbounds i8, ptr %80, i64 1
  store i8 10, ptr %81, align 1, !tbaa !11
  store i8 2, ptr %7, align 1, !tbaa !11
  br label %82

82:                                               ; preds = %77, %68
  %83 = load i8, ptr %7, align 1, !tbaa !11
  %84 = load ptr, ptr %6, align 8, !tbaa !9
  store i8 %83, ptr %84, align 1, !tbaa !11
  store i32 1, ptr %8, align 4
  br label %111

85:                                               ; preds = %60
  %86 = load i32, ptr %4, align 4, !tbaa !5
  %87 = icmp eq i32 %86, 4
  br i1 %87, label %88, label %110

88:                                               ; preds = %85
  %89 = load ptr, ptr @MainEditor, align 8, !tbaa !12
  %90 = getelementptr inbounds %struct.EFI_EDITOR_FILE_BUFFER, ptr %89, i32 0, i32 1
  %91 = load i32, ptr %90, align 8, !tbaa !16
  %92 = icmp eq i32 %91, 2
  br i1 %92, label %93, label %102

93:                                               ; preds = %88
  %94 = load ptr, ptr %5, align 8, !tbaa !9
  %95 = getelementptr inbounds i8, ptr %94, i64 0
  store i8 10, ptr %95, align 1, !tbaa !11
  %96 = load ptr, ptr %5, align 8, !tbaa !9
  %97 = getelementptr inbounds i8, ptr %96, i64 1
  store i8 0, ptr %97, align 1, !tbaa !11
  %98 = load ptr, ptr %5, align 8, !tbaa !9
  %99 = getelementptr inbounds i8, ptr %98, i64 2
  store i8 13, ptr %99, align 1, !tbaa !11
  %100 = load ptr, ptr %5, align 8, !tbaa !9
  %101 = getelementptr inbounds i8, ptr %100, i64 3
  store i8 0, ptr %101, align 1, !tbaa !11
  store i8 4, ptr %7, align 1, !tbaa !11
  br label %107

102:                                              ; preds = %88
  %103 = load ptr, ptr %5, align 8, !tbaa !9
  %104 = getelementptr inbounds i8, ptr %103, i64 0
  store i8 10, ptr %104, align 1, !tbaa !11
  %105 = load ptr, ptr %5, align 8, !tbaa !9
  %106 = getelementptr inbounds i8, ptr %105, i64 1
  store i8 13, ptr %106, align 1, !tbaa !11
  store i8 2, ptr %7, align 1, !tbaa !11
  br label %107

107:                                              ; preds = %102, %93
  %108 = load i8, ptr %7, align 1, !tbaa !11
  %109 = load ptr, ptr %6, align 8, !tbaa !9
  store i8 %108, ptr %109, align 1, !tbaa !11
  store i32 1, ptr %8, align 4
  br label %111

110:                                              ; preds = %85
  store i32 0, ptr %8, align 4
  br label %111

111:                                              ; preds = %110, %107, %82, %57, %38, %20
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  %112 = load i32, ptr %8, align 4
  switch i32 %112, label %114 [
    i32 0, label %113
    i32 1, label %113
  ]

113:                                              ; preds = %111, %111
  ret void

114:                                              ; preds = %111
  unreachable
}

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


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @GetNewLine(i32 noundef %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = add i32 %0, -5
  %or.cond5 = icmp ult i32 %4, -4
  br i1 %or.cond5, label %30, label %5

5:                                                ; preds = %3
  %6 = load ptr, ptr @MainEditor, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  %8 = load i32, ptr %7, align 8, !tbaa !13
  %9 = icmp eq i32 %8, 2
  switch i32 %0, label %default.unreachable [
    i32 2, label %10
    i32 1, label %14
    i32 3, label %18
    i32 4, label %24
  ]

10:                                               ; preds = %5
  br i1 %9, label %11, label %13

11:                                               ; preds = %10
  %12 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 0, ptr %12, align 1, !tbaa !15
  br label %13

13:                                               ; preds = %10, %11
  %.0 = phi i8 [ 2, %11 ], [ 1, %10 ]
  store i8 13, ptr %1, align 1
  br label %30

14:                                               ; preds = %5
  br i1 %9, label %15, label %17

15:                                               ; preds = %14
  %16 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 0, ptr %16, align 1, !tbaa !15
  br label %17

17:                                               ; preds = %14, %15
  %.1 = phi i8 [ 2, %15 ], [ 1, %14 ]
  store i8 10, ptr %1, align 1
  br label %30

18:                                               ; preds = %5
  br i1 %9, label %19, label %22

19:                                               ; preds = %18
  %20 = getelementptr inbounds i8, ptr %1, i64 2
  store i8 10, ptr %20, align 1, !tbaa !15
  %21 = getelementptr inbounds i8, ptr %1, i64 3
  store i8 0, ptr %21, align 1, !tbaa !15
  br label %22

22:                                               ; preds = %18, %19
  %.sink = phi i8 [ 0, %19 ], [ 10, %18 ]
  %.2 = phi i8 [ 4, %19 ], [ 2, %18 ]
  store i8 13, ptr %1, align 1
  %23 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 %.sink, ptr %23, align 1
  br label %30

24:                                               ; preds = %5
  br i1 %9, label %25, label %28

25:                                               ; preds = %24
  %26 = getelementptr inbounds i8, ptr %1, i64 2
  store i8 13, ptr %26, align 1, !tbaa !15
  %27 = getelementptr inbounds i8, ptr %1, i64 3
  store i8 0, ptr %27, align 1, !tbaa !15
  br label %28

28:                                               ; preds = %24, %25
  %.sink40 = phi i8 [ 0, %25 ], [ 13, %24 ]
  %.3 = phi i8 [ 4, %25 ], [ 2, %24 ]
  store i8 10, ptr %1, align 1
  %29 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 %.sink40, ptr %29, align 1
  br label %30

default.unreachable:                              ; preds = %5
  unreachable

30:                                               ; preds = %3, %28, %22, %17, %13
  %.3.sink = phi i8 [ %.3, %28 ], [ %.2, %22 ], [ %.1, %17 ], [ %.0, %13 ], [ 0, %3 ]
  store i8 %.3.sink, ptr %2, align 1, !tbaa !15
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) 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, !12, i64 8}
!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 = !{!8, !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass