; LLVM IR from ponylang/ponyc :: src/libponyc/expr (reference)

; 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.pass_opt_t = type { i32, i32, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i32, i64, i8, i8, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %struct.typecheck_t, ptr, ptr }
%struct.typecheck_t = type { ptr, %struct.typecheck_stats_t, ptr }
%struct.typecheck_stats_t = type { i64, i64, i64, i64 }

@.str.34 = external hidden unnamed_addr constant [66 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 void @ast_settype(ptr noundef, ptr noundef) #1

declare i32 @ast_id(ptr noundef) #1

declare ptr @ast_type(ptr noundef) #1

declare void @ast_error(ptr noundef, ptr noundef, ptr noundef, ...) #1

declare ptr @ast_child(ptr noundef) #1

declare ptr @ast_from(ptr noundef, i32 noundef) #1

declare ptr @ast_sibling(ptr noundef) #1

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

declare void @ast_free(ptr noundef) #1

declare i32 @ast_checkflag(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @expr_tuple(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i1, align 1
  %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
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = call ptr @ast_child(ptr noundef %10)
  store ptr %11, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = call ptr @ast_sibling(ptr noundef %12)
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %18

15:                                               ; preds = %2
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = call ptr @ast_type(ptr noundef %16)
  store ptr %17, ptr %7, align 8, !tbaa !5
  br label %60

18:                                               ; preds = %2
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call ptr @ast_from(ptr noundef %19, i32 noundef 150)
  store ptr %20, ptr %7, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %58, %18
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %59

24:                                               ; preds = %21
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = call i32 @ast_checkflag(ptr noundef %25, i32 noundef 1048576)
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %34

28:                                               ; preds = %24
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.pass_opt_t, ptr %29, i32 0, i32 36
  %31 = getelementptr inbounds %struct.typecheck_t, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  call void (ptr, ptr, ptr, ...) @ast_error(ptr noundef %32, ptr noundef %33, ptr noundef @.str.34)
  store i1 false, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %63

34:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = call ptr @ast_type(ptr noundef %35)
  store ptr %36, ptr %9, align 8, !tbaa !5
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = icmp eq ptr %37, null
  br i1 %38, label %43, label %39

39:                                               ; preds = %34
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = call i32 @ast_id(ptr noundef %40)
  %42 = icmp eq i32 %41, 158
  br i1 %42, label %43, label %44

43:                                               ; preds = %39, %34
  store i1 false, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %56

44:                                               ; preds = %39
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = call zeroext i1 @is_type_literal(ptr noundef %45)
  br i1 %46, label %47, label %50

47:                                               ; preds = %44
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  call void @ast_free(ptr noundef %48)
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  call void @make_literal_type(ptr noundef %49)
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %56

50:                                               ; preds = %44
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = call ptr @ast_append(ptr noundef %51, ptr noundef %52)
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = call ptr @ast_sibling(ptr noundef %54)
  store ptr %55, ptr %6, align 8, !tbaa !5
  store i32 0, ptr %8, align 4
  br label %56

56:                                               ; preds = %50, %47, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %57 = load i32, ptr %8, align 4
  switch i32 %57, label %63 [
    i32 0, label %58
  ]

58:                                               ; preds = %56
  br label %21, !llvm.loop !16

59:                                               ; preds = %21
  br label %60

60:                                               ; preds = %59, %15
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  call void @ast_settype(ptr noundef %61, ptr noundef %62)
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %63

63:                                               ; preds = %60, %56, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %64 = load i1, ptr %3, align 1
  ret i1 %64
}

declare zeroext i1 @is_type_literal(ptr noundef) #1

declare void @make_literal_type(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, !6, i64 216}
!10 = !{!"pass_opt_t", !11, i64 0, !11, i64 4, !12, i64 8, !12, i64 9, !12, i64 10, !12, i64 11, !12, i64 12, !12, i64 13, !12, i64 14, !12, i64 15, !12, i64 16, !12, i64 17, !12, i64 18, !12, i64 19, !12, i64 20, !12, i64 21, !11, i64 24, !13, i64 32, !12, i64 40, !12, i64 41, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !14, i64 176, !6, i64 224, !6, i64 232}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!"typecheck_t", !6, i64 0, !15, i64 8, !6, i64 40}
!15 = !{!"typecheck_stats_t", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24}
!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"

@.str.34 = external hidden unnamed_addr constant [66 x i8], align 1

declare void @ast_settype(ptr noundef, ptr noundef) local_unnamed_addr #0

declare i32 @ast_id(ptr noundef) local_unnamed_addr #0

declare ptr @ast_type(ptr noundef) local_unnamed_addr #0

declare void @ast_error(ptr noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #0

declare ptr @ast_child(ptr noundef) local_unnamed_addr #0

declare ptr @ast_from(ptr noundef, i32 noundef) local_unnamed_addr #0

declare ptr @ast_sibling(ptr noundef) local_unnamed_addr #0

declare ptr @ast_append(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @ast_free(ptr noundef) local_unnamed_addr #0

declare i32 @ast_checkflag(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @expr_tuple(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call ptr @ast_child(ptr noundef %1) #2
  %4 = tail call ptr @ast_sibling(ptr noundef %3) #2
  %5 = icmp eq ptr %4, null
  br i1 %5, label %6, label %8

6:                                                ; preds = %2
  %7 = tail call ptr @ast_type(ptr noundef %3) #2
  br label %.loopexit

8:                                                ; preds = %2
  %9 = tail call ptr @ast_from(ptr noundef %1, i32 noundef 150) #2
  %.not32 = icmp eq ptr %3, null
  br i1 %.not32, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %8, %23
  %.02233 = phi ptr [ %25, %23 ], [ %3, %8 ]
  %10 = tail call i32 @ast_checkflag(ptr noundef nonnull %.02233, i32 noundef 1048576) #2
  %.not25 = icmp eq i32 %10, 0
  br i1 %.not25, label %14, label %11

11:                                               ; preds = %.lr.ph
  %12 = getelementptr inbounds i8, ptr %0, i64 216
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  tail call void (ptr, ptr, ptr, ...) @ast_error(ptr noundef %13, ptr noundef nonnull %.02233, ptr noundef nonnull @.str.34) #2
  br label %.thread

14:                                               ; preds = %.lr.ph
  %15 = tail call ptr @ast_type(ptr noundef nonnull %.02233) #2
  %16 = icmp eq ptr %15, null
  br i1 %16, label %.thread, label %17

17:                                               ; preds = %14
  %18 = tail call i32 @ast_id(ptr noundef nonnull %15) #2
  %19 = icmp eq i32 %18, 158
  br i1 %19, label %.thread, label %20

20:                                               ; preds = %17
  %21 = tail call zeroext i1 @is_type_literal(ptr noundef nonnull %15) #2
  br i1 %21, label %22, label %23

22:                                               ; preds = %20
  tail call void @ast_free(ptr noundef %9) #2
  tail call void @make_literal_type(ptr noundef %1) #2
  br label %.thread

23:                                               ; preds = %20
  %24 = tail call ptr @ast_append(ptr noundef %9, ptr noundef nonnull %15) #2
  %25 = tail call ptr @ast_sibling(ptr noundef nonnull %.02233) #2
  %.not = icmp eq ptr %25, null
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !15

.loopexit:                                        ; preds = %23, %8, %6
  %.021 = phi ptr [ %7, %6 ], [ %9, %8 ], [ %9, %23 ]
  tail call void @ast_settype(ptr noundef %1, ptr noundef %.021) #2
  br label %.thread

.thread:                                          ; preds = %14, %17, %22, %.loopexit, %11
  %.2 = phi i1 [ true, %.loopexit ], [ false, %11 ], [ true, %22 ], [ false, %17 ], [ false, %14 ]
  ret i1 %.2
}

declare zeroext i1 @is_type_literal(ptr noundef) local_unnamed_addr #0

declare void @make_literal_type(ptr noundef) local_unnamed_addr #0

attributes #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 = { 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 #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, !12, i64 216}
!6 = !{!"pass_opt_t", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 9, !10, i64 10, !10, i64 11, !10, i64 12, !10, i64 13, !10, i64 14, !10, i64 15, !10, i64 16, !10, i64 17, !10, i64 18, !10, i64 19, !10, i64 20, !10, i64 21, !7, i64 24, !11, i64 32, !10, i64 40, !10, i64 41, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !12, i64 128, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !13, i64 176, !12, i64 224, !12, i64 232}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_Bool", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"typecheck_t", !12, i64 0, !14, i64 8, !12, i64 40}
!14 = !{!"typecheck_stats_t", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass