; 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

; Function Attrs: nounwind uwtable
define dso_local ptr @json(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %106, %1
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = call signext i8 @next_char(ptr noundef %6)
  %8 = sext i8 %7 to i32
  switch i32 %8, label %105 [
    i32 123, label %9
    i32 91, label %15
    i32 125, label %19
    i32 93, label %44
    i32 58, label %69
    i32 44, label %73
    i32 47, label %83
    i32 62, label %104
    i32 41, label %104
  ]

9:                                                ; preds = %5
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.Lexer, ptr %10, i32 0, i32 6
  call void @push(ptr noundef %11, i8 noundef signext 123)
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.Lexer, ptr %12, i32 0, i32 8
  store i8 1, ptr %13, align 8, !tbaa !9
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  call void @emit(i8 noundef signext 123, ptr noundef %14)
  br label %106

15:                                               ; preds = %5
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.Lexer, ptr %16, i32 0, i32 6
  call void @push(ptr noundef %17, i8 noundef signext 91)
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  call void @emit(i8 noundef signext 91, ptr noundef %18)
  br label %106

19:                                               ; preds = %5
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = call signext i8 @last_char(ptr noundef %20)
  %22 = sext i8 %21 to i32
  %23 = icmp eq i32 %22, 44
  br i1 %23, label %24, label %26

24:                                               ; preds = %19
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  call void @unemit(ptr noundef %25)
  br label %26

26:                                               ; preds = %24, %19
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.Lexer, ptr %27, i32 0, i32 6
  call void @pop(ptr noundef %28)
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.Lexer, ptr %29, i32 0, i32 6
  %31 = call signext i8 @top(ptr noundef %30)
  %32 = sext i8 %31 to i32
  %33 = icmp eq i32 %32, 123
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.Lexer, ptr %34, i32 0, i32 8
  %36 = zext i1 %33 to i8
  store i8 %36, ptr %35, align 8, !tbaa !9
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  call void @emit(i8 noundef signext 125, ptr noundef %37)
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.Lexer, ptr %38, i32 0, i32 6
  %40 = call i64 @size(ptr noundef %39)
  %41 = icmp ule i64 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %26
  store ptr getelementptr inbounds ([5 x %struct.State], ptr @states, i64 0, i64 3), ptr %2, align 8
  br label %107

43:                                               ; preds = %26
  br label %106

44:                                               ; preds = %5
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = call signext i8 @last_char(ptr noundef %45)
  %47 = sext i8 %46 to i32
  %48 = icmp eq i32 %47, 44
  br i1 %48, label %49, label %51

49:                                               ; preds = %44
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  call void @unemit(ptr noundef %50)
  br label %51

51:                                               ; preds = %49, %44
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.Lexer, ptr %52, i32 0, i32 6
  call void @pop(ptr noundef %53)
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.Lexer, ptr %54, i32 0, i32 6
  %56 = call signext i8 @top(ptr noundef %55)
  %57 = sext i8 %56 to i32
  %58 = icmp eq i32 %57, 123
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.Lexer, ptr %59, i32 0, i32 8
  %61 = zext i1 %58 to i8
  store i8 %61, ptr %60, align 8, !tbaa !9
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  call void @emit(i8 noundef signext 93, ptr noundef %62)
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.Lexer, ptr %63, i32 0, i32 6
  %65 = call i64 @size(ptr noundef %64)
  %66 = icmp ule i64 %65, 0
  br i1 %66, label %67, label %68

67:                                               ; preds = %51
  store ptr getelementptr inbounds ([5 x %struct.State], ptr @states, i64 0, i64 3), ptr %2, align 8
  br label %107

68:                                               ; preds = %51
  br label %106

69:                                               ; preds = %5
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.Lexer, ptr %70, i32 0, i32 8
  store i8 0, ptr %71, align 8, !tbaa !9
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  call void @emit(i8 noundef signext 58, ptr noundef %72)
  br label %106

73:                                               ; preds = %5
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  call void @emit(i8 noundef signext 44, ptr noundef %74)
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.Lexer, ptr %75, i32 0, i32 6
  %77 = call signext i8 @top(ptr noundef %76)
  %78 = sext i8 %77 to i32
  %79 = icmp eq i32 %78, 123
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.Lexer, ptr %80, i32 0, i32 8
  %82 = zext i1 %79 to i8
  store i8 %82, ptr %81, align 8, !tbaa !9
  br label %106

83:                                               ; preds = %5
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.Lexer, ptr %84, i32 0, i32 0
  %86 = load ptr, ptr %85, align 8, !tbaa !15
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.Lexer, ptr %87, i32 0, i32 3
  %89 = load i64, ptr %88, align 8, !tbaa !16
  %90 = add i64 %89, 1
  %91 = getelementptr inbounds i8, ptr %86, i64 %90
  %92 = load i8, ptr %91, align 1, !tbaa !17
  store i8 %92, ptr %4, align 1, !tbaa !17
  %93 = load i8, ptr %4, align 1, !tbaa !17
  %94 = sext i8 %93 to i32
  %95 = icmp eq i32 %94, 47
  br i1 %95, label %100, label %96

96:                                               ; preds = %83
  %97 = load i8, ptr %4, align 1, !tbaa !17
  %98 = sext i8 %97 to i32
  %99 = icmp eq i32 %98, 42
  br i1 %99, label %100, label %102

100:                                              ; preds = %96, %83
  %101 = load ptr, ptr %3, align 8, !tbaa !5
  call void @handle_comments(ptr noundef %101)
  br label %103

102:                                              ; preds = %96
  store ptr getelementptr inbounds ([5 x %struct.State], ptr @states, i64 0, i64 2), ptr %2, align 8
  br label %107

103:                                              ; preds = %100
  br label %106

104:                                              ; preds = %5, %5
  store ptr getelementptr inbounds ([5 x %struct.State], ptr @states, i64 0, i64 4), ptr %2, align 8
  br label %107

105:                                              ; preds = %5
  store ptr getelementptr inbounds ([5 x %struct.State], ptr @states, i64 0, i64 2), ptr %2, align 8
  br label %107

106:                                              ; preds = %103, %73, %69, %68, %43, %15, %9
  br label %5

107:                                              ; preds = %105, %104, %102, %67, %42
  %108 = load ptr, ptr %2, align 8
  ret ptr %108
}

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

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

declare signext i8 @top(ptr noundef) #1

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

declare void @push(ptr noundef, i8 noundef signext) #1

; Function Attrs: nounwind uwtable
declare dso_local void @unemit(ptr noundef) #0

declare void @pop(ptr noundef) #1

declare i64 @size(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @handle_comments(ptr noundef) #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 = { "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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !14, i64 96}
!10 = !{!"Lexer", !6, i64 0, !11, i64 8, !12, i64 16, !11, i64 40, !13, i64 48, !6, i64 56, !12, i64 64, !11, i64 88, !14, i64 96}
!11 = !{!"long", !7, i64 0}
!12 = !{!"CharBuffer", !6, i64 0, !11, i64 8, !11, i64 16}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!10, !6, i64 0}
!16 = !{!10, !11, i64 40}
!17 = !{!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"

%struct.State = type { ptr }

@states = external dso_local global [5 x %struct.State], align 16

; Function Attrs: nounwind uwtable
define dso_local nonnull ptr @json(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = getelementptr inbounds i8, ptr %0, i64 64
  %4 = getelementptr inbounds i8, ptr %0, i64 96
  br label %5

5:                                                ; preds = %.backedge, %1
  %6 = tail call signext i8 @next_char(ptr noundef %0)
  switch i8 %6, label %.loopexit [
    i8 123, label %7
    i8 91, label %8
    i8 125, label %9
    i8 93, label %19
    i8 58, label %29
    i8 44, label %30
    i8 47, label %34
    i8 62, label %.loopexit.loopexit
    i8 41, label %.loopexit.loopexit
  ]

7:                                                ; preds = %5
  tail call void @push(ptr noundef nonnull %3, i8 noundef signext 123) #2
  store i8 1, ptr %4, align 8, !tbaa !5
  tail call void @emit(i8 noundef signext 123, ptr noundef %0)
  br label %.backedge

8:                                                ; preds = %5
  tail call void @push(ptr noundef nonnull %3, i8 noundef signext 91) #2
  tail call void @emit(i8 noundef signext 91, ptr noundef %0)
  br label %.backedge

9:                                                ; preds = %5
  %10 = tail call signext i8 @last_char(ptr noundef %0)
  %11 = icmp eq i8 %10, 44
  br i1 %11, label %12, label %13

12:                                               ; preds = %9
  tail call void @unemit(ptr noundef %0)
  br label %13

13:                                               ; preds = %12, %9
  tail call void @pop(ptr noundef nonnull %3) #2
  %14 = tail call signext i8 @top(ptr noundef nonnull %3) #2
  %15 = icmp eq i8 %14, 123
  %16 = zext i1 %15 to i8
  store i8 %16, ptr %4, align 8, !tbaa !5
  tail call void @emit(i8 noundef signext 125, ptr noundef %0)
  %17 = tail call i64 @size(ptr noundef nonnull %3) #2
  %18 = icmp eq i64 %17, 0
  br i1 %18, label %.loopexit, label %.backedge

19:                                               ; preds = %5
  %20 = tail call signext i8 @last_char(ptr noundef %0)
  %21 = icmp eq i8 %20, 44
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  tail call void @unemit(ptr noundef %0)
  br label %23

23:                                               ; preds = %22, %19
  tail call void @pop(ptr noundef nonnull %3) #2
  %24 = tail call signext i8 @top(ptr noundef nonnull %3) #2
  %25 = icmp eq i8 %24, 123
  %26 = zext i1 %25 to i8
  store i8 %26, ptr %4, align 8, !tbaa !5
  tail call void @emit(i8 noundef signext 93, ptr noundef %0)
  %27 = tail call i64 @size(ptr noundef nonnull %3) #2
  %28 = icmp eq i64 %27, 0
  br i1 %28, label %.loopexit, label %.backedge

.backedge:                                        ; preds = %23, %13, %40, %30, %29, %8, %7
  br label %5

29:                                               ; preds = %5
  store i8 0, ptr %4, align 8, !tbaa !5
  tail call void @emit(i8 noundef signext 58, ptr noundef %0)
  br label %.backedge

30:                                               ; preds = %5
  tail call void @emit(i8 noundef signext 44, ptr noundef %0)
  %31 = tail call signext i8 @top(ptr noundef nonnull %3) #2
  %32 = icmp eq i8 %31, 123
  %33 = zext i1 %32 to i8
  store i8 %33, ptr %4, align 8, !tbaa !5
  br label %.backedge

34:                                               ; preds = %5
  %35 = load ptr, ptr %0, align 8, !tbaa !14
  %36 = load i64, ptr %2, align 8, !tbaa !15
  %37 = getelementptr i8, ptr %35, i64 %36
  %38 = getelementptr i8, ptr %37, i64 1
  %39 = load i8, ptr %38, align 1, !tbaa !16
  switch i8 %39, label %.loopexit [
    i8 47, label %40
    i8 42, label %40
  ]

40:                                               ; preds = %34, %34
  tail call void @handle_comments(ptr noundef nonnull %0)
  br label %.backedge

.loopexit.loopexit:                               ; preds = %5, %5
  br label %.loopexit

.loopexit:                                        ; preds = %34, %23, %13, %5, %.loopexit.loopexit
  %.0 = phi ptr [ getelementptr inbounds (i8, ptr @states, i64 16), %5 ], [ getelementptr inbounds (i8, ptr @states, i64 16), %34 ], [ getelementptr inbounds (i8, ptr @states, i64 24), %23 ], [ getelementptr inbounds (i8, ptr @states, i64 24), %13 ], [ getelementptr inbounds (i8, ptr @states, i64 32), %.loopexit.loopexit ]
  ret ptr %.0
}

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

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

declare signext i8 @top(ptr noundef) local_unnamed_addr #1

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

declare void @push(ptr noundef, i8 noundef signext) local_unnamed_addr #1

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

declare void @pop(ptr noundef) local_unnamed_addr #1

declare i64 @size(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @handle_comments(ptr noundef) 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 = { "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 }

!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, !13, i64 96}
!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, !7, i64 0}
!15 = !{!6, !10, i64 40}
!16 = !{!8, !8, i64 0}


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