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

@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [14 x i8], align 1
@__func__.ast_within_scope = external hidden unnamed_addr constant [17 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [14 x i8], align 1

; 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

declare void @ponyint_assert_fail(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @ast_within_scope(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i1, align 1
  %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 %5, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  br label %15

14:                                               ; preds = %3
  call void @ponyint_assert_fail(ptr noundef @.str.20, ptr noundef @.str.1, i64 noundef 1302, ptr noundef @__func__.ast_within_scope)
  br label %15

15:                                               ; preds = %14, %13
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %15
  br label %20

19:                                               ; preds = %15
  call void @ponyint_assert_fail(ptr noundef @.str.21, ptr noundef @.str.1, i64 noundef 1303, ptr noundef @__func__.ast_within_scope)
  br label %20

20:                                               ; preds = %19, %18
  br label %21

21:                                               ; preds = %57, %20
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ast_t, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %39

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ast_t, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = call ptr @symtab_find(ptr noundef %29, ptr noundef %30, ptr noundef %8)
  store ptr %31, ptr %9, align 8, !tbaa !5
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %35

34:                                               ; preds = %26
  store i1 true, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %36

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

36:                                               ; preds = %35, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %37 = load i32, ptr %10, align 4
  switch i32 %37, label %62 [
    i32 0, label %38
    i32 1, label %60
  ]

38:                                               ; preds = %36
  br label %39

39:                                               ; preds = %38, %21
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = icmp eq ptr %40, %41
  br i1 %42, label %43, label %44

43:                                               ; preds = %39
  br label %59

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

48:                                               ; preds = %44
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %57

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

57:                                               ; preds = %51, %48
  %58 = phi i1 [ false, %48 ], [ %56, %51 ]
  br i1 %58, label %21, label %59, !llvm.loop !15

59:                                               ; preds = %57, %43
  store i1 false, ptr %4, align 1
  br label %60

60:                                               ; preds = %59, %36
  %61 = load i1, ptr %4, align 1
  ret i1 %61

62:                                               ; preds = %36
  unreachable
}

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, !6, i64 8}
!10 = !{!"ast_t", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !11, i64 56, !12, i64 60}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!10, !6, i64 24}
!14 = !{!10, !6, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [14 x i8], align 1
@__func__.ast_within_scope = external hidden unnamed_addr constant [17 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [14 x i8], align 1

; 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

declare void @ponyint_assert_fail(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

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

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

5:                                                ; preds = %3
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str.20, ptr noundef nonnull @.str.1, i64 noundef 1302, ptr noundef nonnull @__func__.ast_within_scope) #3
  br label %6

6:                                                ; preds = %3, %5
  %.not15 = icmp eq ptr %1, null
  br i1 %.not15, label %7, label %.preheader

7:                                                ; preds = %6
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str.21, ptr noundef nonnull @.str.1, i64 noundef 1303, ptr noundef nonnull @__func__.ast_within_scope) #3
  br label %.preheader

.preheader:                                       ; preds = %6, %7
  br label %8

8:                                                ; preds = %.preheader, %18
  %.013 = phi ptr [ %17, %18 ], [ %1, %.preheader ]
  %9 = getelementptr inbounds i8, ptr %.013, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %.not16 = icmp eq ptr %10, null
  br i1 %.not16, label %13, label %11

11:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %12 = call ptr @symtab_find(ptr noundef nonnull %10, ptr noundef %2, ptr noundef nonnull %4) #3
  %.not17.not = icmp eq ptr %12, null
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  br i1 %.not17.not, label %13, label %.critedge

13:                                               ; preds = %11, %8
  %14 = icmp eq ptr %.013, %0
  br i1 %14, label %.critedge, label %15

15:                                               ; preds = %13
  %16 = getelementptr inbounds i8, ptr %.013, i64 24
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %.not18 = icmp eq ptr %17, null
  br i1 %.not18, label %.critedge, label %18

18:                                               ; preds = %15
  %19 = load ptr, ptr %17, align 8, !tbaa !13
  %20 = call i32 @token_get_id(ptr noundef %19) #3
  %.not19 = icmp eq i32 %20, 136
  br i1 %.not19, label %.critedge, label %8, !llvm.loop !14

.critedge:                                        ; preds = %11, %18, %13, %15
  %.3 = phi i1 [ true, %11 ], [ false, %15 ], [ false, %13 ], [ false, %18 ]
  ret i1 %.3
}

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, !7, i64 8}
!6 = !{!"ast_t", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !10, i64 56, !11, i64 60}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!6, !7, i64 24}
!13 = !{!6, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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