; LLVM IR from Nykakin/chompjs :: _chompjs (parser)

; 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.State = type { ptr }
%struct.Lexer = type { ptr, i64, %struct.CharBuffer, i64, i32, ptr, %struct.CharBuffer, i64, i8 }
%struct.CharBuffer = type { ptr, i64, i64 }

@states = external dso_local global [5 x %struct.State], align 16
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @next_char(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @emit(i8 noundef signext, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @emit_string_in_place(ptr noundef, i64 noundef, 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: 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 ptr @handle_quoted(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = call signext i8 @next_char(ptr noundef %8)
  store i8 %9, ptr %4, align 1, !tbaa !9
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  call void @emit(i8 noundef signext 34, ptr noundef %10)
  br label %11

11:                                               ; preds = %76, %74, %1
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.Lexer, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !10
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.Lexer, ptr %15, i32 0, i32 3
  %17 = load i64, ptr %16, align 8, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %14, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !9
  store i8 %19, ptr %5, align 1, !tbaa !9
  %20 = load i8, ptr %5, align 1, !tbaa !9
  %21 = sext i8 %20 to i32
  %22 = icmp eq i32 %21, 92
  br i1 %22, label %23, label %47

23:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #2
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Lexer, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !10
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.Lexer, ptr %27, i32 0, i32 3
  %29 = load i64, ptr %28, align 8, !tbaa !16
  %30 = add i64 %29, 1
  %31 = getelementptr inbounds i8, ptr %26, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !9
  store i8 %32, ptr %6, align 1, !tbaa !9
  %33 = load i8, ptr %6, align 1, !tbaa !9
  %34 = sext i8 %33 to i32
  %35 = icmp eq i32 %34, 39
  br i1 %35, label %36, label %42

36:                                               ; preds = %23
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  call void @emit(i8 noundef signext 39, ptr noundef %37)
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.Lexer, ptr %38, i32 0, i32 3
  %40 = load i64, ptr %39, align 8, !tbaa !16
  %41 = add i64 %40, 1
  store i64 %41, ptr %39, align 8, !tbaa !16
  br label %46

42:                                               ; preds = %23
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  call void @emit(i8 noundef signext 92, ptr noundef %43)
  %44 = load i8, ptr %6, align 1, !tbaa !9
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  call void @emit(i8 noundef signext %44, ptr noundef %45)
  br label %46

46:                                               ; preds = %42, %36
  store i32 3, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  br label %74

47:                                               ; preds = %11
  %48 = load i8, ptr %5, align 1, !tbaa !9
  %49 = sext i8 %48 to i32
  %50 = icmp eq i32 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %47
  store ptr getelementptr inbounds ([5 x %struct.State], ptr @states, i64 0, i64 4), ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %74

52:                                               ; preds = %47
  %53 = load i8, ptr %5, align 1, !tbaa !9
  %54 = sext i8 %53 to i32
  %55 = load i8, ptr %4, align 1, !tbaa !9
  %56 = sext i8 %55 to i32
  %57 = icmp eq i32 %54, %56
  br i1 %57, label %58, label %60

58:                                               ; preds = %52
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  call void @emit(i8 noundef signext 34, ptr noundef %59)
  store ptr getelementptr inbounds ([5 x %struct.State], ptr @states, i64 0, i64 1), ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %74

60:                                               ; preds = %52
  %61 = load i8, ptr %5, align 1, !tbaa !9
  %62 = sext i8 %61 to i32
  %63 = icmp eq i32 %62, 34
  br i1 %63, label %64, label %70

64:                                               ; preds = %60
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  call void @emit_string_in_place(ptr noundef @.str.4, i64 noundef 2, ptr noundef %65)
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.Lexer, ptr %66, i32 0, i32 3
  %68 = load i64, ptr %67, align 8, !tbaa !16
  %69 = add i64 %68, 1
  store i64 %69, ptr %67, align 8, !tbaa !16
  br label %73

70:                                               ; preds = %60
  %71 = load i8, ptr %5, align 1, !tbaa !9
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  call void @emit(i8 noundef signext %71, ptr noundef %72)
  br label %73

73:                                               ; preds = %70, %64
  store i32 0, ptr %7, align 4
  br label %74

74:                                               ; preds = %73, %58, %51, %46
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #2
  %75 = load i32, ptr %7, align 4
  switch i32 %75, label %77 [
    i32 0, label %76
    i32 3, label %11
  ]

76:                                               ; preds = %74
  br label %11

77:                                               ; preds = %74
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  %78 = load ptr, ptr %2, align 8
  ret ptr %78
}

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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 0}
!11 = !{!"Lexer", !6, i64 0, !12, i64 8, !13, i64 16, !12, i64 40, !14, i64 48, !6, i64 56, !13, i64 64, !12, i64 88, !15, i64 96}
!12 = !{!"long", !7, i64 0}
!13 = !{!"CharBuffer", !6, i64 0, !12, i64 8, !12, i64 16}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!11, !12, i64 40}


; 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.State = type { ptr }

@states = external dso_local global [5 x %struct.State], align 16
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local void @emit(i8 noundef signext, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @emit_string_in_place(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local nonnull ptr @handle_quoted(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call signext i8 @next_char(ptr noundef %0)
  tail call void @emit(i8 noundef signext 34, ptr noundef %0)
  %3 = getelementptr inbounds i8, ptr %0, i64 40
  br label %4

4:                                                ; preds = %.backedge, %1
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = load i64, ptr %3, align 8, !tbaa !14
  %7 = getelementptr inbounds i8, ptr %5, i64 %6
  %8 = load i8, ptr %7, align 1, !tbaa !15
  switch i8 %8, label %17 [
    i8 92, label %9
    i8 0, label %.loopexit
  ]

9:                                                ; preds = %4
  %10 = getelementptr i8, ptr %7, i64 1
  %11 = load i8, ptr %10, align 1, !tbaa !15
  %12 = icmp eq i8 %11, 39
  br i1 %12, label %13, label %16

13:                                               ; preds = %9
  tail call void @emit(i8 noundef signext 39, ptr noundef nonnull %0)
  %14 = load i64, ptr %3, align 8, !tbaa !14
  %15 = add i64 %14, 1
  store i64 %15, ptr %3, align 8, !tbaa !14
  br label %.backedge

16:                                               ; preds = %9
  tail call void @emit(i8 noundef signext 92, ptr noundef nonnull %0)
  tail call void @emit(i8 noundef signext %11, ptr noundef nonnull %0)
  br label %.backedge

17:                                               ; preds = %4
  %18 = icmp eq i8 %8, %2
  br i1 %18, label %19, label %20

19:                                               ; preds = %17
  tail call void @emit(i8 noundef signext 34, ptr noundef nonnull %0)
  br label %.loopexit

20:                                               ; preds = %17
  %21 = icmp eq i8 %8, 34
  br i1 %21, label %22, label %25

22:                                               ; preds = %20
  tail call void @emit_string_in_place(ptr noundef nonnull @.str.4, i64 noundef 2, ptr noundef nonnull %0)
  %23 = load i64, ptr %3, align 8, !tbaa !14
  %24 = add i64 %23, 1
  store i64 %24, ptr %3, align 8, !tbaa !14
  br label %.backedge

.backedge:                                        ; preds = %22, %25, %13, %16
  br label %4

25:                                               ; preds = %20
  tail call void @emit(i8 noundef signext %8, ptr noundef nonnull %0)
  br label %.backedge

.loopexit:                                        ; preds = %4, %19
  %.1.ph = phi ptr [ getelementptr inbounds (i8, ptr @states, i64 8), %19 ], [ getelementptr inbounds (i8, ptr @states, i64 32), %4 ]
  ret ptr %.1.ph
}

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

!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 = !{!"Lexer", !7, i64 0, !10, i64 8, !11, i64 16, !10, i64 40, !12, i64 48, !7, i64 56, !11, i64 64, !10, i64 88, !13, i64 96}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"CharBuffer", !7, i64 0, !10, i64 8, !10, i64 16}
!12 = !{!"int", !8, i64 0}
!13 = !{!"_Bool", !8, i64 0}
!14 = !{!6, !10, i64 40}
!15 = !{!8, !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass