; LLVM IR from ShahjalalShohag/code-library :: Basics/Bitwise Operations.ll (Z13count_on_bitsi)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z13check_kth_bitii(i32 noundef, i32 noundef) #0

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

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

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

5:                                                ; preds = %18, %1
  %6 = load i32, ptr %4, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 32
  br i1 %7, label %9, label %8

8:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %21

9:                                                ; preds = %5
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = call noundef i32 @_Z13check_kth_bitii(i32 noundef %10, i32 noundef %11)
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %17

14:                                               ; preds = %9
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %3, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %14, %9
  br label %18

18:                                               ; preds = %17
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %4, align 4, !tbaa !5
  br label %5, !llvm.loop !9

21:                                               ; preds = %8
  %22 = load i32, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %22
}

attributes #0 = { mustprogress 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 nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z13count_on_bitsi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 0)
  %3 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 1)
  %4 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 2)
  %5 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 3)
  %6 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 4)
  %7 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 5)
  %8 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 6)
  %9 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 7)
  %10 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 8)
  %11 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 9)
  %12 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 10)
  %13 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 11)
  %14 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 12)
  %15 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 13)
  %16 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 14)
  %17 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 15)
  %18 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 16)
  %19 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 17)
  %20 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 18)
  %21 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 19)
  %22 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 20)
  %23 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 21)
  %24 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 22)
  %25 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 23)
  %26 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 24)
  %27 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 25)
  %28 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 26)
  %29 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 27)
  %30 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 28)
  %31 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 29)
  %32 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 30)
  %33 = tail call noundef i32 @_Z13check_kth_bitii(i32 noundef %0, i32 noundef 31)
  %34 = insertelement <32 x i32> poison, i32 %2, i64 0
  %35 = insertelement <32 x i32> %34, i32 %3, i64 1
  %36 = insertelement <32 x i32> %35, i32 %4, i64 2
  %37 = insertelement <32 x i32> %36, i32 %5, i64 3
  %38 = insertelement <32 x i32> %37, i32 %6, i64 4
  %39 = insertelement <32 x i32> %38, i32 %7, i64 5
  %40 = insertelement <32 x i32> %39, i32 %8, i64 6
  %41 = insertelement <32 x i32> %40, i32 %9, i64 7
  %42 = insertelement <32 x i32> %41, i32 %10, i64 8
  %43 = insertelement <32 x i32> %42, i32 %11, i64 9
  %44 = insertelement <32 x i32> %43, i32 %12, i64 10
  %45 = insertelement <32 x i32> %44, i32 %13, i64 11
  %46 = insertelement <32 x i32> %45, i32 %14, i64 12
  %47 = insertelement <32 x i32> %46, i32 %15, i64 13
  %48 = insertelement <32 x i32> %47, i32 %16, i64 14
  %49 = insertelement <32 x i32> %48, i32 %17, i64 15
  %50 = insertelement <32 x i32> %49, i32 %18, i64 16
  %51 = insertelement <32 x i32> %50, i32 %19, i64 17
  %52 = insertelement <32 x i32> %51, i32 %20, i64 18
  %53 = insertelement <32 x i32> %52, i32 %21, i64 19
  %54 = insertelement <32 x i32> %53, i32 %22, i64 20
  %55 = insertelement <32 x i32> %54, i32 %23, i64 21
  %56 = insertelement <32 x i32> %55, i32 %24, i64 22
  %57 = insertelement <32 x i32> %56, i32 %25, i64 23
  %58 = insertelement <32 x i32> %57, i32 %26, i64 24
  %59 = insertelement <32 x i32> %58, i32 %27, i64 25
  %60 = insertelement <32 x i32> %59, i32 %28, i64 26
  %61 = insertelement <32 x i32> %60, i32 %29, i64 27
  %62 = insertelement <32 x i32> %61, i32 %30, i64 28
  %63 = insertelement <32 x i32> %62, i32 %31, i64 29
  %64 = insertelement <32 x i32> %63, i32 %32, i64 30
  %65 = insertelement <32 x i32> %64, i32 %33, i64 31
  %66 = icmp ne <32 x i32> %65, zeroinitializer
  %67 = bitcast <32 x i1> %66 to i32
  %68 = tail call range(i32 0, 33) i32 @llvm.ctpop.i32(i32 %67)
  ret i32 %68
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.ctpop.i32(i32) #1

attributes #0 = { mustprogress 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 nosync nounwind speculatable willreturn memory(none) }

!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)"}


; Effective O3 passes: GVNPass,GlobalDCEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass