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

@.str.1 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [14 x i8], align 1
@__func__.paint = external hidden unnamed_addr constant [6 x i8], align 1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @paint(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca %struct.painter_t, 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.10, ptr noundef @.str.1, i64 noundef 414, ptr noundef @__func__.paint)
  br label %10

10:                                               ; preds = %9, %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = call i64 @reach_types_size(ptr noundef %11)
  store i64 %12, ptr %3, align 8, !tbaa !9
  %13 = load i64, ptr %3, align 8, !tbaa !9
  %14 = icmp eq i64 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %10
  store i32 1, ptr %4, align 4
  br label %29

16:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 64, ptr %5) #3
  %17 = getelementptr inbounds %struct.painter_t, ptr %5, i32 0, i32 0
  call void @name_records_init(ptr noundef %17, i64 noundef 8)
  %18 = getelementptr inbounds %struct.painter_t, ptr %5, i32 0, i32 1
  store ptr null, ptr %18, align 8, !tbaa !11
  %19 = getelementptr inbounds %struct.painter_t, ptr %5, i32 0, i32 1
  %20 = getelementptr inbounds %struct.painter_t, ptr %5, i32 0, i32 2
  store ptr %19, ptr %20, align 8, !tbaa !16
  %21 = getelementptr inbounds %struct.painter_t, ptr %5, i32 0, i32 4
  store i32 0, ptr %21, align 8, !tbaa !17
  %22 = load i64, ptr %3, align 8, !tbaa !9
  %23 = sub i64 %22, 1
  %24 = udiv i64 %23, 64
  %25 = add i64 %24, 1
  %26 = getelementptr inbounds %struct.painter_t, ptr %5, i32 0, i32 3
  store i64 %25, ptr %26, align 8, !tbaa !18
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  call void @find_names_types_use(ptr noundef %5, ptr noundef %27)
  call void @assign_colours_to_names(ptr noundef %5)
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  call void @distribute_info(ptr noundef %5, ptr noundef %28)
  call void @painter_tidy(ptr noundef %5)
  call void @llvm.lifetime.end.p0(i64 64, ptr %5) #3
  store i32 0, ptr %4, align 4
  br label %29

29:                                               ; preds = %16, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %30 = load i32, ptr %4, align 4
  switch i32 %30, label %32 [
    i32 0, label %31
    i32 1, label %31
  ]

31:                                               ; preds = %29, %29
  ret void

32:                                               ; preds = %29
  unreachable
}

declare i64 @reach_types_size(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @find_names_types_use(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @assign_colours_to_names(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @distribute_info(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @painter_tidy(ptr noundef) #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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 32}
!12 = !{!"painter_t", !13, i64 0, !6, i64 32, !6, i64 40, !10, i64 48, !15, i64 56}
!13 = !{!"name_records_t", !14, i64 0}
!14 = !{!"hashmap_t", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!"int", !7, i64 0}
!16 = !{!12, !6, i64 40}
!17 = !{!12, !15, i64 56}
!18 = !{!12, !10, i64 48}


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

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

@.str.1 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [14 x i8], align 1
@__func__.paint = external hidden unnamed_addr constant [6 x i8], align 1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @paint(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca %struct.painter_t, 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.10, ptr noundef nonnull @.str.1, i64 noundef 414, ptr noundef nonnull @__func__.paint) #3
  br label %4

4:                                                ; preds = %1, %3
  %5 = tail call i64 @reach_types_size(ptr noundef %0) #3
  %6 = icmp eq i64 %5, 0
  br i1 %6, label %15, label %7

7:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %2) #3
  call void @name_records_init(ptr noundef nonnull %2, i64 noundef 8)
  %8 = getelementptr inbounds i8, ptr %2, i64 32
  store ptr null, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %2, i64 40
  store ptr %8, ptr %9, align 8, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %2, i64 56
  store i32 0, ptr %10, align 8, !tbaa !15
  %11 = add i64 %5, -1
  %12 = lshr i64 %11, 6
  %13 = add nuw nsw i64 %12, 1
  %14 = getelementptr inbounds i8, ptr %2, i64 48
  store i64 %13, ptr %14, align 8, !tbaa !16
  call void @find_names_types_use(ptr noundef nonnull %2, ptr noundef %0)
  call void @assign_colours_to_names(ptr noundef nonnull %2)
  call void @distribute_info(ptr noundef nonnull %2, ptr noundef %0)
  call void @painter_tidy(ptr noundef nonnull %2)
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %2) #3
  br label %15

15:                                               ; preds = %4, %7
  ret void
}

declare i64 @reach_types_size(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @find_names_types_use(ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare hidden void @distribute_info(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @painter_tidy(ptr noundef) local_unnamed_addr #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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !12, i64 32}
!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 = !{!6, !12, i64 40}
!15 = !{!6, !13, i64 56}
!16 = !{!6, !9, i64 48}


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