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

; 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: noreturn nounwind
declare void @abort() #1

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

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

10:                                               ; preds = %7
  store i32 2, ptr %6, align 4
  br label %50

11:                                               ; preds = %7
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.basic_block, ptr %12, i32 0, i32 2
  %14 = load i32, ptr %5, 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
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = icmp eq ptr %18, %19
  br i1 %20, label %21, label %46

21:                                               ; preds = %11
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.basic_block, ptr %22, i32 0, i32 2
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [128 x %struct.bb_connection_t], ptr %23, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.bb_connection_t, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 8, !tbaa !13
  switch i32 %28, label %38 [
    i32 0, label %29
    i32 2, label %32
    i32 1, label %35
  ]

29:                                               ; preds = %21
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.basic_block, ptr %30, i32 0, i32 3
  store ptr null, ptr %31, align 8, !tbaa !14
  br label %39

32:                                               ; preds = %21
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.basic_block, ptr %33, i32 0, i32 4
  store ptr null, ptr %34, align 8, !tbaa !18
  br label %39

35:                                               ; preds = %21
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.basic_block, ptr %36, i32 0, i32 5
  store ptr null, ptr %37, align 8, !tbaa !19
  br label %39

38:                                               ; preds = %21
  call void @abort() #4
  unreachable

39:                                               ; preds = %35, %32, %29
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.basic_block, ptr %40, i32 0, i32 2
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [128 x %struct.bb_connection_t], ptr %41, i64 0, i64 %43
  %45 = getelementptr inbounds %struct.bb_connection_t, ptr %44, i32 0, i32 0
  store ptr null, ptr %45, align 8, !tbaa !11
  store i32 2, ptr %6, align 4
  br label %50

46:                                               ; preds = %11
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %5, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %5, align 4, !tbaa !9
  br label %7, !llvm.loop !20

50:                                               ; preds = %39, %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %51

51:                                               ; preds = %50
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 #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 }
attributes #4 = { noreturn 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 = !{!15, !6, i64 2080}
!15 = !{!"basic_block", !16, i64 0, !16, 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, !17, i64 28812, !7, i64 28816, !6, i64 29328, !7, i64 29336, !6, i64 31384, !6, i64 31392, !6, i64 31400, !16, i64 31408, !10, i64 31424}
!16 = !{!"", !6, i64 0, !6, i64 8}
!17 = !{!"_Bool", !7, i64 0}
!18 = !{!15, !6, i64 2088}
!19 = !{!15, !6, i64 2096}
!20 = distinct !{!20, !21}
!21 = !{!"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.bb_connection_t = type { ptr, i32 }

@switch.table.bb_disconnect = private unnamed_addr constant [3 x i64] [i64 2080, i64 2096, i64 2088], align 8

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @bb_disconnect(ptr noundef writeonly %0, ptr nocapture noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %1, i64 32
  br label %17

4:                                                ; preds = %17
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %5 = getelementptr inbounds [128 x %struct.bb_connection_t], ptr %3, i64 0, i64 %indvars.iv.next
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = icmp eq ptr %6, %0
  br i1 %7, label %21, label %8

8:                                                ; preds = %4
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %9 = getelementptr inbounds [128 x %struct.bb_connection_t], ptr %3, i64 0, i64 %indvars.iv.next.1
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = icmp eq ptr %10, %0
  br i1 %11, label %21, label %12

12:                                               ; preds = %8
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %13 = getelementptr inbounds [128 x %struct.bb_connection_t], ptr %3, i64 0, i64 %indvars.iv.next.2
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = icmp eq ptr %14, %0
  br i1 %15, label %21, label %16

16:                                               ; preds = %12
  %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 %.loopexit, label %17, !llvm.loop !11

17:                                               ; preds = %16, %2
  %indvars.iv = phi i64 [ 0, %2 ], [ %indvars.iv.next.3, %16 ]
  %18 = getelementptr inbounds [128 x %struct.bb_connection_t], ptr %3, i64 0, i64 %indvars.iv
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = icmp eq ptr %19, %0
  br i1 %20, label %21, label %4

21:                                               ; preds = %12, %8, %4, %17
  %.lcssa = phi ptr [ %18, %17 ], [ %5, %4 ], [ %9, %8 ], [ %13, %12 ]
  %22 = getelementptr inbounds i8, ptr %.lcssa, i64 8
  %23 = load i32, ptr %22, align 8, !tbaa !13
  %24 = icmp ult i32 %23, 3
  br i1 %24, label %switch.lookup, label %25

25:                                               ; preds = %21
  tail call void @abort() #2
  unreachable

switch.lookup:                                    ; preds = %21
  %26 = zext nneg i32 %23 to i64
  %switch.gep = getelementptr inbounds [3 x i64], ptr @switch.table.bb_disconnect, i64 0, i64 %26
  %switch.load = load i64, ptr %switch.gep, align 8
  %27 = getelementptr inbounds i8, ptr %0, i64 %switch.load
  store ptr null, ptr %27, align 8, !tbaa !14
  store ptr null, ptr %.lcssa, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %16, %switch.lookup
  ret void
}

attributes #0 = { noreturn 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 #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 = { noreturn 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, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!6, !10, i64 8}
!14 = !{!7, !7, i64 0}


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