; LLVM IR from EarlGray/language-incubator :: llvm/kldscp (ast)

; 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.parser = type { i32, i32, ptr }

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @parse_toplevel(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.parser, ptr %4, i32 0, i32 0
  %6 = load i32, ptr %5, align 8, !tbaa !9
  switch i32 %6, label %23 [
    i32 65535, label %7
    i32 -1, label %11
    i32 -3, label %12
    i32 -2, label %15
    i32 -12, label %18
    i32 59, label %21
  ]

7:                                                ; preds = %1
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  call void @next_token(ptr noundef %8)
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call ptr @parse_toplevel(ptr noundef %9)
  store ptr %10, ptr %2, align 8
  br label %26

11:                                               ; preds = %1
  store ptr null, ptr %2, align 8
  br label %26

12:                                               ; preds = %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = call ptr @parse_extern(ptr noundef %13)
  store ptr %14, ptr %2, align 8
  br label %26

15:                                               ; preds = %1
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = call ptr @parse_def(ptr noundef %16)
  store ptr %17, ptr %2, align 8
  br label %26

18:                                               ; preds = %1
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = call ptr @parse_import(ptr noundef %19)
  store ptr %20, ptr %2, align 8
  br label %26

21:                                               ; preds = %1
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  call void @next_token(ptr noundef %22)
  store ptr null, ptr %2, align 8
  br label %26

23:                                               ; preds = %1
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = call ptr @parse_expr(ptr noundef %24)
  store ptr %25, ptr %2, align 8
  br label %26

26:                                               ; preds = %23, %21, %18, %15, %12, %11, %7
  %27 = load ptr, ptr %2, align 8
  ret ptr %27
}

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, !11, i64 0}
!10 = !{!"parser", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !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"

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @parse_toplevel(ptr noundef %0) local_unnamed_addr #0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %3, %1
  %2 = load i32, ptr %0, align 8, !tbaa !5
  switch i32 %2, label %11 [
    i32 65535, label %3
    i32 -1, label %.loopexit
    i32 -3, label %4
    i32 -2, label %6
    i32 -12, label %8
    i32 59, label %10
  ]

3:                                                ; preds = %tailrecurse
  tail call void @next_token(ptr noundef nonnull %0)
  br label %tailrecurse

4:                                                ; preds = %tailrecurse
  %5 = tail call ptr @parse_extern(ptr noundef nonnull %0)
  br label %.loopexit

6:                                                ; preds = %tailrecurse
  %7 = tail call ptr @parse_def(ptr noundef nonnull %0)
  br label %.loopexit

8:                                                ; preds = %tailrecurse
  %9 = tail call ptr @parse_import(ptr noundef nonnull %0)
  br label %.loopexit

10:                                               ; preds = %tailrecurse
  tail call void @next_token(ptr noundef nonnull %0)
  br label %.loopexit

11:                                               ; preds = %tailrecurse
  %12 = tail call ptr @parse_expr(ptr noundef nonnull %0)
  br label %.loopexit

.loopexit:                                        ; preds = %tailrecurse, %11, %10, %8, %6, %4
  %.0 = phi ptr [ %12, %11 ], [ null, %10 ], [ %9, %8 ], [ %7, %6 ], [ %5, %4 ], [ null, %tailrecurse ]
  ret ptr %.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, !7, i64 0}
!6 = !{!"parser", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}


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