; 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.basic_block = type { %struct.insn_list_t, %struct.ph2_ir_list_t, [128 x %struct.bb_connection_t], ptr, ptr, ptr, ptr, ptr, ptr, ptr, [800 x ptr], i32, [800 x ptr], i32, [800 x ptr], i32, [800 x ptr], i32, i32, i32, [64 x ptr], [64 x ptr], i32, i32, i32, i8, [64 x ptr], ptr, [256 x ptr], ptr, ptr, ptr, %struct.symbol_list_t, i32 }
%struct.insn_list_t = type { ptr, ptr }
%struct.ph2_ir_list_t = type { ptr, ptr }
%struct.bb_connection_t = type { ptr, i32 }
%struct.insn = type { ptr, ptr, i32, i32, ptr, ptr, ptr, i32, i8, ptr, ptr, [64 x i8] }

@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: 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 @use_chain_add_tail(ptr noundef, ptr noundef) #1

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

6:                                                ; preds = %58, %0
  %7 = load ptr, ptr %1, align 8, !tbaa !10
  %8 = icmp ne ptr %7, null
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  store i32 2, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  br label %62

10:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %11 = load ptr, ptr %1, align 8, !tbaa !10
  %12 = getelementptr inbounds %struct.func, ptr %11, i32 0, i32 5
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  store ptr %13, ptr %3, align 8, !tbaa !10
  br label %14

14:                                               ; preds = %53, %10
  %15 = load ptr, ptr %3, align 8, !tbaa !10
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %14
  store i32 5, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  br label %57

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %19 = load ptr, ptr %3, align 8, !tbaa !10
  %20 = getelementptr inbounds %struct.basic_block, ptr %19, i32 0, i32 0
  %21 = getelementptr inbounds %struct.insn_list_t, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !18
  store ptr %22, ptr %4, align 8, !tbaa !10
  br label %23

23:                                               ; preds = %48, %18
  %24 = load ptr, ptr %4, align 8, !tbaa !10
  %25 = icmp ne ptr %24, null
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  store i32 8, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %52

27:                                               ; preds = %23
  %28 = load ptr, ptr %4, align 8, !tbaa !10
  %29 = getelementptr inbounds %struct.insn, ptr %28, i32 0, i32 5
  %30 = load ptr, ptr %29, align 8, !tbaa !20
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %37

32:                                               ; preds = %27
  %33 = load ptr, ptr %4, align 8, !tbaa !10
  %34 = load ptr, ptr %4, align 8, !tbaa !10
  %35 = getelementptr inbounds %struct.insn, ptr %34, i32 0, i32 5
  %36 = load ptr, ptr %35, align 8, !tbaa !20
  call void @use_chain_add_tail(ptr noundef %33, ptr noundef %36)
  br label %37

37:                                               ; preds = %32, %27
  %38 = load ptr, ptr %4, align 8, !tbaa !10
  %39 = getelementptr inbounds %struct.insn, ptr %38, i32 0, i32 6
  %40 = load ptr, ptr %39, align 8, !tbaa !22
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %47

42:                                               ; preds = %37
  %43 = load ptr, ptr %4, align 8, !tbaa !10
  %44 = load ptr, ptr %4, align 8, !tbaa !10
  %45 = getelementptr inbounds %struct.insn, ptr %44, i32 0, i32 6
  %46 = load ptr, ptr %45, align 8, !tbaa !22
  call void @use_chain_add_tail(ptr noundef %43, ptr noundef %46)
  br label %47

47:                                               ; preds = %42, %37
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr %4, align 8, !tbaa !10
  %50 = getelementptr inbounds %struct.insn, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !23
  store ptr %51, ptr %4, align 8, !tbaa !10
  br label %23, !llvm.loop !24

52:                                               ; preds = %26
  br label %53

53:                                               ; preds = %52
  %54 = load ptr, ptr %3, align 8, !tbaa !10
  %55 = getelementptr inbounds %struct.basic_block, ptr %54, i32 0, i32 8
  %56 = load ptr, ptr %55, align 8, !tbaa !26
  store ptr %56, ptr %3, align 8, !tbaa !10
  br label %14, !llvm.loop !27

57:                                               ; preds = %17
  br label %58

58:                                               ; preds = %57
  %59 = load ptr, ptr %1, align 8, !tbaa !10
  %60 = getelementptr inbounds %struct.func, ptr %59, i32 0, i32 10
  %61 = load ptr, ptr %60, align 8, !tbaa !28
  store ptr %61, ptr %1, align 8, !tbaa !10
  br label %6, !llvm.loop !29

62:                                               ; preds = %9
  ret void
}

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 = { 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !7, i64 8512}
!12 = !{!"func", !13, i64 0, !8, i64 944, !14, i64 8496, !14, i64 8500, !14, i64 8504, !7, i64 8512, !7, i64 8520, !6, i64 8528, !14, i64 8544, !14, i64 8548, !7, i64 8552}
!13 = !{!"var", !8, i64 0, !8, 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, !7, i64 96, !14, i64 104, !8, i64 112, !14, i64 624, !16, i64 628, !17, i64 896, !7, i64 912, !7, i64 920, !7, i64 928, !14, i64 936, !15, i64 940, !15, i64 941, !15, i64 942}
!14 = !{!"int", !8, i64 0}
!15 = !{!"_Bool", !8, i64 0}
!16 = !{!"", !14, i64 0, !8, i64 4, !14, i64 260}
!17 = !{!"ref_block_list", !7, i64 0, !7, i64 8}
!18 = !{!19, !7, i64 0}
!19 = !{!"basic_block", !6, i64 0, !6, i64 16, !8, i64 32, !7, i64 2080, !7, i64 2088, !7, i64 2096, !7, i64 2104, !7, i64 2112, !7, i64 2120, !7, i64 2128, !8, i64 2136, !14, i64 8536, !8, i64 8544, !14, i64 14944, !8, i64 14952, !14, i64 21352, !8, i64 21360, !14, i64 27760, !14, i64 27764, !14, i64 27768, !8, i64 27776, !8, i64 28288, !14, i64 28800, !14, i64 28804, !14, i64 28808, !15, i64 28812, !8, i64 28816, !7, i64 29328, !8, i64 29336, !7, i64 31384, !7, i64 31392, !7, i64 31400, !6, i64 31408, !14, i64 31424}
!20 = !{!21, !7, i64 32}
!21 = !{!"insn", !7, i64 0, !7, i64 8, !14, i64 16, !14, i64 20, !7, i64 24, !7, i64 32, !7, i64 40, !14, i64 48, !15, i64 52, !7, i64 56, !7, i64 64, !8, i64 72}
!22 = !{!21, !7, i64 40}
!23 = !{!21, !7, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = !{!19, !7, i64 2120}
!27 = distinct !{!27, !25}
!28 = !{!12, !7, i64 8552}
!29 = distinct !{!29, !25}


; 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: nounwind uwtable
declare dso_local void @use_chain_add_tail(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @use_chain_build() local_unnamed_addr #0 {
  %.01529 = load ptr, ptr @FUNC_LIST, align 8, !tbaa !5
  %.not30 = icmp eq ptr %.01529, null
  br i1 %.not30, label %._crit_edge34, label %.lr.ph33

._crit_edge34:                                    ; preds = %._crit_edge28, %0
  ret void

.lr.ph33:                                         ; preds = %0, %._crit_edge28
  %.01531 = phi ptr [ %.015, %._crit_edge28 ], [ %.01529, %0 ]
  %1 = getelementptr inbounds i8, ptr %.01531, i64 8512
  %.01425 = load ptr, ptr %1, align 8, !tbaa !5
  %.not1826 = icmp eq ptr %.01425, null
  br i1 %.not1826, label %._crit_edge28, label %.preheader

.preheader:                                       ; preds = %.lr.ph33, %._crit_edge
  %.01427 = phi ptr [ %.014, %._crit_edge ], [ %.01425, %.lr.ph33 ]
  %.022 = load ptr, ptr %.01427, align 8, !tbaa !5
  %.not1923 = icmp eq ptr %.022, null
  br i1 %.not1923, label %._crit_edge, label %.lr.ph

._crit_edge28:                                    ; preds = %._crit_edge, %.lr.ph33
  %2 = getelementptr inbounds i8, ptr %.01531, i64 8552
  %.015 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %.015, null
  br i1 %.not, label %._crit_edge34, label %.lr.ph33, !llvm.loop !9

._crit_edge:                                      ; preds = %11, %.preheader
  %3 = getelementptr inbounds i8, ptr %.01427, i64 2120
  %.014 = load ptr, ptr %3, align 8, !tbaa !5
  %.not18 = icmp eq ptr %.014, null
  br i1 %.not18, label %._crit_edge28, label %.preheader, !llvm.loop !11

.lr.ph:                                           ; preds = %.preheader, %11
  %.024 = phi ptr [ %.0, %11 ], [ %.022, %.preheader ]
  %4 = getelementptr inbounds i8, ptr %.024, i64 32
  %5 = load ptr, ptr %4, align 8, !tbaa !12
  %.not20 = icmp eq ptr %5, null
  br i1 %.not20, label %7, label %6

6:                                                ; preds = %.lr.ph
  tail call void @use_chain_add_tail(ptr noundef nonnull %.024, ptr noundef nonnull %5)
  br label %7

7:                                                ; preds = %6, %.lr.ph
  %8 = getelementptr inbounds i8, ptr %.024, i64 40
  %9 = load ptr, ptr %8, align 8, !tbaa !16
  %.not21 = icmp eq ptr %9, null
  br i1 %.not21, label %11, label %10

10:                                               ; preds = %7
  tail call void @use_chain_add_tail(ptr noundef nonnull %.024, ptr noundef nonnull %9)
  br label %11

11:                                               ; preds = %7, %10
  %.0 = load ptr, ptr %.024, align 8, !tbaa !5
  %.not19 = icmp eq ptr %.0, null
  br i1 %.not19, label %._crit_edge, label %.lr.ph, !llvm.loop !17
}

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

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = !{!13, !6, i64 32}
!13 = !{!"insn", !6, i64 0, !6, i64 8, !14, i64 16, !14, i64 20, !6, i64 24, !6, i64 32, !6, i64 40, !14, i64 48, !15, i64 52, !6, i64 56, !6, i64 64, !7, i64 72}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!13, !6, i64 40}
!17 = distinct !{!17, !10}


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