; 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 @begin(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  br label %4

4:                                                ; preds = %18, %1
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = call signext i8 @next_char(ptr noundef %5)
  %7 = sext i8 %6 to i32
  switch i32 %7, label %13 [
    i32 123, label %8
    i32 91, label %11
    i32 0, label %12
  ]

8:                                                ; preds = %4
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.Lexer, ptr %9, i32 0, i32 8
  store i8 1, ptr %10, align 8, !tbaa !9
  br label %11

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

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

13:                                               ; preds = %4
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.Lexer, ptr %14, i32 0, i32 3
  %16 = load i64, ptr %15, align 8, !tbaa !15
  %17 = add i64 %16, 1
  store i64 %17, ptr %15, align 8, !tbaa !15
  br label %18

18:                                               ; preds = %13
  br label %4

19:                                               ; preds = %12, %11
  %20 = load ptr, ptr %2, align 8
  ret ptr %20
}

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @next_char(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" }

!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, !11, 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

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

3:                                                ; preds = %7, %1
  %4 = tail call signext i8 @next_char(ptr noundef %0)
  switch i8 %4, label %7 [
    i8 123, label %5
    i8 91, label %.loopexit.loopexit
    i8 0, label %.loopexit
  ]

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 96
  store i8 1, ptr %6, align 8, !tbaa !5
  br label %.loopexit

7:                                                ; preds = %3
  %8 = load i64, ptr %2, align 8, !tbaa !14
  %9 = add i64 %8, 1
  store i64 %9, ptr %2, align 8, !tbaa !14
  br label %3

.loopexit.loopexit:                               ; preds = %3
  br label %.loopexit

.loopexit:                                        ; preds = %3, %.loopexit.loopexit, %5
  %.0 = phi ptr [ getelementptr inbounds (i8, ptr @states, i64 8), %5 ], [ getelementptr inbounds (i8, ptr @states, i64 8), %.loopexit.loopexit ], [ getelementptr inbounds (i8, ptr @states, i64 24), %3 ]
  ret ptr %.0
}

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @next_char(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" }

!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, !10, i64 40}


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