; LLVM IR from xuxping/codelife :: foroffer (question15)

; 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: 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
define dso_local i32 @numberOfOne1(i32 noundef %0) #1 {
  %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 1, ptr %4, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %16, %1
  %6 = load i32, ptr %4, align 4, !tbaa !5
  %7 = icmp ne i32 %6, 0
  br i1 %7, label %8, label %19

8:                                                ; preds = %5
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = and i32 %9, %10
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %13, label %16

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

16:                                               ; preds = %13, %8
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = shl i32 %17, 1
  store i32 %18, ptr %4, align 4, !tbaa !5
  br label %5, !llvm.loop !9

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

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/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 nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local i32 @numberOfOne1(i32 noundef %0) local_unnamed_addr #0 {
  %2 = and i32 %0, 1
  %3 = lshr i32 %0, 1
  %.lobit = and i32 %3, 1
  %spec.select.1 = add nuw nsw i32 %2, %.lobit
  %4 = lshr i32 %0, 2
  %.lobit10 = and i32 %4, 1
  %spec.select.2 = add nuw nsw i32 %spec.select.1, %.lobit10
  %5 = lshr i32 %0, 3
  %.lobit11 = and i32 %5, 1
  %spec.select.3 = add nuw nsw i32 %spec.select.2, %.lobit11
  %6 = lshr i32 %0, 4
  %.lobit12 = and i32 %6, 1
  %spec.select.4 = add nuw nsw i32 %spec.select.3, %.lobit12
  %7 = lshr i32 %0, 5
  %.lobit13 = and i32 %7, 1
  %spec.select.5 = add nuw nsw i32 %spec.select.4, %.lobit13
  %8 = lshr i32 %0, 6
  %.lobit14 = and i32 %8, 1
  %spec.select.6 = add nuw nsw i32 %spec.select.5, %.lobit14
  %9 = lshr i32 %0, 7
  %.lobit15 = and i32 %9, 1
  %spec.select.7 = add nuw nsw i32 %spec.select.6, %.lobit15
  %10 = lshr i32 %0, 8
  %.lobit16 = and i32 %10, 1
  %spec.select.8 = add nuw nsw i32 %spec.select.7, %.lobit16
  %11 = lshr i32 %0, 9
  %.lobit17 = and i32 %11, 1
  %spec.select.9 = add nuw nsw i32 %spec.select.8, %.lobit17
  %12 = lshr i32 %0, 10
  %.lobit18 = and i32 %12, 1
  %spec.select.10 = add nuw nsw i32 %spec.select.9, %.lobit18
  %13 = lshr i32 %0, 11
  %.lobit19 = and i32 %13, 1
  %spec.select.11 = add nuw nsw i32 %spec.select.10, %.lobit19
  %14 = lshr i32 %0, 12
  %.lobit20 = and i32 %14, 1
  %spec.select.12 = add nuw nsw i32 %spec.select.11, %.lobit20
  %15 = lshr i32 %0, 13
  %.lobit21 = and i32 %15, 1
  %spec.select.13 = add nuw nsw i32 %spec.select.12, %.lobit21
  %16 = lshr i32 %0, 14
  %.lobit22 = and i32 %16, 1
  %spec.select.14 = add nuw nsw i32 %spec.select.13, %.lobit22
  %17 = lshr i32 %0, 15
  %.lobit23 = and i32 %17, 1
  %spec.select.15 = add nuw nsw i32 %spec.select.14, %.lobit23
  %18 = lshr i32 %0, 16
  %.lobit24 = and i32 %18, 1
  %spec.select.16 = add nuw nsw i32 %spec.select.15, %.lobit24
  %19 = lshr i32 %0, 17
  %.lobit25 = and i32 %19, 1
  %spec.select.17 = add nuw nsw i32 %spec.select.16, %.lobit25
  %20 = lshr i32 %0, 18
  %.lobit26 = and i32 %20, 1
  %spec.select.18 = add nuw nsw i32 %spec.select.17, %.lobit26
  %21 = lshr i32 %0, 19
  %.lobit27 = and i32 %21, 1
  %spec.select.19 = add nuw nsw i32 %spec.select.18, %.lobit27
  %22 = lshr i32 %0, 20
  %.lobit28 = and i32 %22, 1
  %spec.select.20 = add nuw nsw i32 %spec.select.19, %.lobit28
  %23 = lshr i32 %0, 21
  %.lobit29 = and i32 %23, 1
  %spec.select.21 = add nuw nsw i32 %spec.select.20, %.lobit29
  %24 = lshr i32 %0, 22
  %.lobit30 = and i32 %24, 1
  %spec.select.22 = add nuw nsw i32 %spec.select.21, %.lobit30
  %25 = lshr i32 %0, 23
  %.lobit31 = and i32 %25, 1
  %spec.select.23 = add nuw nsw i32 %spec.select.22, %.lobit31
  %26 = lshr i32 %0, 24
  %.lobit32 = and i32 %26, 1
  %spec.select.24 = add nuw nsw i32 %spec.select.23, %.lobit32
  %27 = lshr i32 %0, 25
  %.lobit33 = and i32 %27, 1
  %spec.select.25 = add nuw nsw i32 %spec.select.24, %.lobit33
  %28 = lshr i32 %0, 26
  %.lobit34 = and i32 %28, 1
  %spec.select.26 = add nuw nsw i32 %spec.select.25, %.lobit34
  %29 = lshr i32 %0, 27
  %.lobit35 = and i32 %29, 1
  %spec.select.27 = add nuw nsw i32 %spec.select.26, %.lobit35
  %30 = lshr i32 %0, 28
  %.lobit36 = and i32 %30, 1
  %spec.select.28 = add nuw nsw i32 %spec.select.27, %.lobit36
  %31 = lshr i32 %0, 29
  %.lobit37 = and i32 %31, 1
  %spec.select.29 = add nuw nsw i32 %spec.select.28, %.lobit37
  %32 = lshr i32 %0, 30
  %.lobit38 = and i32 %32, 1
  %spec.select.30 = add nuw nsw i32 %spec.select.29, %.lobit38
  %.lobit39 = lshr i32 %0, 31
  %spec.select.31 = add nuw nsw i32 %spec.select.30, %.lobit39
  ret i32 %spec.select.31
}

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


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass