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

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

@_ZL9isAcqData = external hidden constant [9 x %struct.cbAcqSettings], align 16

; 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

declare noundef i32 @_Z17cbGetAinpSamplingjPjS_j(i32 noundef, ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z13cbGetAcqGroupjj(i32 noundef %0, i32 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = 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 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = call noundef i32 @_Z17cbGetAinpSamplingjPjS_j(i32 noundef %10, ptr noundef %6, ptr noundef %7, i32 noundef %11)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store ptr @_ZL9isAcqData, ptr %8, align 8, !tbaa !9
  br label %13

13:                                               ; preds = %36, %2
  %14 = load ptr, ptr %8, align 8, !tbaa !9
  %15 = icmp ne ptr %14, getelementptr inbounds (%struct.cbAcqSettings, ptr @_ZL9isAcqData, i64 9)
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  store i32 2, ptr %9, align 4
  br label %39

17:                                               ; preds = %13
  %18 = load ptr, ptr %8, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.cbAcqSettings, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = icmp eq i32 %20, %21
  br i1 %22, label %23, label %35

23:                                               ; preds = %17
  %24 = load ptr, ptr %8, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.cbAcqSettings, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = icmp eq i32 %26, %27
  br i1 %28, label %29, label %35

29:                                               ; preds = %23
  %30 = load ptr, ptr %8, align 8, !tbaa !9
  %31 = ptrtoint ptr %30 to i64
  %32 = sub i64 %31, ptrtoint (ptr @_ZL9isAcqData to i64)
  %33 = sdiv exact i64 %32, 8
  %34 = trunc i64 %33 to i32
  store i32 %34, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %39

35:                                               ; preds = %23, %17
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr %8, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.cbAcqSettings, ptr %37, i32 1
  store ptr %38, ptr %8, align 8, !tbaa !9
  br label %13, !llvm.loop !14

39:                                               ; preds = %29, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %40 = load i32, ptr %9, align 4
  switch i32 %40, label %45 [
    i32 2, label %41
  ]

41:                                               ; preds = %39
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = call noundef i32 @_Z13cbSetAcqGroupjjj(i32 noundef %42, i32 noundef 0, i32 noundef %43)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %45

45:                                               ; preds = %41, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %46 = load i32, ptr %3, align 4
  ret i32 %46
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z13cbSetAcqGroupjjj(i32 noundef, i32 noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS13cbAcqSettings", !6, i64 0, !6, i64 4}
!13 = !{!12, !6, i64 4}
!14 = distinct !{!14, !15}
!15 = !{!"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.cbAcqSettings = type { i32, i32 }

@_ZL9isAcqData = external hidden local_unnamed_addr constant [9 x %struct.cbAcqSettings], align 16

; 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

declare noundef i32 @_Z17cbGetAinpSamplingjPjS_j(i32 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z13cbGetAcqGroupjj(i32 noundef %0, i32 noundef %1) local_unnamed_addr #2 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  %5 = call noundef i32 @_Z17cbGetAinpSamplingjPjS_j(i32 noundef %0, ptr noundef nonnull %3, ptr noundef nonnull %4, i32 noundef %1)
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = load i32, ptr %4, align 4
  %8 = load i32, ptr @_ZL9isAcqData, align 16, !tbaa !9
  %9 = icmp eq i32 %8, %6
  %10 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL9isAcqData, i64 4), align 4
  %11 = icmp eq i32 %10, %7
  %or.cond = select i1 %9, i1 %11, i1 false
  br i1 %or.cond, label %54, label %12

12:                                               ; preds = %2
  %13 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL9isAcqData, i64 8), align 8, !tbaa !9
  %14 = icmp eq i32 %13, %6
  %15 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL9isAcqData, i64 12), align 4
  %16 = icmp eq i32 %15, %7
  %or.cond19 = select i1 %14, i1 %16, i1 false
  br i1 %or.cond19, label %54, label %17

17:                                               ; preds = %12
  %18 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL9isAcqData, i64 16), align 16, !tbaa !9
  %19 = icmp eq i32 %18, %6
  %20 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL9isAcqData, i64 20), align 4
  %21 = icmp eq i32 %20, %7
  %or.cond21 = select i1 %19, i1 %21, i1 false
  br i1 %or.cond21, label %54, label %22

22:                                               ; preds = %17
  %23 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL9isAcqData, i64 24), align 8, !tbaa !9
  %24 = icmp eq i32 %23, %6
  %25 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL9isAcqData, i64 28), align 4
  %26 = icmp eq i32 %25, %7
  %or.cond23 = select i1 %24, i1 %26, i1 false
  br i1 %or.cond23, label %54, label %27

27:                                               ; preds = %22
  %28 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL9isAcqData, i64 32), align 16, !tbaa !9
  %29 = icmp eq i32 %28, %6
  %30 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL9isAcqData, i64 36), align 4
  %31 = icmp eq i32 %30, %7
  %or.cond25 = select i1 %29, i1 %31, i1 false
  br i1 %or.cond25, label %54, label %32

32:                                               ; preds = %27
  %33 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL9isAcqData, i64 40), align 8, !tbaa !9
  %34 = icmp eq i32 %33, %6
  %35 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL9isAcqData, i64 44), align 4
  %36 = icmp eq i32 %35, %7
  %or.cond27 = select i1 %34, i1 %36, i1 false
  br i1 %or.cond27, label %54, label %37

37:                                               ; preds = %32
  %38 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL9isAcqData, i64 48), align 16, !tbaa !9
  %39 = icmp eq i32 %38, %6
  %40 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL9isAcqData, i64 52), align 4
  %41 = icmp eq i32 %40, %7
  %or.cond29 = select i1 %39, i1 %41, i1 false
  br i1 %or.cond29, label %54, label %42

42:                                               ; preds = %37
  %43 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL9isAcqData, i64 56), align 8, !tbaa !9
  %44 = icmp eq i32 %43, %6
  %45 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL9isAcqData, i64 60), align 4
  %46 = icmp eq i32 %45, %7
  %or.cond31 = select i1 %44, i1 %46, i1 false
  br i1 %or.cond31, label %54, label %47

47:                                               ; preds = %42
  %48 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL9isAcqData, i64 64), align 16, !tbaa !9
  %49 = icmp eq i32 %48, %6
  %50 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL9isAcqData, i64 68), align 4
  %51 = icmp eq i32 %50, %7
  %or.cond33 = select i1 %49, i1 %51, i1 false
  br i1 %or.cond33, label %54, label %52

52:                                               ; preds = %47
  %53 = call noundef i32 @_Z13cbSetAcqGroupjjj(i32 noundef %0, i32 noundef 0, i32 noundef %1)
  br label %54

54:                                               ; preds = %47, %42, %37, %32, %27, %22, %17, %12, %2, %52
  %.1 = phi i32 [ 0, %52 ], [ 0, %2 ], [ 1, %12 ], [ 2, %17 ], [ 3, %22 ], [ 4, %27 ], [ 5, %32 ], [ 6, %37 ], [ 7, %42 ], [ 8, %47 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  ret i32 %.1
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z13cbSetAcqGroupjjj(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,SCCPPass,SROAPass,SimplifyCFGPass