; 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.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 }
%struct.bb_traversal_args_t = type { ptr, ptr, 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_backward_traversal(ptr noundef) #3

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @build_reversed_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 = %41, %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 %45

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

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

45:                                               ; preds = %8
  %46 = load ptr, ptr %1, align 8, !tbaa !5
  call void @free(ptr noundef %46) #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, !14, i64 8544}
!12 = !{!"func", !13, i64 0, !7, i64 944, !14, i64 8496, !14, i64 8500, !14, i64 8504, !6, i64 8512, !6, i64 8520, !10, 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 = !{!19, !6, i64 0}
!19 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!20 = !{!12, !6, i64 8520}
!21 = !{!19, !6, i64 8}
!22 = !{!12, !14, i64 8548}
!23 = !{!19, !6, i64 24}
!24 = !{!12, !6, i64 8552}
!25 = distinct !{!25, !26}
!26 = !{!"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_backward_traversal(ptr noundef) local_unnamed_addr #2

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @build_reversed_rpo() local_unnamed_addr #2 {
  %1 = tail call noalias dereferenceable_or_null(32) ptr @calloc(i64 noundef 1, i64 noundef 32) #3
  %.017 = load ptr, ptr @FUNC_LIST, align 8, !tbaa !5
  %.not18 = icmp eq ptr %.017, null
  br i1 %.not18, 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
  %.019 = phi ptr [ %.017, %.lr.ph ], [ %.0, %4 ]
  %5 = getelementptr inbounds i8, ptr %.019, i64 8544
  store i32 0, ptr %5, align 8, !tbaa !9
  store ptr %.019, ptr %1, align 8, !tbaa !17
  %6 = getelementptr inbounds i8, ptr %.019, i64 8520
  %7 = load ptr, ptr %6, align 8, !tbaa !19
  store ptr %7, ptr %2, align 8, !tbaa !20
  %8 = getelementptr inbounds i8, ptr %.019, i64 8548
  %9 = load i32, ptr %8, align 4, !tbaa !21
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr %8, align 4, !tbaa !21
  store ptr @bb_index_reversed_rpo, ptr %3, align 8, !tbaa !22
  tail call void @bb_backward_traversal(ptr noundef nonnull %1)
  %11 = load i32, ptr %8, align 4, !tbaa !21
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr %8, align 4, !tbaa !21
  store ptr @bb_reverse_reversed_index, ptr %3, align 8, !tbaa !22
  tail call void @bb_backward_traversal(ptr noundef nonnull %1)
  %13 = load i32, ptr %8, align 4, !tbaa !21
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr %8, align 4, !tbaa !21
  store ptr @bb_build_reversed_rpo, ptr %3, align 8, !tbaa !22
  tail call void @bb_backward_traversal(ptr noundef nonnull %1)
  %15 = getelementptr inbounds i8, ptr %.019, i64 8552
  %.0 = load ptr, ptr %15, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %4, !llvm.loop !23
}

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


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