; LLVM IR from ponylang/ponyc :: src/libponyc/reach (paint)

; 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.painter_t = type { %struct.name_records_t, ptr, ptr, i64, i32 }
%struct.name_records_t = type { %struct.hashmap_t }
%struct.hashmap_t = type { i64, i64, ptr, ptr }
%struct.name_record_t = type { ptr, i32, i64, ptr }
%struct.colour_record_t = type { i32, ptr, ptr }

@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [75 x i8], align 1
@__func__.painter_print = external hidden unnamed_addr constant [14 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [13 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

; Function Attrs: nounwind uwtable
declare dso_local ptr @name_records_next(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @painter_print(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  br label %10

9:                                                ; preds = %1
  call void @ponyint_assert_fail(ptr noundef @.str, ptr noundef @.str.1, i64 noundef 146, ptr noundef @__func__.painter_print)
  br label %10

10:                                               ; preds = %9, %8
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.painter_t, ptr %11, i32 0, i32 3
  %13 = load i64, ptr %12, align 8, !tbaa !9
  %14 = mul i64 %13, 8
  %15 = mul i64 %14, 8
  %16 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %15)
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 -1, ptr %3, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  br label %18

18:                                               ; preds = %39, %10
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.painter_t, ptr %19, i32 0, i32 0
  %21 = call ptr @name_records_next(ptr noundef %20, ptr noundef %3)
  store ptr %21, ptr %4, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %46

23:                                               ; preds = %18
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.name_record_t, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, ptr noundef %26)
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.name_record_t, ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 8, !tbaa !18
  %31 = icmp eq i32 %30, -1
  br i1 %31, label %32, label %34

32:                                               ; preds = %23
  %33 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  br label %39

34:                                               ; preds = %23
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.name_record_t, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 8, !tbaa !18
  %38 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef %37)
  br label %39

39:                                               ; preds = %34, %32
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.name_record_t, ptr %40, i32 0, i32 2
  %42 = load i64, ptr %41, align 8, !tbaa !19
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.name_record_t, ptr %43, i32 0, i32 3
  %45 = load ptr, ptr %44, align 8, !tbaa !20
  call void @print_typemap(i64 noundef %42, ptr noundef %45)
  br label %18, !llvm.loop !21

46:                                               ; preds = %18
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.painter_t, ptr %47, i32 0, i32 4
  %49 = load i32, ptr %48, align 8, !tbaa !23
  %50 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, i32 noundef %49)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.painter_t, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !24
  store ptr %53, ptr %5, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %69, %46
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = icmp ne ptr %55, null
  br i1 %56, label %58, label %57

57:                                               ; preds = %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %73

58:                                               ; preds = %54
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.colour_record_t, ptr %59, i32 0, i32 0
  %61 = load i32, ptr %60, align 8, !tbaa !25
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, i32 noundef %61)
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.painter_t, ptr %63, i32 0, i32 3
  %65 = load i64, ptr %64, align 8, !tbaa !9
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.colour_record_t, ptr %66, i32 0, i32 1
  %68 = load ptr, ptr %67, align 8, !tbaa !27
  call void @print_typemap(i64 noundef %65, ptr noundef %68)
  br label %69

69:                                               ; preds = %58
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.colour_record_t, ptr %70, i32 0, i32 2
  %72 = load ptr, ptr %71, align 8, !tbaa !28
  store ptr %72, ptr %5, align 8, !tbaa !5
  br label %54, !llvm.loop !29

73:                                               ; preds = %57
  %74 = call i32 (ptr, ...) @printf(ptr noundef @.str.9)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
declare hidden void @print_typemap(i64 noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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, !13, i64 48}
!10 = !{!"painter_t", !11, i64 0, !6, i64 32, !6, i64 40, !13, i64 48, !14, i64 56}
!11 = !{!"name_records_t", !12, i64 0}
!12 = !{!"hashmap_t", !13, i64 0, !13, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!"long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!13, !13, i64 0}
!16 = !{!17, !6, i64 0}
!17 = !{!"name_record_t", !6, i64 0, !14, i64 8, !13, i64 16, !6, i64 24}
!18 = !{!17, !14, i64 8}
!19 = !{!17, !13, i64 16}
!20 = !{!17, !6, i64 24}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!10, !14, i64 56}
!24 = !{!10, !6, i64 32}
!25 = !{!26, !14, i64 0}
!26 = !{!"colour_record_t", !14, i64 0, !6, i64 8, !6, i64 16}
!27 = !{!26, !6, i64 8}
!28 = !{!26, !6, i64 16}
!29 = distinct !{!29, !22}


; 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 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [75 x i8], align 1
@__func__.painter_print = external hidden unnamed_addr constant [14 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [13 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

; Function Attrs: nounwind uwtable
declare dso_local ptr @name_records_next(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @painter_print(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca i64, align 8
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %3, label %4

3:                                                ; preds = %1
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i64 noundef 146, ptr noundef nonnull @__func__.painter_print) #4
  br label %4

4:                                                ; preds = %1, %3
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = shl i64 %6, 6
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %7)
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  store i64 -1, ptr %2, align 8, !tbaa !14
  %10 = call ptr @name_records_next(ptr noundef %0, ptr noundef nonnull %2)
  %.not1719 = icmp eq ptr %10, null
  br i1 %.not1719, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %21
  %11 = phi ptr [ %26, %21 ], [ %10, %4 ]
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %13 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, ptr noundef %12)
  %14 = getelementptr inbounds i8, ptr %11, i64 8
  %15 = load i32, ptr %14, align 8, !tbaa !17
  %16 = icmp eq i32 %15, -1
  br i1 %16, label %17, label %19

17:                                               ; preds = %.lr.ph
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  br label %21

19:                                               ; preds = %.lr.ph
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef %15)
  br label %21

21:                                               ; preds = %19, %17
  %22 = getelementptr inbounds i8, ptr %11, i64 16
  %23 = load i64, ptr %22, align 8, !tbaa !18
  %24 = getelementptr inbounds i8, ptr %11, i64 24
  %25 = load ptr, ptr %24, align 8, !tbaa !19
  call void @print_typemap(i64 noundef %23, ptr noundef %25)
  %26 = call ptr @name_records_next(ptr noundef %0, ptr noundef nonnull %2)
  %.not17 = icmp eq ptr %26, null
  br i1 %.not17, label %._crit_edge, label %.lr.ph, !llvm.loop !20

._crit_edge:                                      ; preds = %21, %4
  %27 = getelementptr inbounds i8, ptr %0, i64 56
  %28 = load i32, ptr %27, align 8, !tbaa !22
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, i32 noundef %28)
  %30 = getelementptr inbounds i8, ptr %0, i64 32
  %.020 = load ptr, ptr %30, align 8, !tbaa !23
  %.not1821 = icmp eq ptr %.020, null
  br i1 %.not1821, label %._crit_edge25, label %.lr.ph24

._crit_edge25:                                    ; preds = %.lr.ph24, %._crit_edge
  %31 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  ret void

.lr.ph24:                                         ; preds = %._crit_edge, %.lr.ph24
  %.022 = phi ptr [ %.0, %.lr.ph24 ], [ %.020, %._crit_edge ]
  %32 = load i32, ptr %.022, align 8, !tbaa !24
  %33 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, i32 noundef %32)
  %34 = load i64, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %.022, i64 8
  %36 = load ptr, ptr %35, align 8, !tbaa !26
  call void @print_typemap(i64 noundef %34, ptr noundef %36)
  %37 = getelementptr inbounds i8, ptr %.022, i64 16
  %.0 = load ptr, ptr %37, align 8, !tbaa !23
  %.not18 = icmp eq ptr %.0, null
  br i1 %.not18, label %._crit_edge25, label %.lr.ph24, !llvm.loop !27
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden void @print_typemap(i64 noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = { nofree nounwind "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 #4 = { 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, !9, i64 48}
!6 = !{!"painter_t", !7, i64 0, !12, i64 32, !12, i64 40, !9, i64 48, !13, i64 56}
!7 = !{!"name_records_t", !8, i64 0}
!8 = !{!"hashmap_t", !9, i64 0, !9, i64 8, !12, i64 16, !12, i64 24}
!9 = !{!"long", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"any pointer", !10, i64 0}
!13 = !{!"int", !10, i64 0}
!14 = !{!9, !9, i64 0}
!15 = !{!16, !12, i64 0}
!16 = !{!"name_record_t", !12, i64 0, !13, i64 8, !9, i64 16, !12, i64 24}
!17 = !{!16, !13, i64 8}
!18 = !{!16, !9, i64 16}
!19 = !{!16, !12, i64 24}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!6, !13, i64 56}
!23 = !{!12, !12, i64 0}
!24 = !{!25, !13, i64 0}
!25 = !{!"colour_record_t", !13, i64 0, !12, i64 8, !12, i64 16}
!26 = !{!25, !12, i64 8}
!27 = distinct !{!27, !21}


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