; 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.block = type { [1600 x %struct.var], i32, ptr, ptr, ptr, 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 }

@BB_ARENA = external dso_local global ptr, 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 ptr @arena_alloc(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @bb_create(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %5 = load ptr, ptr @BB_ARENA, align 8, !tbaa !5
  %6 = call ptr @arena_alloc(ptr noundef %5, i32 noundef 31432)
  store ptr %6, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %24, %1
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = icmp slt i32 %8, 128
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %27

11:                                               ; preds = %7
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.basic_block, ptr %12, i32 0, i32 2
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [128 x %struct.bb_connection_t], ptr %13, i64 0, i64 %15
  %17 = getelementptr inbounds %struct.bb_connection_t, ptr %16, i32 0, i32 0
  store ptr null, ptr %17, align 8, !tbaa !11
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.basic_block, ptr %18, i32 0, i32 2
  %20 = load i32, ptr %4, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [128 x %struct.bb_connection_t], ptr %19, i64 0, i64 %21
  %23 = getelementptr inbounds %struct.bb_connection_t, ptr %22, i32 0, i32 1
  store i32 0, ptr %23, align 8, !tbaa !13
  br label %24

24:                                               ; preds = %11
  %25 = load i32, ptr %4, align 4, !tbaa !9
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %4, align 4, !tbaa !9
  br label %7, !llvm.loop !14

27:                                               ; preds = %10
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.basic_block, ptr %29, i32 0, i32 31
  store ptr %28, ptr %30, align 8, !tbaa !16
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.block, ptr %31, i32 0, i32 3
  %33 = load ptr, ptr %32, align 8, !tbaa !20
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.basic_block, ptr %34, i32 0, i32 30
  store ptr %33, ptr %35, align 8, !tbaa !22
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret ptr %36
}

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"", !6, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !6, i64 31400}
!17 = !{!"basic_block", !18, i64 0, !18, 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, !10, i64 8536, !7, i64 8544, !10, i64 14944, !7, i64 14952, !10, i64 21352, !7, i64 21360, !10, i64 27760, !10, i64 27764, !10, i64 27768, !7, i64 27776, !7, i64 28288, !10, i64 28800, !10, i64 28804, !10, i64 28808, !19, i64 28812, !7, i64 28816, !6, i64 29328, !7, i64 29336, !6, i64 31384, !6, i64 31392, !6, i64 31400, !18, i64 31408, !10, i64 31424}
!18 = !{!"", !6, i64 0, !6, i64 8}
!19 = !{!"_Bool", !7, i64 0}
!20 = !{!21, !6, i64 1510416}
!21 = !{!"block", !7, i64 0, !10, i64 1510400, !6, i64 1510408, !6, i64 1510416, !6, i64 1510424, !10, i64 1510432, !6, i64 1510440}
!22 = !{!17, !6, i64 31392}


; 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.bb_connection_t = type { ptr, i32 }

@BB_ARENA = external dso_local local_unnamed_addr global ptr, align 8

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

; Function Attrs: nounwind uwtable
define dso_local ptr @bb_create(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @BB_ARENA, align 8, !tbaa !5
  %3 = tail call ptr @arena_alloc(ptr noundef %2, i32 noundef 31432)
  %4 = getelementptr inbounds i8, ptr %3, i64 32
  br label %10

5:                                                ; preds = %10
  %6 = getelementptr inbounds i8, ptr %3, i64 31400
  store ptr %0, ptr %6, align 8, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %0, i64 1510416
  %8 = load ptr, ptr %7, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %3, i64 31392
  store ptr %8, ptr %9, align 8, !tbaa !16
  ret ptr %3

10:                                               ; preds = %10, %1
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next.3, %10 ]
  %11 = getelementptr inbounds [128 x %struct.bb_connection_t], ptr %4, i64 0, i64 %indvars.iv
  store ptr null, ptr %11, align 8, !tbaa !17
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  store i32 0, ptr %12, align 8, !tbaa !19
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %13 = getelementptr inbounds [128 x %struct.bb_connection_t], ptr %4, i64 0, i64 %indvars.iv.next
  store ptr null, ptr %13, align 8, !tbaa !17
  %14 = getelementptr inbounds i8, ptr %13, i64 8
  store i32 0, ptr %14, align 8, !tbaa !19
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %15 = getelementptr inbounds [128 x %struct.bb_connection_t], ptr %4, i64 0, i64 %indvars.iv.next.1
  store ptr null, ptr %15, align 8, !tbaa !17
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  store i32 0, ptr %16, align 8, !tbaa !19
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %17 = getelementptr inbounds [128 x %struct.bb_connection_t], ptr %4, i64 0, i64 %indvars.iv.next.2
  store ptr null, ptr %17, align 8, !tbaa !17
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  store i32 0, ptr %18, align 8, !tbaa !19
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, 128
  br i1 %exitcond.not.3, label %5, label %10, !llvm.loop !20
}

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 = !{!10, !6, i64 31400}
!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, !6, i64 1510416}
!15 = !{!"block", !7, i64 0, !12, i64 1510400, !6, i64 1510408, !6, i64 1510416, !6, i64 1510424, !12, i64 1510432, !6, i64 1510440}
!16 = !{!10, !6, i64 31392}
!17 = !{!18, !6, i64 0}
!18 = !{!"", !6, i64 0, !12, i64 8}
!19 = !{!18, !12, i64 8}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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