; LLVM IR from mist64/perfect6502 :: cbmbasic (plugin)

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

@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @compare(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: nounwind uwtable
declare hidden void @set_chrptr(i16 noundef zeroext) #0

; 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
define dso_local zeroext i16 @plugin_gone() #0 {
  %1 = alloca i16, align 2
  %2 = alloca i16, align 2
  %3 = alloca i8, align 1
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i16, align 2
  %7 = alloca i8, align 1
  %8 = alloca [256 x i8], align 16
  %9 = call zeroext i16 @get_chrptr()
  %10 = zext i16 %9 to i32
  %11 = add nsw i32 %10, 1
  %12 = trunc i32 %11 to i16
  call void @set_chrptr(i16 noundef zeroext %12)
  br label %13

13:                                               ; preds = %73, %0
  call void @llvm.lifetime.start.p0(i64 2, ptr %2) #4
  %14 = call zeroext i16 @get_chrptr()
  %15 = zext i16 %14 to i32
  %16 = sub nsw i32 %15, 1
  %17 = trunc i32 %16 to i16
  call void @set_chrptr(i16 noundef zeroext %17)
  %18 = call zeroext i16 @get_chrptr()
  store i16 %18, ptr %2, align 2, !tbaa !5
  %19 = call i32 @compare(ptr noundef @.str)
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %47

21:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #4
  %22 = call zeroext i8 @get_byte()
  store i8 %22, ptr %4, align 1, !tbaa !9
  call void @check_comma()
  %23 = call zeroext i8 @get_byte()
  store i8 %23, ptr %3, align 1, !tbaa !9
  %24 = load i8, ptr %3, align 1, !tbaa !9
  %25 = zext i8 %24 to i32
  %26 = icmp sgt i32 %25, 80
  br i1 %26, label %39, label %27

27:                                               ; preds = %21
  %28 = load i8, ptr %4, align 1, !tbaa !9
  %29 = zext i8 %28 to i32
  %30 = icmp sgt i32 %29, 25
  br i1 %30, label %39, label %31

31:                                               ; preds = %27
  %32 = load i8, ptr %3, align 1, !tbaa !9
  %33 = zext i8 %32 to i32
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %39, label %35

35:                                               ; preds = %31
  %36 = load i8, ptr %4, align 1, !tbaa !9
  %37 = zext i8 %36 to i32
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %41

39:                                               ; preds = %35, %31, %27, %21
  %40 = call zeroext i16 @error(i8 noundef zeroext 14)
  store i16 %40, ptr %1, align 2
  store i32 1, ptr %5, align 4
  br label %46

41:                                               ; preds = %35
  %42 = load i8, ptr %3, align 1, !tbaa !9
  %43 = zext i8 %42 to i32
  %44 = load i8, ptr %4, align 1, !tbaa !9
  %45 = zext i8 %44 to i32
  call void @move_cursor(i32 noundef %43, i32 noundef %45)
  store i32 3, ptr %5, align 4
  br label %46

46:                                               ; preds = %41, %39
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #4
  br label %73

47:                                               ; preds = %13
  %48 = call i32 @compare(ptr noundef @.str.1)
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %61

50:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #4
  %51 = call zeroext i16 @get_word()
  store i16 %51, ptr %6, align 2, !tbaa !5
  call void @check_comma()
  %52 = call zeroext i8 @get_byte()
  store i8 %52, ptr %7, align 1, !tbaa !9
  %53 = load i16, ptr %6, align 2, !tbaa !5
  %54 = zext i16 %53 to i32
  %55 = icmp eq i32 %54, 6502
  br i1 %55, label %56, label %58

56:                                               ; preds = %50
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  store i32 3, ptr %5, align 4
  br label %60

58:                                               ; preds = %50
  %59 = load i16, ptr %2, align 2, !tbaa !5
  call void @set_chrptr(i16 noundef zeroext %59)
  store i16 0, ptr %1, align 2
  store i32 1, ptr %5, align 4
  br label %60

60:                                               ; preds = %58, %56
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #4
  br label %73

61:                                               ; preds = %47
  %62 = call i32 @compare(ptr noundef @.str.3)
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %64, label %68

64:                                               ; preds = %61
  call void @llvm.lifetime.start.p0(i64 256, ptr %8) #4
  %65 = getelementptr inbounds [256 x i8], ptr %8, i64 0, i64 0
  call void @get_string(ptr noundef %65)
  %66 = getelementptr inbounds [256 x i8], ptr %8, i64 0, i64 0
  %67 = call i32 @system(ptr noundef %66)
  store i32 3, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 256, ptr %8) #4
  br label %73

68:                                               ; preds = %61
  %69 = call i32 @compare(ptr noundef @.str.4)
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %71, label %72

71:                                               ; preds = %68
  call void @exit(i32 noundef 0) #5
  unreachable

72:                                               ; preds = %68
  store i32 2, ptr %5, align 4
  br label %73

73:                                               ; preds = %72, %64, %60, %46
  call void @llvm.lifetime.end.p0(i64 2, ptr %2) #4
  %74 = load i32, ptr %5, align 4
  switch i32 %74, label %78 [
    i32 1, label %76
    i32 3, label %13
    i32 2, label %75
  ]

75:                                               ; preds = %73
  store i16 0, ptr %1, align 2
  br label %76

76:                                               ; preds = %75, %73
  %77 = load i16, ptr %1, align 2
  ret i16 %77

78:                                               ; preds = %73
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i16 @error(i8 noundef zeroext) #0

declare void @move_cursor(i32 noundef, i32 noundef) #2

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

; Function Attrs: nounwind uwtable
declare hidden void @get_string(ptr noundef) #0

declare i32 @system(ptr noundef) #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #3

; Function Attrs: nounwind uwtable
declare hidden zeroext i16 @get_chrptr() #0

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @get_byte() #0

; Function Attrs: nounwind uwtable
declare hidden void @check_comma() #0

; Function Attrs: nounwind uwtable
declare hidden zeroext i16 @get_word() #0

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 = { "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 = { noreturn nounwind "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 #4 = { nounwind }
attributes #5 = { noreturn 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, 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"

@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @compare(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare hidden void @set_chrptr(i16 noundef zeroext) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i16 @plugin_gone() local_unnamed_addr #0 {
  %1 = alloca [256 x i8], align 16
  %2 = tail call zeroext i16 @get_chrptr()
  %3 = add i16 %2, 1
  tail call void @set_chrptr(i16 noundef zeroext %3)
  br label %4

4:                                                ; preds = %.backedge, %0
  %5 = call zeroext i16 @get_chrptr()
  %6 = add i16 %5, -1
  call void @set_chrptr(i16 noundef zeroext %6)
  %7 = call zeroext i16 @get_chrptr()
  %8 = call i32 @compare(ptr noundef nonnull @.str)
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %21, label %9

9:                                                ; preds = %4
  %10 = call zeroext i8 @get_byte()
  call void @check_comma()
  %11 = call zeroext i8 @get_byte()
  %12 = add i8 %11, -81
  %13 = icmp ult i8 %12, -80
  %14 = add i8 %10, -26
  %15 = icmp ult i8 %14, -25
  %or.cond8 = select i1 %13, i1 true, i1 %15
  br i1 %or.cond8, label %16, label %18

16:                                               ; preds = %9
  %17 = call zeroext i16 @error(i8 noundef zeroext 14)
  br label %.thread

18:                                               ; preds = %9
  %19 = zext nneg i8 %10 to i32
  %20 = zext nneg i8 %11 to i32
  call void @move_cursor(i32 noundef %20, i32 noundef %19) #6
  br label %.backedge

21:                                               ; preds = %4
  %22 = call i32 @compare(ptr noundef nonnull @.str.1)
  %.not23 = icmp eq i32 %22, 0
  br i1 %.not23, label %30, label %23

23:                                               ; preds = %21
  %24 = call zeroext i16 @get_word()
  call void @check_comma()
  %25 = call zeroext i8 @get_byte()
  %26 = icmp eq i16 %24, 6502
  br i1 %26, label %27, label %29

27:                                               ; preds = %23
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %.backedge

.backedge:                                        ; preds = %27, %18, %32
  br label %4

29:                                               ; preds = %23
  call void @set_chrptr(i16 noundef zeroext %7)
  br label %.thread

30:                                               ; preds = %21
  %31 = call i32 @compare(ptr noundef nonnull @.str.3)
  %.not24 = icmp eq i32 %31, 0
  br i1 %.not24, label %34, label %32

32:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %1) #6
  call void @get_string(ptr noundef nonnull %1)
  %33 = call i32 @system(ptr noundef nonnull %1) #6
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %1) #6
  br label %.backedge

34:                                               ; preds = %30
  %35 = call i32 @compare(ptr noundef nonnull @.str.4)
  %.not25 = icmp eq i32 %35, 0
  br i1 %.not25, label %.thread, label %36

36:                                               ; preds = %34
  call void @exit(i32 noundef 0) #7
  unreachable

.thread:                                          ; preds = %29, %16, %34
  %.4 = phi i16 [ 0, %34 ], [ 0, %29 ], [ %17, %16 ]
  ret i16 %.4
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i16 @error(i8 noundef zeroext) local_unnamed_addr #0

declare void @move_cursor(i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden void @get_string(ptr noundef) local_unnamed_addr #0

; Function Attrs: nofree
declare noundef i32 @system(ptr nocapture noundef readonly) local_unnamed_addr #4

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
declare hidden zeroext i16 @get_chrptr() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @get_byte() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @check_comma() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden zeroext i16 @get_word() local_unnamed_addr #0

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 = { mustprogress 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 = { nofree nounwind "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 #4 = { 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 #5 = { noreturn nounwind "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 #6 = { nounwind }
attributes #7 = { noreturn 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)"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass