; LLVM IR from JessonYue/LeetCodeLearning :: Array/wuchao/other/8-6 交替位二进制数 (HasAlternatingBits)

; 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: nounwind uwtable
define dso_local zeroext i1 @hasAlternatingBits(i32 noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca i32, align 4
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = and i32 %7, 1
  %9 = icmp sgt i32 %8, 0
  %10 = zext i1 %9 to i8
  store i8 %10, ptr %4, align 1, !tbaa !9
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = ashr i32 %11, 1
  store i32 %12, ptr %3, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %39, %1
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %40

16:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = and i32 %17, 1
  store i32 %18, ptr %5, align 4, !tbaa !5
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = icmp sgt i32 %19, 0
  br i1 %20, label %21, label %24

21:                                               ; preds = %16
  %22 = load i8, ptr %4, align 1, !tbaa !9, !range !11, !noundef !12
  %23 = trunc i8 %22 to i1
  br i1 %23, label %30, label %24

24:                                               ; preds = %21, %16
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %31

27:                                               ; preds = %24
  %28 = load i8, ptr %4, align 1, !tbaa !9, !range !11, !noundef !12
  %29 = trunc i8 %28 to i1
  br i1 %29, label %31, label %30

30:                                               ; preds = %27, %21
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %37

31:                                               ; preds = %27, %24
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = icmp sgt i32 %32, 0
  %34 = zext i1 %33 to i8
  store i8 %34, ptr %4, align 1, !tbaa !9
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = ashr i32 %35, 1
  store i32 %36, ptr %3, align 4, !tbaa !5
  store i32 0, ptr %6, align 4
  br label %37

37:                                               ; preds = %31, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  %38 = load i32, ptr %6, align 4
  switch i32 %38, label %41 [
    i32 0, label %39
  ]

39:                                               ; preds = %37
  br label %13, !llvm.loop !13

40:                                               ; preds = %13
  store i1 true, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %41

41:                                               ; preds = %40, %37
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  %42 = load i1, ptr %2, align 1
  ret i1 %42
}

; 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"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: nofree norecurse nosync nounwind memory(none) uwtable
define dso_local noundef zeroext i1 @hasAlternatingBits(i32 noundef %0) local_unnamed_addr #0 {
  %.not22 = icmp ult i32 %0, 2
  br i1 %.not22, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %1, %6
  %.01424.in = phi i32 [ %.01424, %6 ], [ %0, %1 ]
  %.01223.in = phi i32 [ %2, %6 ], [ %0, %1 ]
  %.01424 = ashr i32 %.01424.in, 1
  %2 = and i32 %.01424, 1
  %cond17 = icmp eq i32 %2, 0
  %3 = trunc i32 %.01223.in to i1
  br i1 %cond17, label %5, label %4

4:                                                ; preds = %.lr.ph
  br i1 %3, label %.thread, label %6

5:                                                ; preds = %.lr.ph
  br i1 %3, label %6, label %.thread

6:                                                ; preds = %5, %4
  %.not = icmp ult i32 %.01424, 2
  br i1 %.not, label %.thread, label %.lr.ph, !llvm.loop !5

.thread:                                          ; preds = %6, %5, %4, %1
  %.not.lcssa = phi i1 [ true, %1 ], [ false, %4 ], [ false, %5 ], [ true, %6 ]
  ret i1 %.not.lcssa
}

attributes #0 = { nofree norecurse nosync nounwind 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)"}
!5 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass