; LLVM IR from Angold-4/chainsaw :: src/debug/editor.ll (ZN6Editor7ReadKeyEi)

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

; 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: mustprogress uwtable
declare dso_local void @_ZN6Editor4ExitEi(ptr noundef nonnull align 8 dereferenceable(448), i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6Editor7ReadKeyEi(ptr noundef nonnull align 8 dereferenceable(448) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca [3 x i8], align 1
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 3, ptr %8) #3
  br label %11

11:                                               ; preds = %16, %2
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = call i64 @read(i32 noundef %12, ptr noundef %7, i64 noundef 1)
  %14 = trunc i64 %13 to i32
  store i32 %14, ptr %6, align 4, !tbaa !9
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %11
  br label %11, !llvm.loop !11

17:                                               ; preds = %11
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = icmp eq i32 %18, -1
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  call void @_ZN6Editor4ExitEi(ptr noundef nonnull align 8 dereferenceable(448) %10, i32 noundef 1)
  br label %21

21:                                               ; preds = %20, %17
  br label %22

22:                                               ; preds = %104, %21
  br label %23

23:                                               ; preds = %22
  %24 = load i8, ptr %7, align 1, !tbaa !13
  %25 = sext i8 %24 to i32
  switch i32 %25, label %101 [
    i32 27, label %26
  ]

26:                                               ; preds = %23
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = getelementptr inbounds [3 x i8], ptr %8, i64 0, i64 0
  %29 = call i64 @read(i32 noundef %27, ptr noundef %28, i64 noundef 1)
  %30 = icmp eq i64 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %26
  store i32 27, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %105

32:                                               ; preds = %26
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = getelementptr inbounds [3 x i8], ptr %8, i64 0, i64 0
  %35 = getelementptr inbounds i8, ptr %34, i64 1
  %36 = call i64 @read(i32 noundef %33, ptr noundef %35, i64 noundef 1)
  %37 = icmp eq i64 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %32
  store i32 27, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %105

39:                                               ; preds = %32
  %40 = getelementptr inbounds [3 x i8], ptr %8, i64 0, i64 0
  %41 = load i8, ptr %40, align 1, !tbaa !13
  %42 = sext i8 %41 to i32
  %43 = icmp eq i32 %42, 91
  br i1 %43, label %44, label %87

44:                                               ; preds = %39
  %45 = getelementptr inbounds [3 x i8], ptr %8, i64 0, i64 1
  %46 = load i8, ptr %45, align 1, !tbaa !13
  %47 = sext i8 %46 to i32
  %48 = icmp sge i32 %47, 48
  br i1 %48, label %49, label %75

49:                                               ; preds = %44
  %50 = getelementptr inbounds [3 x i8], ptr %8, i64 0, i64 1
  %51 = load i8, ptr %50, align 1, !tbaa !13
  %52 = sext i8 %51 to i32
  %53 = icmp sle i32 %52, 57
  br i1 %53, label %54, label %75

54:                                               ; preds = %49
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = getelementptr inbounds [3 x i8], ptr %8, i64 0, i64 0
  %57 = getelementptr inbounds i8, ptr %56, i64 2
  %58 = call i64 @read(i32 noundef %55, ptr noundef %57, i64 noundef 1)
  %59 = icmp eq i64 %58, 0
  br i1 %59, label %60, label %61

60:                                               ; preds = %54
  store i32 27, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %105

61:                                               ; preds = %54
  %62 = getelementptr inbounds [3 x i8], ptr %8, i64 0, i64 2
  %63 = load i8, ptr %62, align 1, !tbaa !13
  %64 = sext i8 %63 to i32
  %65 = icmp eq i32 %64, 126
  br i1 %65, label %66, label %74

66:                                               ; preds = %61
  %67 = getelementptr inbounds [3 x i8], ptr %8, i64 0, i64 1
  %68 = load i8, ptr %67, align 1, !tbaa !13
  %69 = sext i8 %68 to i32
  switch i32 %69, label %73 [
    i32 51, label %70
    i32 53, label %71
    i32 54, label %72
  ]

70:                                               ; preds = %66
  store i32 1004, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %105

71:                                               ; preds = %66
  store i32 1007, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %105

72:                                               ; preds = %66
  store i32 1008, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %105

73:                                               ; preds = %66
  br label %74

74:                                               ; preds = %73, %61
  br label %86

75:                                               ; preds = %49, %44
  %76 = getelementptr inbounds [3 x i8], ptr %8, i64 0, i64 1
  %77 = load i8, ptr %76, align 1, !tbaa !13
  %78 = sext i8 %77 to i32
  switch i32 %78, label %85 [
    i32 65, label %79
    i32 66, label %80
    i32 67, label %81
    i32 68, label %82
    i32 72, label %83
    i32 70, label %84
  ]

79:                                               ; preds = %75
  store i32 1002, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %105

80:                                               ; preds = %75
  store i32 1003, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %105

81:                                               ; preds = %75
  store i32 1001, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %105

82:                                               ; preds = %75
  store i32 1000, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %105

83:                                               ; preds = %75
  store i32 1005, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %105

84:                                               ; preds = %75
  store i32 1006, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %105

85:                                               ; preds = %75
  br label %86

86:                                               ; preds = %85, %74
  br label %100

87:                                               ; preds = %39
  %88 = getelementptr inbounds [3 x i8], ptr %8, i64 0, i64 0
  %89 = load i8, ptr %88, align 1, !tbaa !13
  %90 = sext i8 %89 to i32
  %91 = icmp eq i32 %90, 79
  br i1 %91, label %92, label %99

92:                                               ; preds = %87
  %93 = getelementptr inbounds [3 x i8], ptr %8, i64 0, i64 1
  %94 = load i8, ptr %93, align 1, !tbaa !13
  %95 = sext i8 %94 to i32
  switch i32 %95, label %98 [
    i32 72, label %96
    i32 70, label %97
  ]

96:                                               ; preds = %92
  store i32 1005, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %105

97:                                               ; preds = %92
  store i32 1006, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %105

98:                                               ; preds = %92
  br label %99

99:                                               ; preds = %98, %87
  br label %100

100:                                              ; preds = %99, %86
  br label %104

101:                                              ; preds = %23
  %102 = load i8, ptr %7, align 1, !tbaa !13
  %103 = sext i8 %102 to i32
  store i32 %103, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %105

104:                                              ; preds = %100
  br label %22, !llvm.loop !14

105:                                              ; preds = %101, %97, %96, %84, %83, %82, %81, %80, %79, %72, %71, %70, %60, %38, %31
  call void @llvm.lifetime.end.p0(i64 3, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %106 = load i32, ptr %3, align 4
  ret i32 %106
}

declare i64 @read(i32 noundef, ptr noundef, i64 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !12}


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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Editor4ExitEi(ptr noundef nonnull align 8 dereferenceable(448), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 -128, 1009) i32 @_ZN6Editor7ReadKeyEi(ptr noundef nonnull align 8 dereferenceable(448) %0, i32 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = alloca i8, align 1
  %4 = alloca [3 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 3, ptr nonnull %4) #3
  br label %5

5:                                                ; preds = %5, %2
  %6 = call i64 @read(i32 noundef %1, ptr noundef nonnull %3, i64 noundef 1)
  %7 = trunc i64 %6 to i32
  switch i32 %7, label %.loopexit12 [
    i32 0, label %5
    i32 -1, label %8
  ]

8:                                                ; preds = %5
  tail call void @_ZN6Editor4ExitEi(ptr noundef nonnull align 8 dereferenceable(448) %0, i32 noundef 1)
  br label %.loopexit12

.loopexit12:                                      ; preds = %5, %8
  %9 = load i8, ptr %3, align 1, !tbaa !5
  %cond = icmp eq i8 %9, 27
  br i1 %cond, label %.lr.ph, label %35

.lr.ph:                                           ; preds = %.loopexit12
  %10 = getelementptr inbounds i8, ptr %4, i64 1
  %11 = getelementptr inbounds i8, ptr %4, i64 2
  %12 = call i64 @read(i32 noundef %1, ptr noundef nonnull %4, i64 noundef 1)
  %13 = icmp eq i64 %12, 0
  br i1 %13, label %.split33.us, label %.lr.ph36

.lr.ph36:                                         ; preds = %.lr.ph, %32
  %14 = call i64 @read(i32 noundef %1, ptr noundef nonnull %10, i64 noundef 1)
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %.split33.us.loopexit50, label %16

16:                                               ; preds = %.lr.ph36
  %17 = load i8, ptr %4, align 1, !tbaa !5
  switch i8 %17, label %32 [
    i8 91, label %20
    i8 79, label %18
  ]

18:                                               ; preds = %16
  %19 = load i8, ptr %10, align 1, !tbaa !5
  switch i8 %19, label %32 [
    i8 72, label %.split33.us.loopexit50
    i8 70, label %.split33.us.loopexit52
  ]

20:                                               ; preds = %16
  %21 = load i8, ptr %10, align 1
  %22 = add i8 %21, -48
  %or.cond.us = icmp ult i8 %22, 10
  br i1 %or.cond.us, label %24, label %23

23:                                               ; preds = %20
  switch i8 %21, label %32 [
    i8 65, label %.loopexit
    i8 66, label %.split33.us.loopexit
    i8 67, label %.split33.us.loopexit48
    i8 68, label %.split33.us.loopexit50
    i8 72, label %.split33.us.loopexit52
    i8 70, label %.split33.us
  ]

24:                                               ; preds = %20
  %25 = call i64 @read(i32 noundef %1, ptr noundef nonnull %11, i64 noundef 1)
  %26 = icmp eq i64 %25, 0
  br i1 %26, label %.split33.us.loopexit50, label %27

27:                                               ; preds = %24
  %28 = load i8, ptr %11, align 1, !tbaa !5
  %29 = icmp eq i8 %28, 126
  br i1 %29, label %30, label %32

30:                                               ; preds = %27
  %31 = load i8, ptr %10, align 1, !tbaa !5
  switch i8 %31, label %32 [
    i8 51, label %.split33.us.loopexit50
    i8 53, label %.split33.us.loopexit52
    i8 54, label %.split33.us
  ]

32:                                               ; preds = %30, %27, %23, %18, %16
  %33 = call i64 @read(i32 noundef %1, ptr noundef nonnull %4, i64 noundef 1)
  %34 = icmp eq i64 %33, 0
  br i1 %34, label %.split33.us.loopexit50, label %.lr.ph36

35:                                               ; preds = %.loopexit12
  %36 = sext i8 %9 to i32
  br label %.split33.us

.loopexit:                                        ; preds = %23
  br label %.split33.us

.split33.us.loopexit:                             ; preds = %23
  br label %.split33.us

.split33.us.loopexit48:                           ; preds = %23
  br label %.split33.us

.split33.us.loopexit50:                           ; preds = %23, %30, %24, %18, %.lr.ph36, %32
  %.0.ph51 = phi i32 [ 27, %32 ], [ 27, %.lr.ph36 ], [ 1005, %18 ], [ 27, %24 ], [ 1004, %30 ], [ 1000, %23 ]
  br label %.split33.us

.split33.us.loopexit52:                           ; preds = %23, %30, %18
  %.0.ph = phi i32 [ 1007, %30 ], [ 1006, %18 ], [ 1005, %23 ]
  br label %.split33.us

.split33.us:                                      ; preds = %30, %23, %.split33.us.loopexit52, %.split33.us.loopexit50, %.lr.ph, %.split33.us.loopexit48, %.split33.us.loopexit, %.loopexit, %35
  %.0 = phi i32 [ %36, %35 ], [ 27, %.lr.ph ], [ 1002, %.loopexit ], [ %.0.ph51, %.split33.us.loopexit50 ], [ 1003, %.split33.us.loopexit ], [ %.0.ph, %.split33.us.loopexit52 ], [ 1006, %23 ], [ 1008, %30 ], [ 1001, %.split33.us.loopexit48 ]
  call void @llvm.lifetime.end.p0(i64 3, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #3
  ret i32 %.0
}

; Function Attrs: nofree
declare noundef i64 @read(i32 noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nofree "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass