; LLVM IR from CerebusOSS/CereLink :: cbhwlib/cbHwlibHi.ll (Z15AreHoopsDefinedjj)

; 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.cbHOOP = type { i16, i16, i16, i16 }

; 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: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z15AreHoopsDefinedjj(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i1, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca [5 x [4 x %struct.cbHOOP]], align 16
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 160, ptr %6) #3
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = getelementptr inbounds [5 x [4 x %struct.cbHOOP]], ptr %6, i64 0, i64 0
  %11 = getelementptr inbounds [4 x %struct.cbHOOP], ptr %10, i64 0, i64 0
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = call noundef i32 @_Z19cbGetAinpSpikeHoopsjP6cbHOOPj(i32 noundef %9, ptr noundef %11, i32 noundef %12)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %28, %2
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %16 = icmp ult i32 %15, 5
  br i1 %16, label %18, label %17

17:                                               ; preds = %14
  store i32 2, ptr %8, align 4
  br label %31

18:                                               ; preds = %14
  %19 = load i32, ptr %7, align 4, !tbaa !5
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds [5 x [4 x %struct.cbHOOP]], ptr %6, i64 0, i64 %20
  %22 = getelementptr inbounds [4 x %struct.cbHOOP], ptr %21, i64 0, i64 0
  %23 = getelementptr inbounds %struct.cbHOOP, ptr %22, i32 0, i32 0
  %24 = load i16, ptr %23, align 16, !tbaa !9
  %25 = icmp ne i16 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %18
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %31

27:                                               ; preds = %18
  br label %28

28:                                               ; preds = %27
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = add i32 %29, 1
  store i32 %30, ptr %7, align 4, !tbaa !5
  br label %14, !llvm.loop !12

31:                                               ; preds = %26, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %32 = load i32, ptr %8, align 4
  switch i32 %32, label %34 [
    i32 2, label %33
  ]

33:                                               ; preds = %31
  store i1 false, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %34

34:                                               ; preds = %33, %31
  call void @llvm.lifetime.end.p0(i64 160, ptr %6) #3
  %35 = load i1, ptr %3, align 1
  ret i1 %35
}

declare noundef i32 @_Z19cbGetAinpSpikeHoopsjP6cbHOOPj(i32 noundef, ptr noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { "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 }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS6cbHOOP", !11, i64 0, !11, i64 2, !11, i64 4, !11, i64 6}
!11 = !{!"short", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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.cbHOOP = type { i16, i16, i16, i16 }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z15AreHoopsDefinedjj(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
.critedge:
  %2 = alloca [5 x [4 x %struct.cbHOOP]], align 16
  call void @llvm.lifetime.start.p0(i64 160, ptr nonnull %2) #3
  %3 = call noundef i32 @_Z19cbGetAinpSpikeHoopsjP6cbHOOPj(i32 noundef %0, ptr noundef nonnull %2, i32 noundef %1)
  %4 = load i16, ptr %2, align 16, !tbaa !5
  %.not = icmp ne i16 %4, 0
  %5 = getelementptr inbounds i8, ptr %2, i64 32
  %6 = load i16, ptr %5, align 16
  %.not.1 = icmp ne i16 %6, 0
  %or.cond.not18 = select i1 %.not, i1 true, i1 %.not.1
  %7 = getelementptr inbounds i8, ptr %2, i64 64
  %8 = load i16, ptr %7, align 16
  %.not.2 = icmp ne i16 %8, 0
  %or.cond11.not17 = select i1 %or.cond.not18, i1 true, i1 %.not.2
  %9 = getelementptr inbounds i8, ptr %2, i64 96
  %10 = load i16, ptr %9, align 16
  %.not.3 = icmp ne i16 %10, 0
  %or.cond13.not16 = select i1 %or.cond11.not17, i1 true, i1 %.not.3
  %11 = getelementptr inbounds i8, ptr %2, i64 128
  %12 = load i16, ptr %11, align 16
  %.not.4 = icmp ne i16 %12, 0
  %or.cond15.not = select i1 %or.cond13.not16, i1 true, i1 %.not.4
  call void @llvm.lifetime.end.p0(i64 160, ptr nonnull %2) #3
  ret i1 %or.cond15.not
}

declare noundef i32 @_Z19cbGetAinpSpikeHoopsjP6cbHOOPj(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { "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 }

!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 = !{!"_ZTS6cbHOOP", !7, i64 0, !7, i64 2, !7, i64 4, !7, i64 6}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,SROAPass,SimplifyCFGPass