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

; 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_INPUT_KEY = type { i16, i16 }

@FileBuffer = external dso_local global %struct.EFI_EDITOR_FILE_BUFFER, align 8
@.str.24 = external hidden unnamed_addr constant [16 x i32], align 4
@.str.25 = external hidden unnamed_addr constant [35 x i32], align 4

; 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

declare i64 @StatusBarSetStatusString(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @FileBufferScrollLeft() #2

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @FileBufferDoDelete() #2

; Function Attrs: nounwind uwtable
declare dso_local i64 @FileBufferScrollRight() #2

; Function Attrs: nounwind uwtable
declare dso_local i64 @FileBufferDoCharInput(i16 noundef zeroext) #2

; Function Attrs: nounwind uwtable
declare dso_local i64 @FileBufferScrollDown() #2

; Function Attrs: nounwind uwtable
declare dso_local i64 @FileBufferScrollUp() #2

; Function Attrs: nounwind uwtable
declare dso_local i64 @FileBufferPageDown() #2

; Function Attrs: nounwind uwtable
declare dso_local i64 @FileBufferPageUp() #2

; Function Attrs: nounwind uwtable
declare dso_local i64 @FileBufferEnd() #2

; Function Attrs: nounwind uwtable
define dso_local i64 @FileBufferHandleInput(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 0, ptr %3, align 8, !tbaa !9
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.EFI_INPUT_KEY, ptr %4, i32 0, i32 0
  %6 = load i16, ptr %5, align 2, !tbaa !11
  %7 = zext i16 %6 to i32
  switch i32 %7, label %49 [
    i32 0, label %8
    i32 1, label %19
    i32 2, label %21
    i32 3, label %23
    i32 4, label %25
    i32 9, label %27
    i32 10, label %29
    i32 8, label %31
    i32 5, label %39
    i32 6, label %41
    i32 7, label %43
  ]

8:                                                ; preds = %1
  %9 = load i8, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 11), align 2, !tbaa !14
  %10 = icmp ne i8 %9, 0
  br i1 %10, label %16, label %11

11:                                               ; preds = %8
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.EFI_INPUT_KEY, ptr %12, i32 0, i32 1
  %14 = load i16, ptr %13, align 2, !tbaa !18
  %15 = call i64 @FileBufferDoCharInput(i16 noundef zeroext %14)
  store i64 %15, ptr %3, align 8, !tbaa !9
  br label %18

16:                                               ; preds = %8
  %17 = call i64 @StatusBarSetStatusString(ptr noundef @.str.25)
  store i64 %17, ptr %3, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %16, %11
  br label %51

19:                                               ; preds = %1
  %20 = call i64 @FileBufferScrollUp()
  store i64 %20, ptr %3, align 8, !tbaa !9
  br label %51

21:                                               ; preds = %1
  %22 = call i64 @FileBufferScrollDown()
  store i64 %22, ptr %3, align 8, !tbaa !9
  br label %51

23:                                               ; preds = %1
  %24 = call i64 @FileBufferScrollRight()
  store i64 %24, ptr %3, align 8, !tbaa !9
  br label %51

25:                                               ; preds = %1
  %26 = call i64 @FileBufferScrollLeft()
  store i64 %26, ptr %3, align 8, !tbaa !9
  br label %51

27:                                               ; preds = %1
  %28 = call i64 @FileBufferPageUp()
  store i64 %28, ptr %3, align 8, !tbaa !9
  br label %51

29:                                               ; preds = %1
  %30 = call i64 @FileBufferPageDown()
  store i64 %30, ptr %3, align 8, !tbaa !9
  br label %51

31:                                               ; preds = %1
  %32 = load i8, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 11), align 2, !tbaa !14
  %33 = icmp ne i8 %32, 0
  br i1 %33, label %36, label %34

34:                                               ; preds = %31
  %35 = call i64 @FileBufferDoDelete()
  store i64 %35, ptr %3, align 8, !tbaa !9
  br label %38

36:                                               ; preds = %31
  %37 = call i64 @StatusBarSetStatusString(ptr noundef @.str.25)
  store i64 %37, ptr %3, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %36, %34
  br label %51

39:                                               ; preds = %1
  %40 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 6), align 8, !tbaa !19
  call void @FileBufferMovePosition(i64 noundef %40, i64 noundef 1)
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %51

41:                                               ; preds = %1
  %42 = call i64 @FileBufferEnd()
  store i64 %42, ptr %3, align 8, !tbaa !9
  br label %51

43:                                               ; preds = %1
  %44 = load i8, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 10), align 1, !tbaa !20
  %45 = icmp ne i8 %44, 0
  %46 = xor i1 %45, true
  %47 = zext i1 %46 to i32
  %48 = trunc i32 %47 to i8
  store i8 %48, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 10), align 1, !tbaa !20
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %51

49:                                               ; preds = %1
  %50 = call i64 @StatusBarSetStatusString(ptr noundef @.str.24)
  store i64 %50, ptr %3, align 8, !tbaa !9
  br label %51

51:                                               ; preds = %49, %43, %41, %39, %38, %29, %27, %25, %23, %21, %19, %18
  %52 = load i64, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i64 %52
}

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


; 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.24 = external hidden unnamed_addr constant [16 x i32], align 4
@.str.25 = external hidden unnamed_addr constant [35 x i32], align 4

declare i64 @StatusBarSetStatusString(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @FileBufferScrollLeft() local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @FileBufferDoDelete() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @FileBufferScrollRight() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @FileBufferDoCharInput(i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @FileBufferScrollDown() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @FileBufferScrollUp() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @FileBufferPageDown() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @FileBufferPageUp() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @FileBufferEnd() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @FileBufferHandleInput(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = load i16, ptr %0, align 2, !tbaa !5
  switch i16 %2, label %36 [
    i16 0, label %3
    i16 1, label %11
    i16 2, label %13
    i16 3, label %15
    i16 4, label %17
    i16 9, label %19
    i16 10, label %21
    i16 8, label %23
    i16 5, label %29
    i16 6, label %31
    i16 7, label %33
  ]

3:                                                ; preds = %1
  %4 = load i8, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 106), align 2, !tbaa !10
  %.not3 = icmp eq i8 %4, 0
  br i1 %.not3, label %5, label %9

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 2
  %7 = load i16, ptr %6, align 2, !tbaa !16
  %8 = tail call i64 @FileBufferDoCharInput(i16 noundef zeroext %7)
  br label %38

9:                                                ; preds = %3
  %10 = tail call i64 @StatusBarSetStatusString(ptr noundef nonnull @.str.25) #2
  br label %38

11:                                               ; preds = %1
  %12 = tail call i64 @FileBufferScrollUp()
  br label %38

13:                                               ; preds = %1
  %14 = tail call i64 @FileBufferScrollDown()
  br label %38

15:                                               ; preds = %1
  %16 = tail call i64 @FileBufferScrollRight()
  br label %38

17:                                               ; preds = %1
  %18 = tail call i64 @FileBufferScrollLeft()
  br label %38

19:                                               ; preds = %1
  %20 = tail call i64 @FileBufferPageUp()
  br label %38

21:                                               ; preds = %1
  %22 = tail call i64 @FileBufferPageDown()
  br label %38

23:                                               ; preds = %1
  %24 = load i8, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 106), align 2, !tbaa !10
  %.not2 = icmp eq i8 %24, 0
  br i1 %.not2, label %25, label %27

25:                                               ; preds = %23
  %26 = tail call i64 @FileBufferDoDelete()
  br label %38

27:                                               ; preds = %23
  %28 = tail call i64 @StatusBarSetStatusString(ptr noundef nonnull @.str.25) #2
  br label %38

29:                                               ; preds = %1
  %30 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 56), align 8, !tbaa !17
  tail call void @FileBufferMovePosition(i64 noundef %30, i64 noundef 1)
  br label %38

31:                                               ; preds = %1
  %32 = tail call i64 @FileBufferEnd()
  br label %38

33:                                               ; preds = %1
  %34 = load i8, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 105), align 1, !tbaa !18
  %.not = icmp eq i8 %34, 0
  %35 = zext i1 %.not to i8
  store i8 %35, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 105), align 1, !tbaa !18
  br label %38

36:                                               ; preds = %1
  %37 = tail call i64 @StatusBarSetStatusString(ptr noundef nonnull @.str.24) #2
  br label %38

38:                                               ; preds = %25, %27, %5, %9, %36, %33, %31, %29, %21, %19, %17, %15, %13, %11
  %.0 = phi i64 [ %37, %36 ], [ 0, %33 ], [ %32, %31 ], [ 0, %29 ], [ %28, %27 ], [ %26, %25 ], [ %22, %21 ], [ %20, %19 ], [ %18, %17 ], [ %16, %15 ], [ %14, %13 ], [ %12, %11 ], [ %10, %9 ], [ %8, %5 ]
  ret i64 %.0
}

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


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