; LLVM IR from ponylang/ponyc :: src/libponyc/ast (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.ast_t = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i8 }

; 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

declare i32 @token_get_id(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @ast_get(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %15

13:                                               ; preds = %3
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %13, %3
  br label %16

16:                                               ; preds = %58, %15
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ast_t, ptr %17, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %45

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ast_t, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = call ptr @symtab_find(ptr noundef %24, ptr noundef %25, ptr noundef %8)
  store ptr %26, ptr %9, align 8, !tbaa !5
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %36

29:                                               ; preds = %21
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %36

33:                                               ; preds = %29
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %34, ptr %35, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %33, %29, %21
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %41

39:                                               ; preds = %36
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %40, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %42

41:                                               ; preds = %36
  store i32 0, ptr %10, align 4
  br label %42

42:                                               ; preds = %41, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %43 = load i32, ptr %10, align 4
  switch i32 %43, label %63 [
    i32 0, label %44
    i32 1, label %61
  ]

44:                                               ; preds = %42
  br label %45

45:                                               ; preds = %44, %16
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.ast_t, ptr %46, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !14
  store ptr %48, ptr %5, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %45
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %58

52:                                               ; preds = %49
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.ast_t, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !15
  %56 = call i32 @token_get_id(ptr noundef %55)
  %57 = icmp ne i32 %56, 136
  br label %58

58:                                               ; preds = %52, %49
  %59 = phi i1 [ false, %49 ], [ %57, %52 ]
  br i1 %59, label %16, label %60, !llvm.loop !16

60:                                               ; preds = %58
  store ptr null, ptr %4, align 8
  br label %61

61:                                               ; preds = %60, %42
  %62 = load ptr, ptr %4, align 8
  ret ptr %62

63:                                               ; preds = %42
  unreachable
}

declare ptr @symtab_find(ptr noundef, ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #3 = { 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, !6, i64 8}
!12 = !{!"ast_t", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !10, i64 56, !13, i64 60}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!12, !6, i64 24}
!15 = !{!12, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare i32 @token_get_id(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @ast_get(ptr nocapture noundef readonly %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca i32, align 4
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %.split.us, label %5

5:                                                ; preds = %3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %.split

.split.us:                                        ; preds = %3, %13
  %.015.us = phi ptr [ %12, %13 ], [ %0, %3 ]
  %6 = getelementptr inbounds i8, ptr %.015.us, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %.not20.us = icmp eq ptr %7, null
  br i1 %.not20.us, label %10, label %8

8:                                                ; preds = %.split.us
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %9 = call ptr @symtab_find(ptr noundef nonnull %7, ptr noundef %1, ptr noundef nonnull %4) #3
  %.not21.not.us = icmp eq ptr %9, null
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  br i1 %.not21.not.us, label %10, label %.critedge

10:                                               ; preds = %8, %.split.us
  %11 = getelementptr inbounds i8, ptr %.015.us, i64 24
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %.not22.us = icmp eq ptr %12, null
  br i1 %.not22.us, label %.critedge, label %13

13:                                               ; preds = %10
  %14 = load ptr, ptr %12, align 8, !tbaa !14
  %15 = call i32 @token_get_id(ptr noundef %14) #3
  %.not23.us = icmp eq i32 %15, 136
  br i1 %.not23.us, label %.critedge, label %.split.us, !llvm.loop !15

.split:                                           ; preds = %5, %28
  %.015 = phi ptr [ %27, %28 ], [ %0, %5 ]
  %16 = getelementptr inbounds i8, ptr %.015, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %.not20 = icmp eq ptr %17, null
  br i1 %.not20, label %25, label %18

18:                                               ; preds = %.split
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %19 = call ptr @symtab_find(ptr noundef nonnull %17, ptr noundef %1, ptr noundef nonnull %4) #3
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %18
  %23 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %23, ptr %2, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %22, %18
  %.not21.not = icmp eq ptr %19, null
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  br i1 %.not21.not, label %25, label %.critedge

25:                                               ; preds = %24, %.split
  %26 = getelementptr inbounds i8, ptr %.015, i64 24
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %.not22 = icmp eq ptr %27, null
  br i1 %.not22, label %.critedge, label %28

28:                                               ; preds = %25
  %29 = load ptr, ptr %27, align 8, !tbaa !14
  %30 = call i32 @token_get_id(ptr noundef %29) #3
  %.not23 = icmp eq i32 %30, 136
  br i1 %.not23, label %.critedge, label %.split, !llvm.loop !15

.critedge:                                        ; preds = %25, %28, %24, %8, %10, %13
  %.us-phi = phi ptr [ %9, %8 ], [ null, %10 ], [ null, %13 ], [ %19, %24 ], [ null, %25 ], [ null, %28 ]
  ret ptr %.us-phi
}

declare ptr @symtab_find(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #3 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"ast_t", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !6, i64 56, !12, i64 60}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!10, !11, i64 24}
!14 = !{!10, !11, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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