; LLVM IR from krig/LISP :: komplott (read_token)

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

@token_peek = external dso_local global i32, align 4
@token_text = external dso_local global [256 x i8], align 16

; 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
declare dso_local ptr @intern_string(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @read_token(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %4

4:                                                ; preds = %14, %1
  %5 = call ptr @__ctype_b_loc() #6
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = load i32, ptr @token_peek, align 4, !tbaa !9
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds i16, ptr %6, i64 %8
  %10 = load i16, ptr %9, align 2, !tbaa !11
  %11 = zext i16 %10 to i32
  %12 = and i32 %11, 8192
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %17

14:                                               ; preds = %4
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = call i32 @fgetc(ptr noundef %15)
  store i32 %16, ptr @token_peek, align 4, !tbaa !9
  br label %4, !llvm.loop !13

17:                                               ; preds = %4
  %18 = load i32, ptr @token_peek, align 4, !tbaa !9
  %19 = icmp eq i32 %18, 40
  br i1 %19, label %23, label %20

20:                                               ; preds = %17
  %21 = load i32, ptr @token_peek, align 4, !tbaa !9
  %22 = icmp eq i32 %21, 41
  br i1 %22, label %23, label %32

23:                                               ; preds = %20, %17
  %24 = load i32, ptr @token_peek, align 4, !tbaa !9
  %25 = trunc i32 %24 to i8
  %26 = load i32, ptr %3, align 4, !tbaa !9
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %3, align 4, !tbaa !9
  %28 = sext i32 %26 to i64
  %29 = getelementptr inbounds [256 x i8], ptr @token_text, i64 0, i64 %28
  store i8 %25, ptr %29, align 1, !tbaa !15
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = call i32 @fgetc(ptr noundef %30)
  store i32 %31, ptr @token_peek, align 4, !tbaa !9
  br label %63

32:                                               ; preds = %20
  br label %33

33:                                               ; preds = %53, %32
  %34 = load i32, ptr @token_peek, align 4, !tbaa !9
  %35 = icmp sge i32 %34, 33
  br i1 %35, label %36, label %39

36:                                               ; preds = %33
  %37 = load i32, ptr @token_peek, align 4, !tbaa !9
  %38 = icmp sle i32 %37, 39
  br i1 %38, label %47, label %39

39:                                               ; preds = %36, %33
  %40 = load i32, ptr @token_peek, align 4, !tbaa !9
  %41 = icmp sge i32 %40, 42
  br i1 %41, label %42, label %45

42:                                               ; preds = %39
  %43 = load i32, ptr @token_peek, align 4, !tbaa !9
  %44 = icmp sle i32 %43, 126
  br label %45

45:                                               ; preds = %42, %39
  %46 = phi i1 [ false, %39 ], [ %44, %42 ]
  br label %47

47:                                               ; preds = %45, %36
  %48 = phi i1 [ true, %36 ], [ %46, %45 ]
  br i1 %48, label %49, label %62

49:                                               ; preds = %47
  %50 = load i32, ptr %3, align 4, !tbaa !9
  %51 = icmp eq i32 %50, 256
  br i1 %51, label %52, label %53

52:                                               ; preds = %49
  call void @abort() #7
  unreachable

53:                                               ; preds = %49
  %54 = load i32, ptr @token_peek, align 4, !tbaa !9
  %55 = trunc i32 %54 to i8
  %56 = load i32, ptr %3, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %3, align 4, !tbaa !9
  %58 = sext i32 %56 to i64
  %59 = getelementptr inbounds [256 x i8], ptr @token_text, i64 0, i64 %58
  store i8 %55, ptr %59, align 1, !tbaa !15
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = call i32 @fgetc(ptr noundef %60)
  store i32 %61, ptr @token_peek, align 4, !tbaa !9
  br label %33, !llvm.loop !16

62:                                               ; preds = %47
  br label %63

63:                                               ; preds = %62, %23
  %64 = load i32, ptr @token_peek, align 4, !tbaa !9
  %65 = icmp eq i32 %64, -1
  br i1 %65, label %66, label %67

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

67:                                               ; preds = %63
  %68 = load i32, ptr %3, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [256 x i8], ptr @token_text, i64 0, i64 %69
  store i8 0, ptr %70, align 1, !tbaa !15
  %71 = call ptr @intern_string(ptr noundef @token_text)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret ptr %71
}

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() #2

declare i32 @fgetc(ptr noundef) #3

; Function Attrs: noreturn nounwind
declare void @abort() #4

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

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 willreturn memory(none) "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 = { "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 = { 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(none) }
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)"}
!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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !14}


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

@token_peek = external dso_local local_unnamed_addr global i32, align 4
@token_text = external dso_local global [256 x i8], align 16

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

; Function Attrs: nounwind uwtable
define dso_local ptr @read_token(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr @__ctype_b_loc() #4
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = load i32, ptr @token_peek, align 4
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds i16, ptr %3, i64 %5
  %7 = load i16, ptr %6, align 2, !tbaa !9
  %8 = and i16 %7, 8192
  %.not12 = icmp eq i16 %8, 0
  br i1 %.not12, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %9 = tail call i32 @fgetc(ptr noundef %0)
  store i32 %9, ptr @token_peek, align 4, !tbaa !11
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = sext i32 %9 to i64
  %12 = getelementptr inbounds i16, ptr %10, i64 %11
  %13 = load i16, ptr %12, align 2, !tbaa !9
  %14 = and i16 %13, 8192
  %.not = icmp eq i16 %14, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %1
  %15 = phi i32 [ %4, %1 ], [ %9, %.lr.ph ]
  %16 = and i32 %15, -2
  %or.cond = icmp eq i32 %16, 40
  br i1 %or.cond, label %20, label %.preheader

.preheader:                                       ; preds = %._crit_edge
  %17 = add i32 %15, -33
  %or.cond313 = icmp ult i32 %17, 7
  %18 = add i32 %15, -42
  %19 = icmp ult i32 %18, 85
  %or.cond1014 = or i1 %or.cond313, %19
  br i1 %or.cond1014, label %.critedge, label %thread-pre-split

20:                                               ; preds = %._crit_edge
  %21 = trunc nuw i32 %15 to i8
  store i8 %21, ptr @token_text, align 16, !tbaa !15
  %22 = tail call i32 @fgetc(ptr noundef %0)
  store i32 %22, ptr @token_peek, align 4, !tbaa !11
  br label %thread-pre-split

.critedge:                                        ; preds = %.preheader, %26
  %indvars.iv = phi i64 [ %indvars.iv.next, %26 ], [ 0, %.preheader ]
  %23 = phi i32 [ %29, %26 ], [ %15, %.preheader ]
  %24 = icmp eq i64 %indvars.iv, 256
  br i1 %24, label %25, label %26

25:                                               ; preds = %.critedge
  tail call void @abort() #5
  unreachable

26:                                               ; preds = %.critedge
  %27 = trunc nuw i32 %23 to i8
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %28 = getelementptr inbounds [256 x i8], ptr @token_text, i64 0, i64 %indvars.iv
  store i8 %27, ptr %28, align 1, !tbaa !15
  %29 = tail call i32 @fgetc(ptr noundef %0)
  store i32 %29, ptr @token_peek, align 4, !tbaa !11
  %30 = add i32 %29, -33
  %or.cond3 = icmp ult i32 %30, 7
  %31 = add i32 %29, -42
  %32 = icmp ult i32 %31, 85
  %or.cond10 = or i1 %or.cond3, %32
  br i1 %or.cond10, label %.critedge, label %thread-pre-split.loopexit, !llvm.loop !16

thread-pre-split.loopexit:                        ; preds = %26
  %33 = and i64 %indvars.iv.next, 4294967295
  br label %thread-pre-split

thread-pre-split:                                 ; preds = %.preheader, %thread-pre-split.loopexit, %20
  %34 = phi i32 [ %22, %20 ], [ %15, %.preheader ], [ %29, %thread-pre-split.loopexit ]
  %.1 = phi i64 [ 1, %20 ], [ 0, %.preheader ], [ %33, %thread-pre-split.loopexit ]
  %35 = icmp eq i32 %34, -1
  br i1 %35, label %36, label %37

36:                                               ; preds = %thread-pre-split
  tail call void @exit(i32 noundef 0) #5
  unreachable

37:                                               ; preds = %thread-pre-split
  %38 = getelementptr inbounds [256 x i8], ptr @token_text, i64 0, i64 %.1
  store i8 0, ptr %38, align 1, !tbaa !15
  %39 = tail call ptr @intern_string(ptr noundef nonnull @token_text)
  ret ptr %39
}

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fgetc(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #3

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

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 nofree nosync nounwind willreturn memory(none) "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 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 #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 willreturn memory(none) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !14}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass