; LLVM IR from sysprog21/shecc :: src (ssa)

; 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.func_list_t = type { ptr, ptr }
%struct.bb_traversal_args_t = type { ptr, ptr, ptr, ptr }
%struct.func = type { %struct.var, [8 x %struct.var], i32, i32, i32, ptr, ptr, %struct.symbol_list_t, i32, i32, ptr }
%struct.var = type { [32 x i8], [32 x i8], i32, i8, i8, i32, i32, i32, i32, i32, ptr, i32, [64 x ptr], i32, %struct.rename_t, %struct.ref_block_list, ptr, ptr, ptr, i32, i8, i8, i8 }
%struct.rename_t = type { i32, [64 x i32], i32 }
%struct.ref_block_list = type { ptr, ptr }
%struct.symbol_list_t = type { ptr, ptr }

@FUNC_LIST = external dso_local global %struct.func_list_t, align 8

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

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

; 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 void @bb_forward_traversal(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local void @bb_index_rpo(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local void @bb_reverse_index(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local void @bb_build_rpo(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @build_rpo() #3 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  %3 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 32) #5
  store ptr %3, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %4 = load ptr, ptr @FUNC_LIST, align 8, !tbaa !9
  store ptr %4, ptr %2, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %39, %0
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %9, label %8

8:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  br label %43

9:                                                ; preds = %5
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = load ptr, ptr %1, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.bb_traversal_args_t, ptr %11, i32 0, i32 0
  store ptr %10, ptr %12, align 8, !tbaa !11
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.func, ptr %13, i32 0, i32 5
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = load ptr, ptr %1, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.bb_traversal_args_t, ptr %16, i32 0, i32 1
  store ptr %15, ptr %17, align 8, !tbaa !20
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.func, ptr %18, i32 0, i32 9
  %20 = load i32, ptr %19, align 4, !tbaa !21
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %19, align 4, !tbaa !21
  %22 = load ptr, ptr %1, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.bb_traversal_args_t, ptr %22, i32 0, i32 3
  store ptr @bb_index_rpo, ptr %23, align 8, !tbaa !22
  %24 = load ptr, ptr %1, align 8, !tbaa !5
  call void @bb_forward_traversal(ptr noundef %24)
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.func, ptr %25, i32 0, i32 9
  %27 = load i32, ptr %26, align 4, !tbaa !21
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %26, align 4, !tbaa !21
  %29 = load ptr, ptr %1, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.bb_traversal_args_t, ptr %29, i32 0, i32 3
  store ptr @bb_reverse_index, ptr %30, align 8, !tbaa !22
  %31 = load ptr, ptr %1, align 8, !tbaa !5
  call void @bb_forward_traversal(ptr noundef %31)
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.func, ptr %32, i32 0, i32 9
  %34 = load i32, ptr %33, align 4, !tbaa !21
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %33, align 4, !tbaa !21
  %36 = load ptr, ptr %1, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.bb_traversal_args_t, ptr %36, i32 0, i32 3
  store ptr @bb_build_rpo, ptr %37, align 8, !tbaa !22
  %38 = load ptr, ptr %1, align 8, !tbaa !5
  call void @bb_forward_traversal(ptr noundef %38)
  br label %39

39:                                               ; preds = %9
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.func, ptr %40, i32 0, i32 10
  %42 = load ptr, ptr %41, align 8, !tbaa !23
  store ptr %42, ptr %2, align 8, !tbaa !5
  br label %5, !llvm.loop !24

43:                                               ; preds = %8
  %44 = load ptr, ptr %1, align 8, !tbaa !5
  call void @free(ptr noundef %44) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(0,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 "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 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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0,1) }

!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 0}
!10 = !{!"", !6, i64 0, !6, i64 8}
!11 = !{!12, !6, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!14, !6, i64 8512}
!14 = !{!"func", !15, i64 0, !7, i64 944, !16, i64 8496, !16, i64 8500, !16, i64 8504, !6, i64 8512, !6, i64 8520, !10, i64 8528, !16, i64 8544, !16, i64 8548, !6, i64 8552}
!15 = !{!"var", !7, i64 0, !7, i64 32, !16, i64 64, !17, i64 68, !17, i64 69, !16, i64 72, !16, i64 76, !16, i64 80, !16, i64 84, !16, i64 88, !6, i64 96, !16, i64 104, !7, i64 112, !16, i64 624, !18, i64 628, !19, i64 896, !6, i64 912, !6, i64 920, !6, i64 928, !16, i64 936, !17, i64 940, !17, i64 941, !17, i64 942}
!16 = !{!"int", !7, i64 0}
!17 = !{!"_Bool", !7, i64 0}
!18 = !{!"", !16, i64 0, !7, i64 4, !16, i64 260}
!19 = !{!"ref_block_list", !6, i64 0, !6, i64 8}
!20 = !{!12, !6, i64 8}
!21 = !{!14, !16, i64 8548}
!22 = !{!12, !6, i64 24}
!23 = !{!14, !6, i64 8552}
!24 = distinct !{!24, !25}
!25 = !{!"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"

%struct.func_list_t = type { ptr, ptr }

@FUNC_LIST = external dso_local local_unnamed_addr global %struct.func_list_t, align 8

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @bb_forward_traversal(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @bb_index_rpo(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @bb_reverse_index(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @bb_build_rpo(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @build_rpo() local_unnamed_addr #2 {
  %1 = tail call noalias dereferenceable_or_null(32) ptr @calloc(i64 noundef 1, i64 noundef 32) #3
  %.016 = load ptr, ptr @FUNC_LIST, align 8, !tbaa !5
  %.not17 = icmp eq ptr %.016, null
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0
  %2 = getelementptr inbounds i8, ptr %1, i64 8
  %3 = getelementptr inbounds i8, ptr %1, i64 24
  br label %4

._crit_edge:                                      ; preds = %4, %0
  tail call void @free(ptr noundef %1) #4
  ret void

4:                                                ; preds = %.lr.ph, %4
  %.018 = phi ptr [ %.016, %.lr.ph ], [ %.0, %4 ]
  store ptr %.018, ptr %1, align 8, !tbaa !9
  %5 = getelementptr inbounds i8, ptr %.018, i64 8512
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  store ptr %6, ptr %2, align 8, !tbaa !19
  %7 = getelementptr inbounds i8, ptr %.018, i64 8548
  %8 = load i32, ptr %7, align 4, !tbaa !20
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr %7, align 4, !tbaa !20
  store ptr @bb_index_rpo, ptr %3, align 8, !tbaa !21
  tail call void @bb_forward_traversal(ptr noundef nonnull %1)
  %10 = load i32, ptr %7, align 4, !tbaa !20
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr %7, align 4, !tbaa !20
  store ptr @bb_reverse_index, ptr %3, align 8, !tbaa !21
  tail call void @bb_forward_traversal(ptr noundef nonnull %1)
  %12 = load i32, ptr %7, align 4, !tbaa !20
  %13 = add nsw i32 %12, 1
  store i32 %13, ptr %7, align 4, !tbaa !20
  store ptr @bb_build_rpo, ptr %3, align 8, !tbaa !21
  tail call void @bb_forward_traversal(ptr noundef nonnull %1)
  %14 = getelementptr inbounds i8, ptr %.018, i64 8552
  %.0 = load ptr, ptr %14, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %4, !llvm.loop !22
}

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0,1) }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!12, !6, i64 8512}
!12 = !{!"func", !13, i64 0, !7, i64 944, !14, i64 8496, !14, i64 8500, !14, i64 8504, !6, i64 8512, !6, i64 8520, !18, i64 8528, !14, i64 8544, !14, i64 8548, !6, i64 8552}
!13 = !{!"var", !7, i64 0, !7, i64 32, !14, i64 64, !15, i64 68, !15, i64 69, !14, i64 72, !14, i64 76, !14, i64 80, !14, i64 84, !14, i64 88, !6, i64 96, !14, i64 104, !7, i64 112, !14, i64 624, !16, i64 628, !17, i64 896, !6, i64 912, !6, i64 920, !6, i64 928, !14, i64 936, !15, i64 940, !15, i64 941, !15, i64 942}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!"", !14, i64 0, !7, i64 4, !14, i64 260}
!17 = !{!"ref_block_list", !6, i64 0, !6, i64 8}
!18 = !{!"", !6, i64 0, !6, i64 8}
!19 = !{!10, !6, i64 8}
!20 = !{!12, !14, i64 8548}
!21 = !{!10, !6, i64 24}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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