; LLVM IR from Simple-XX/SimpleKernel :: src/drv/keyboard/keyboard.ll (ZN8KEYBOARD4readEv)

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

%class.KEYBOARD = type { i8, i8, i8, i8, i8 }

@.str = external hidden unnamed_addr constant [17 x i8], align 1
@_ZN8KEYBOARD6keymapE = external dso_local constant <{ [251 x i8], [133 x i8] }>, align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i8 @_ZN8KEYBOARD4readEv(ptr noundef nonnull align 1 dereferenceable(5) %0) #0 align 2 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  %8 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN2IO12get_instanceEv()
  %9 = call noundef zeroext i8 @_ZN2IO3inbEj(i32 noundef 96)
  store i8 %9, ptr %4, align 1, !tbaa !9
  %10 = load i8, ptr %4, align 1, !tbaa !9
  %11 = icmp ne i8 %10, 0
  br i1 %11, label %14, label %12

12:                                               ; preds = %1
  %13 = call i32 (ptr, ...) @warn(ptr noundef @.str)
  store i8 0, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %84

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  store i8 0, ptr %6, align 1, !tbaa !9
  %15 = load i8, ptr %4, align 1, !tbaa !9
  %16 = zext i8 %15 to i32
  switch i32 %16, label %59 [
    i32 42, label %17
    i32 170, label %19
    i32 54, label %21
    i32 182, label %23
    i32 29, label %25
    i32 157, label %27
    i32 56, label %29
    i32 184, label %31
    i32 58, label %33
    i32 69, label %43
    i32 14, label %53
    i32 28, label %55
    i32 15, label %57
  ]

17:                                               ; preds = %14
  %18 = getelementptr inbounds %class.KEYBOARD, ptr %7, i32 0, i32 0
  store i8 1, ptr %18, align 1, !tbaa !10
  br label %82

19:                                               ; preds = %14
  %20 = getelementptr inbounds %class.KEYBOARD, ptr %7, i32 0, i32 0
  store i8 0, ptr %20, align 1, !tbaa !10
  br label %82

21:                                               ; preds = %14
  %22 = getelementptr inbounds %class.KEYBOARD, ptr %7, i32 0, i32 0
  store i8 1, ptr %22, align 1, !tbaa !10
  br label %82

23:                                               ; preds = %14
  %24 = getelementptr inbounds %class.KEYBOARD, ptr %7, i32 0, i32 0
  store i8 0, ptr %24, align 1, !tbaa !10
  br label %82

25:                                               ; preds = %14
  %26 = getelementptr inbounds %class.KEYBOARD, ptr %7, i32 0, i32 2
  store i8 1, ptr %26, align 1, !tbaa !13
  br label %82

27:                                               ; preds = %14
  %28 = getelementptr inbounds %class.KEYBOARD, ptr %7, i32 0, i32 2
  store i8 0, ptr %28, align 1, !tbaa !13
  br label %82

29:                                               ; preds = %14
  %30 = getelementptr inbounds %class.KEYBOARD, ptr %7, i32 0, i32 4
  store i8 1, ptr %30, align 1, !tbaa !14
  br label %82

31:                                               ; preds = %14
  %32 = getelementptr inbounds %class.KEYBOARD, ptr %7, i32 0, i32 4
  store i8 0, ptr %32, align 1, !tbaa !14
  br label %82

33:                                               ; preds = %14
  %34 = getelementptr inbounds %class.KEYBOARD, ptr %7, i32 0, i32 1
  %35 = load i8, ptr %34, align 1, !tbaa !15, !range !16, !noundef !17
  %36 = trunc i8 %35 to i1
  %37 = xor i1 %36, true
  %38 = zext i1 %37 to i32
  %39 = and i32 %38, 1
  %40 = icmp ne i32 %39, 0
  %41 = getelementptr inbounds %class.KEYBOARD, ptr %7, i32 0, i32 1
  %42 = zext i1 %40 to i8
  store i8 %42, ptr %41, align 1, !tbaa !15
  br label %82

43:                                               ; preds = %14
  %44 = getelementptr inbounds %class.KEYBOARD, ptr %7, i32 0, i32 3
  %45 = load i8, ptr %44, align 1, !tbaa !18, !range !16, !noundef !17
  %46 = trunc i8 %45 to i1
  %47 = xor i1 %46, true
  %48 = zext i1 %47 to i32
  %49 = and i32 %48, 1
  %50 = icmp ne i32 %49, 0
  %51 = getelementptr inbounds %class.KEYBOARD, ptr %7, i32 0, i32 3
  %52 = zext i1 %50 to i8
  store i8 %52, ptr %51, align 1, !tbaa !18
  br label %82

53:                                               ; preds = %14
  %54 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN2IO12get_instanceEv()
  call void @_ZN2IO8put_charEc(ptr noundef nonnull align 8 dereferenceable(8) %54, i8 noundef signext 8)
  store i8 8, ptr %6, align 1, !tbaa !9
  br label %82

55:                                               ; preds = %14
  %56 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN2IO12get_instanceEv()
  call void @_ZN2IO8put_charEc(ptr noundef nonnull align 8 dereferenceable(8) %56, i8 noundef signext 10)
  store i8 10, ptr %6, align 1, !tbaa !9
  br label %82

57:                                               ; preds = %14
  %58 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN2IO12get_instanceEv()
  call void @_ZN2IO8put_charEc(ptr noundef nonnull align 8 dereferenceable(8) %58, i8 noundef signext 9)
  store i8 9, ptr %6, align 1, !tbaa !9
  br label %82

59:                                               ; preds = %14
  %60 = load i8, ptr %4, align 1, !tbaa !9
  %61 = zext i8 %60 to i32
  %62 = and i32 %61, 128
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %81, label %64

64:                                               ; preds = %59
  %65 = load i8, ptr %4, align 1, !tbaa !9
  %66 = zext i8 %65 to i32
  %67 = mul nsw i32 %66, 3
  %68 = trunc i32 %67 to i8
  %69 = zext i8 %68 to i32
  %70 = getelementptr inbounds %class.KEYBOARD, ptr %7, i32 0, i32 0
  %71 = load i8, ptr %70, align 1, !tbaa !10, !range !16, !noundef !17
  %72 = trunc i8 %71 to i1
  %73 = zext i1 %72 to i8
  %74 = zext i8 %73 to i32
  %75 = add nsw i32 %69, %74
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [384 x i8], ptr @_ZN8KEYBOARD6keymapE, i64 0, i64 %76
  %78 = load i8, ptr %77, align 1, !tbaa !9
  store i8 %78, ptr %6, align 1, !tbaa !9
  %79 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN2IO12get_instanceEv()
  %80 = load i8, ptr %6, align 1, !tbaa !9
  call void @_ZN2IO8put_charEc(ptr noundef nonnull align 8 dereferenceable(8) %79, i8 noundef signext %80)
  br label %82

81:                                               ; preds = %59
  br label %82

82:                                               ; preds = %81, %64, %57, %55, %53, %43, %33, %31, %29, %27, %25, %23, %21, %19, %17
  %83 = load i8, ptr %6, align 1, !tbaa !9
  store i8 %83, ptr %2, align 1
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  br label %84

84:                                               ; preds = %82, %12
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  %85 = load i8, ptr %2, align 1
  ret i8 %85
}

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

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZN2IO12get_instanceEv() #2

declare noundef zeroext i8 @_ZN2IO3inbEj(i32 noundef) #2

declare i32 @warn(ptr noundef, ...) #2

declare void @_ZN2IO8put_charEc(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef signext) #2

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

attributes #0 = { mustprogress 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 = { "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++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"_ZTS8KEYBOARD", !12, i64 0, !12, i64 1, !12, i64 2, !12, i64 3, !12, i64 4}
!12 = !{!"bool", !7, i64 0}
!13 = !{!11, !12, i64 2}
!14 = !{!11, !12, i64 4}
!15 = !{!11, !12, i64 1}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!11, !12, i64 3}


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

@.str = external hidden unnamed_addr constant [17 x i8], align 1
@_ZN8KEYBOARD6keymapE = external dso_local local_unnamed_addr constant <{ [251 x i8], [133 x i8] }>, align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i8 @_ZN8KEYBOARD4readEv(ptr nocapture noundef nonnull align 1 dereferenceable(5) %0) local_unnamed_addr #0 align 2 {
  %2 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN2IO12get_instanceEv()
  %3 = tail call noundef zeroext i8 @_ZN2IO3inbEj(i32 noundef 96)
  switch i8 %3, label %32 [
    i8 0, label %4
    i8 42, label %6
    i8 -86, label %7
    i8 54, label %8
    i8 -74, label %9
    i8 29, label %10
    i8 -99, label %12
    i8 56, label %14
    i8 -72, label %16
    i8 58, label %18
    i8 69, label %22
    i8 14, label %26
    i8 28, label %28
    i8 15, label %30
  ]

4:                                                ; preds = %1
  %5 = tail call i32 (ptr, ...) @warn(ptr noundef nonnull @.str)
  br label %42

6:                                                ; preds = %1
  store i8 1, ptr %0, align 1, !tbaa !5
  br label %42

7:                                                ; preds = %1
  store i8 0, ptr %0, align 1, !tbaa !5
  br label %42

8:                                                ; preds = %1
  store i8 1, ptr %0, align 1, !tbaa !5
  br label %42

9:                                                ; preds = %1
  store i8 0, ptr %0, align 1, !tbaa !5
  br label %42

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

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

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

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

18:                                               ; preds = %1
  %19 = getelementptr inbounds i8, ptr %0, i64 1
  %20 = load i8, ptr %19, align 1, !tbaa !12, !range !13, !noundef !14
  %21 = xor i8 %20, 1
  store i8 %21, ptr %19, align 1, !tbaa !12
  br label %42

22:                                               ; preds = %1
  %23 = getelementptr inbounds i8, ptr %0, i64 3
  %24 = load i8, ptr %23, align 1, !tbaa !15, !range !13, !noundef !14
  %25 = xor i8 %24, 1
  store i8 %25, ptr %23, align 1, !tbaa !15
  br label %42

26:                                               ; preds = %1
  %27 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN2IO12get_instanceEv()
  tail call void @_ZN2IO8put_charEc(ptr noundef nonnull align 8 dereferenceable(8) %27, i8 noundef signext 8)
  br label %42

28:                                               ; preds = %1
  %29 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN2IO12get_instanceEv()
  tail call void @_ZN2IO8put_charEc(ptr noundef nonnull align 8 dereferenceable(8) %29, i8 noundef signext 10)
  br label %42

30:                                               ; preds = %1
  %31 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN2IO12get_instanceEv()
  tail call void @_ZN2IO8put_charEc(ptr noundef nonnull align 8 dereferenceable(8) %31, i8 noundef signext 9)
  br label %42

32:                                               ; preds = %1
  %.not9 = icmp sgt i8 %3, -1
  br i1 %.not9, label %33, label %42

33:                                               ; preds = %32
  %34 = mul i8 %3, 3
  %35 = zext i8 %34 to i64
  %36 = load i8, ptr %0, align 1, !tbaa !5, !range !13, !noundef !14
  %37 = zext nneg i8 %36 to i64
  %38 = add nuw nsw i64 %37, %35
  %39 = getelementptr inbounds [384 x i8], ptr @_ZN8KEYBOARD6keymapE, i64 0, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !16
  %41 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN2IO12get_instanceEv()
  tail call void @_ZN2IO8put_charEc(ptr noundef nonnull align 8 dereferenceable(8) %41, i8 noundef signext %40)
  br label %42

42:                                               ; preds = %6, %7, %8, %9, %10, %12, %14, %16, %18, %22, %26, %28, %30, %33, %32, %4
  %.07 = phi i8 [ 0, %4 ], [ 0, %32 ], [ %40, %33 ], [ 9, %30 ], [ 10, %28 ], [ 8, %26 ], [ 0, %22 ], [ 0, %18 ], [ 0, %16 ], [ 0, %14 ], [ 0, %12 ], [ 0, %10 ], [ 0, %9 ], [ 0, %8 ], [ 0, %7 ], [ 0, %6 ]
  ret i8 %.07
}

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZN2IO12get_instanceEv() local_unnamed_addr #1

declare noundef zeroext i8 @_ZN2IO3inbEj(i32 noundef) local_unnamed_addr #1

declare i32 @warn(ptr noundef, ...) local_unnamed_addr #1

declare void @_ZN2IO8put_charEc(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef signext) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { "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 = !{!"_ZTS8KEYBOARD", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 2}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !7, i64 1}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!6, !7, i64 3}
!16 = !{!8, !8, i64 0}


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