; LLVM IR from Tunghohin/Competitive_Coding :: Codeforces/cf1646_C.ll (Z9count_onex)

; 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
define dso_local noundef i64 @_Z9count_onex(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 62, ptr %4, align 4, !tbaa !9
  br label %5

5:                                                ; preds = %20, %1
  %6 = load i32, ptr %4, align 4, !tbaa !9
  %7 = icmp sge i32 %6, 0
  br i1 %7, label %9, label %8

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

9:                                                ; preds = %5
  %10 = load i64, ptr %2, align 8, !tbaa !5
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = zext i32 %11 to i64
  %13 = ashr i64 %10, %12
  %14 = and i64 %13, 1
  %15 = icmp ne i64 %14, 0
  br i1 %15, label %16, label %19

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

19:                                               ; preds = %16, %9
  br label %20

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

23:                                               ; preds = %8
  %24 = load i32, ptr %3, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i64 %25
}

; 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

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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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 noundef range(i64 -2147483648, 2147483648) i64 @_Z9count_onex(i64 noundef %0) local_unnamed_addr #0 {
vector.ph:
  %broadcast.splatinsert = insertelement <4 x i64> poison, i64 %0, i64 0
  %broadcast.splat = shufflevector <4 x i64> %broadcast.splatinsert, <4 x i64> poison, <4 x i32> zeroinitializer
  %1 = and <4 x i64> %broadcast.splat, <i64 288230376151711744, i64 144115188075855872, i64 72057594037927936, i64 36028797018963968>
  %2 = icmp ne <4 x i64> %1, zeroinitializer
  %3 = zext <4 x i1> %2 to <4 x i32>
  %4 = and <4 x i64> %broadcast.splat, <i64 1125899906842624, i64 562949953421312, i64 281474976710656, i64 140737488355328>
  %5 = icmp ne <4 x i64> %4, zeroinitializer
  %6 = zext <4 x i1> %5 to <4 x i32>
  %7 = add nuw nsw <4 x i32> %3, %6
  %8 = and <4 x i64> %broadcast.splat, <i64 4398046511104, i64 2199023255552, i64 1099511627776, i64 549755813888>
  %9 = icmp ne <4 x i64> %8, zeroinitializer
  %10 = zext <4 x i1> %9 to <4 x i32>
  %11 = add nuw nsw <4 x i32> %7, %10
  %12 = and <4 x i64> %broadcast.splat, <i64 17179869184, i64 8589934592, i64 4294967296, i64 2147483648>
  %13 = icmp ne <4 x i64> %12, zeroinitializer
  %14 = zext <4 x i1> %13 to <4 x i32>
  %15 = add nuw nsw <4 x i32> %11, %14
  %16 = and <4 x i64> %broadcast.splat, <i64 67108864, i64 33554432, i64 16777216, i64 8388608>
  %17 = icmp ne <4 x i64> %16, zeroinitializer
  %18 = zext <4 x i1> %17 to <4 x i32>
  %19 = add nuw nsw <4 x i32> %15, %18
  %20 = and <4 x i64> %broadcast.splat, <i64 262144, i64 131072, i64 65536, i64 32768>
  %21 = icmp ne <4 x i64> %20, zeroinitializer
  %22 = zext <4 x i1> %21 to <4 x i32>
  %23 = add nuw nsw <4 x i32> %19, %22
  %24 = and <4 x i64> %broadcast.splat, <i64 1024, i64 512, i64 256, i64 128>
  %25 = icmp ne <4 x i64> %24, zeroinitializer
  %26 = zext <4 x i1> %25 to <4 x i32>
  %27 = add nuw nsw <4 x i32> %23, %26
  %28 = and <4 x i64> %broadcast.splat, <i64 4611686018427387904, i64 2305843009213693952, i64 1152921504606846976, i64 576460752303423488>
  %29 = icmp ne <4 x i64> %28, zeroinitializer
  %30 = zext <4 x i1> %29 to <4 x i32>
  %31 = and <4 x i64> %broadcast.splat, <i64 18014398509481984, i64 9007199254740992, i64 4503599627370496, i64 2251799813685248>
  %32 = icmp ne <4 x i64> %31, zeroinitializer
  %33 = zext <4 x i1> %32 to <4 x i32>
  %34 = add nuw nsw <4 x i32> %30, %33
  %35 = and <4 x i64> %broadcast.splat, <i64 70368744177664, i64 35184372088832, i64 17592186044416, i64 8796093022208>
  %36 = icmp ne <4 x i64> %35, zeroinitializer
  %37 = zext <4 x i1> %36 to <4 x i32>
  %38 = add nuw nsw <4 x i32> %34, %37
  %39 = and <4 x i64> %broadcast.splat, <i64 274877906944, i64 137438953472, i64 68719476736, i64 34359738368>
  %40 = icmp ne <4 x i64> %39, zeroinitializer
  %41 = zext <4 x i1> %40 to <4 x i32>
  %42 = add nuw nsw <4 x i32> %38, %41
  %43 = and <4 x i64> %broadcast.splat, <i64 1073741824, i64 536870912, i64 268435456, i64 134217728>
  %44 = icmp ne <4 x i64> %43, zeroinitializer
  %45 = zext <4 x i1> %44 to <4 x i32>
  %46 = add nuw nsw <4 x i32> %42, %45
  %47 = and <4 x i64> %broadcast.splat, <i64 4194304, i64 2097152, i64 1048576, i64 524288>
  %48 = icmp ne <4 x i64> %47, zeroinitializer
  %49 = zext <4 x i1> %48 to <4 x i32>
  %50 = add nuw nsw <4 x i32> %46, %49
  %51 = and <4 x i64> %broadcast.splat, <i64 16384, i64 8192, i64 4096, i64 2048>
  %52 = icmp ne <4 x i64> %51, zeroinitializer
  %53 = zext <4 x i1> %52 to <4 x i32>
  %54 = add nuw nsw <4 x i32> %50, %53
  %bin.rdx = add <4 x i32> %27, %54
  %55 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %56 = trunc i64 %0 to i32
  %57 = lshr i32 %56, 6
  %58 = and i32 %57, 1
  %spec.select = add nuw nsw i32 %55, %58
  %59 = trunc i64 %0 to i32
  %60 = lshr i32 %59, 5
  %61 = and i32 %60, 1
  %spec.select.1 = add nuw nsw i32 %spec.select, %61
  %62 = trunc i64 %0 to i32
  %63 = lshr i32 %62, 4
  %64 = and i32 %63, 1
  %spec.select.2 = add nuw nsw i32 %spec.select.1, %64
  %65 = trunc i64 %0 to i32
  %66 = lshr i32 %65, 3
  %67 = and i32 %66, 1
  %spec.select.3 = add nuw nsw i32 %spec.select.2, %67
  %68 = trunc i64 %0 to i32
  %69 = lshr i32 %68, 2
  %70 = and i32 %69, 1
  %spec.select.4 = add nuw nsw i32 %spec.select.3, %70
  %71 = trunc i64 %0 to i32
  %72 = lshr i32 %71, 1
  %73 = and i32 %72, 1
  %spec.select.5 = add nuw nsw i32 %spec.select.4, %73
  %74 = trunc i64 %0 to i32
  %75 = and i32 %74, 1
  %spec.select.6 = add nuw nsw i32 %spec.select.5, %75
  %76 = zext nneg i32 %spec.select.6 to i64
  ret i64 %76
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #1

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" }
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,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass