; 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.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.symbol_list_t = type { ptr, ptr }
%struct.insn = type { ptr, ptr, i32, i32, ptr, ptr, ptr, i32, i8, ptr, ptr, [64 x i8] }
%struct.phi_operand = type { ptr, ptr, ptr }

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

; Function Attrs: nounwind uwtable
define dso_local void @bb_unwind_phi(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.basic_block, ptr %8, i32 0, i32 0
  %10 = getelementptr inbounds %struct.insn_list_t, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %11, ptr %5, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %44, %2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %48

15:                                               ; preds = %12
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.insn, ptr %16, i32 0, i32 3
  %18 = load i32, ptr %17, align 4, !tbaa !14
  %19 = icmp ne i32 %18, 1
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  br label %48

21:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.insn, ptr %22, i32 0, i32 10
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  store ptr %24, ptr %6, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %39, %21
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %29, label %28

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

29:                                               ; preds = %25
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.phi_operand, ptr %30, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !17
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.insn, ptr %33, i32 0, i32 4
  %35 = load ptr, ptr %34, align 8, !tbaa !19
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.phi_operand, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !20
  call void @append_unwound_phi_insn(ptr noundef %32, ptr noundef %35, ptr noundef %38)
  br label %39

39:                                               ; preds = %29
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.phi_operand, ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !21
  store ptr %42, ptr %6, align 8, !tbaa !5
  br label %25, !llvm.loop !22

43:                                               ; preds = %28
  br label %44

44:                                               ; preds = %43
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.insn, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !24
  store ptr %47, ptr %5, align 8, !tbaa !5
  br label %12, !llvm.loop !25

48:                                               ; preds = %20, %12
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.basic_block, ptr %50, i32 0, i32 0
  %52 = getelementptr inbounds %struct.insn_list_t, ptr %51, i32 0, i32 0
  store ptr %49, ptr %52, align 8, !tbaa !9
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = icmp ne ptr %53, null
  br i1 %54, label %59, label %55

55:                                               ; preds = %48
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.basic_block, ptr %56, i32 0, i32 0
  %58 = getelementptr inbounds %struct.insn_list_t, ptr %57, i32 0, i32 1
  store ptr null, ptr %58, align 8, !tbaa !26
  br label %62

59:                                               ; preds = %48
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.insn, ptr %60, i32 0, i32 1
  store ptr null, ptr %61, align 8, !tbaa !27
  br label %62

62:                                               ; preds = %59, %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  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, !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 = !{!"basic_block", !11, i64 0, !11, i64 16, !7, i64 32, !6, i64 2080, !6, i64 2088, !6, i64 2096, !6, i64 2104, !6, i64 2112, !6, i64 2120, !6, i64 2128, !7, i64 2136, !12, i64 8536, !7, i64 8544, !12, i64 14944, !7, i64 14952, !12, i64 21352, !7, i64 21360, !12, i64 27760, !12, i64 27764, !12, i64 27768, !7, i64 27776, !7, i64 28288, !12, i64 28800, !12, i64 28804, !12, i64 28808, !13, i64 28812, !7, i64 28816, !6, i64 29328, !7, i64 29336, !6, i64 31384, !6, i64 31392, !6, i64 31400, !11, i64 31408, !12, i64 31424}
!11 = !{!"", !6, i64 0, !6, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!15, !12, i64 20}
!15 = !{!"insn", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 20, !6, i64 24, !6, i64 32, !6, i64 40, !12, i64 48, !13, i64 52, !6, i64 56, !6, i64 64, !7, i64 72}
!16 = !{!15, !6, i64 64}
!17 = !{!18, !6, i64 8}
!18 = !{!"phi_operand", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = !{!15, !6, i64 24}
!20 = !{!18, !6, i64 0}
!21 = !{!18, !6, i64 16}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!15, !6, i64 0}
!25 = distinct !{!25, !23}
!26 = !{!10, !6, i64 8}
!27 = !{!15, !6, i64 8}


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

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

; Function Attrs: nounwind uwtable
define dso_local void @bb_unwind_phi(ptr nocapture noundef readnone %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %.01623 = load ptr, ptr %1, align 8, !tbaa !5
  %.not24 = icmp eq ptr %.01623, null
  br i1 %.not24, label %._crit_edge, label %.lr.ph26

.loopexit:                                        ; preds = %8, %5
  %.016 = load ptr, ptr %.01625, align 8, !tbaa !5
  %.not = icmp eq ptr %.016, null
  br i1 %.not, label %._crit_edge, label %.lr.ph26, !llvm.loop !9

.lr.ph26:                                         ; preds = %2, %.loopexit
  %.01625 = phi ptr [ %.016, %.loopexit ], [ %.01623, %2 ]
  %3 = getelementptr inbounds i8, ptr %.01625, i64 20
  %4 = load i32, ptr %3, align 4, !tbaa !11
  %.not17 = icmp eq i32 %4, 1
  br i1 %.not17, label %5, label %14

5:                                                ; preds = %.lr.ph26
  %6 = getelementptr inbounds i8, ptr %.01625, i64 64
  %.020 = load ptr, ptr %6, align 8, !tbaa !5
  %.not1821 = icmp eq ptr %.020, null
  br i1 %.not1821, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %7 = getelementptr inbounds i8, ptr %.01625, i64 24
  br label %8

8:                                                ; preds = %.lr.ph, %8
  %.022 = phi ptr [ %.020, %.lr.ph ], [ %.0, %8 ]
  %9 = getelementptr inbounds i8, ptr %.022, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !15
  %11 = load ptr, ptr %7, align 8, !tbaa !17
  %12 = load ptr, ptr %.022, align 8, !tbaa !18
  tail call void @append_unwound_phi_insn(ptr noundef %10, ptr noundef %11, ptr noundef %12)
  %13 = getelementptr inbounds i8, ptr %.022, i64 16
  %.0 = load ptr, ptr %13, align 8, !tbaa !5
  %.not18 = icmp eq ptr %.0, null
  br i1 %.not18, label %.loopexit, label %8, !llvm.loop !19

._crit_edge:                                      ; preds = %.loopexit, %2
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %1, i8 0, i64 16, i1 false)
  br label %16

14:                                               ; preds = %.lr.ph26
  store ptr %.01625, ptr %1, align 8, !tbaa !20
  %15 = getelementptr inbounds i8, ptr %.01625, i64 8
  store ptr null, ptr %15, align 8, !tbaa !23
  br label %16

16:                                               ; preds = %14, %._crit_edge
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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 nounwind willreturn memory(argmem: write) }

!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 = !{!12, !13, i64 20}
!12 = !{!"insn", !6, i64 0, !6, i64 8, !13, i64 16, !13, i64 20, !6, i64 24, !6, i64 32, !6, i64 40, !13, i64 48, !14, i64 52, !6, i64 56, !6, i64 64, !7, i64 72}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!16, !6, i64 8}
!16 = !{!"phi_operand", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!12, !6, i64 24}
!18 = !{!16, !6, i64 0}
!19 = distinct !{!19, !10}
!20 = !{!21, !6, i64 0}
!21 = !{!"basic_block", !22, i64 0, !22, i64 16, !7, i64 32, !6, i64 2080, !6, i64 2088, !6, i64 2096, !6, i64 2104, !6, i64 2112, !6, i64 2120, !6, i64 2128, !7, i64 2136, !13, i64 8536, !7, i64 8544, !13, i64 14944, !7, i64 14952, !13, i64 21352, !7, i64 21360, !13, i64 27760, !13, i64 27764, !13, i64 27768, !7, i64 27776, !7, i64 28288, !13, i64 28800, !13, i64 28804, !13, i64 28808, !14, i64 28812, !7, i64 28816, !6, i64 29328, !7, i64 29336, !6, i64 31384, !6, i64 31392, !6, i64 31400, !22, i64 31408, !13, i64 31424}
!22 = !{!"", !6, i64 0, !6, i64 8}
!23 = !{!12, !6, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass