; LLVM IR from xirc/cp-algorithm :: codeforces/1420/1420B/main.ll (Z15highest_one_biti)

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

@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [82 x i8], align 1
@__PRETTY_FUNCTION__._Z15highest_one_biti = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z15highest_one_biti(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = icmp sge i32 %6, 0
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  br label %11

9:                                                ; preds = %1
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 7, ptr noundef @__PRETTY_FUNCTION__._Z15highest_one_biti) #3
  unreachable

10:                                               ; No predecessors!
  br label %11

11:                                               ; preds = %10, %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 30, ptr %4, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %25, %11
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = icmp sge i32 %13, 0
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  store i32 2, ptr %5, align 4
  br label %28

16:                                               ; preds = %12
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = ashr i32 %17, %18
  %20 = and i32 %19, 1
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %16
  %23 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %23, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %28

24:                                               ; preds = %16
  br label %25

25:                                               ; preds = %24
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = add nsw i32 %26, -1
  store i32 %27, ptr %4, align 4, !tbaa !5
  br label %12, !llvm.loop !9

28:                                               ; preds = %22, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %29 = load i32, ptr %5, align 4
  switch i32 %29, label %33 [
    i32 2, label %30
    i32 1, label %31
  ]

30:                                               ; preds = %28
  store i32 -1, ptr %2, align 4
  br label %31

31:                                               ; preds = %30, %28
  %32 = load i32, ptr %2, align 4
  ret i32 %32

33:                                               ; preds = %28
  unreachable
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

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

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 = { noreturn nounwind "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { noreturn nounwind }
attributes #4 = { 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"

@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [82 x i8], align 1
@__PRETTY_FUNCTION__._Z15highest_one_biti = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z15highest_one_biti(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp sgt i32 %0, -1
  br i1 %2, label %.preheader.preheader, label %3

.preheader.preheader:                             ; preds = %1
  %.not = icmp ult i32 %0, 1073741824
  br i1 %.not, label %.preheader.1, label %.preheader.30

3:                                                ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 7, ptr noundef nonnull @__PRETTY_FUNCTION__._Z15highest_one_biti) #2
  unreachable

.preheader.1:                                     ; preds = %.preheader.preheader
  %.not.1 = icmp ult i32 %0, 536870912
  br i1 %.not.1, label %.preheader.2, label %.preheader.30

.preheader.2:                                     ; preds = %.preheader.1
  %.not.2 = icmp ult i32 %0, 268435456
  br i1 %.not.2, label %.preheader.3, label %.preheader.30

.preheader.3:                                     ; preds = %.preheader.2
  %.not.3 = icmp ult i32 %0, 134217728
  br i1 %.not.3, label %.preheader.4, label %.preheader.30

.preheader.4:                                     ; preds = %.preheader.3
  %.not.4 = icmp ult i32 %0, 67108864
  br i1 %.not.4, label %.preheader.5, label %.preheader.30

.preheader.5:                                     ; preds = %.preheader.4
  %.not.5 = icmp ult i32 %0, 33554432
  br i1 %.not.5, label %.preheader.6, label %.preheader.30

.preheader.6:                                     ; preds = %.preheader.5
  %.not.6 = icmp ult i32 %0, 16777216
  br i1 %.not.6, label %.preheader.7, label %.preheader.30

.preheader.7:                                     ; preds = %.preheader.6
  %.not.7 = icmp ult i32 %0, 8388608
  br i1 %.not.7, label %.preheader.8, label %.preheader.30

.preheader.8:                                     ; preds = %.preheader.7
  %.not.8 = icmp ult i32 %0, 4194304
  br i1 %.not.8, label %.preheader.9, label %.preheader.30

.preheader.9:                                     ; preds = %.preheader.8
  %.not.9 = icmp ult i32 %0, 2097152
  br i1 %.not.9, label %.preheader.10, label %.preheader.30

.preheader.10:                                    ; preds = %.preheader.9
  %.not.10 = icmp ult i32 %0, 1048576
  br i1 %.not.10, label %.preheader.11, label %.preheader.30

.preheader.11:                                    ; preds = %.preheader.10
  %.not.11 = icmp ult i32 %0, 524288
  br i1 %.not.11, label %.preheader.12, label %.preheader.30

.preheader.12:                                    ; preds = %.preheader.11
  %.not.12 = icmp ult i32 %0, 262144
  br i1 %.not.12, label %.preheader.13, label %.preheader.30

.preheader.13:                                    ; preds = %.preheader.12
  %.not.13 = icmp ult i32 %0, 131072
  br i1 %.not.13, label %.preheader.14, label %.preheader.30

.preheader.14:                                    ; preds = %.preheader.13
  %.not.14 = icmp ult i32 %0, 65536
  br i1 %.not.14, label %.preheader.15, label %.preheader.30

.preheader.15:                                    ; preds = %.preheader.14
  %.not.15 = icmp ult i32 %0, 32768
  br i1 %.not.15, label %.preheader.16, label %.preheader.30

.preheader.16:                                    ; preds = %.preheader.15
  %.not.16 = icmp ult i32 %0, 16384
  br i1 %.not.16, label %.preheader.17, label %.preheader.30

.preheader.17:                                    ; preds = %.preheader.16
  %.not.17 = icmp ult i32 %0, 8192
  br i1 %.not.17, label %.preheader.18, label %.preheader.30

.preheader.18:                                    ; preds = %.preheader.17
  %.not.18 = icmp ult i32 %0, 4096
  br i1 %.not.18, label %.preheader.19, label %.preheader.30

.preheader.19:                                    ; preds = %.preheader.18
  %.not.19 = icmp ult i32 %0, 2048
  br i1 %.not.19, label %.preheader.20, label %.preheader.30

.preheader.20:                                    ; preds = %.preheader.19
  %.not.20 = icmp ult i32 %0, 1024
  br i1 %.not.20, label %.preheader.21, label %.preheader.30

.preheader.21:                                    ; preds = %.preheader.20
  %.not.21 = icmp ult i32 %0, 512
  br i1 %.not.21, label %.preheader.22, label %.preheader.30

.preheader.22:                                    ; preds = %.preheader.21
  %.not.22 = icmp ult i32 %0, 256
  br i1 %.not.22, label %.preheader.23, label %.preheader.30

.preheader.23:                                    ; preds = %.preheader.22
  %.not.23 = icmp ult i32 %0, 128
  br i1 %.not.23, label %.preheader.24, label %.preheader.30

.preheader.24:                                    ; preds = %.preheader.23
  %.not.24 = icmp ult i32 %0, 64
  br i1 %.not.24, label %.preheader.25, label %.preheader.30

.preheader.25:                                    ; preds = %.preheader.24
  %.not.25 = icmp ult i32 %0, 32
  br i1 %.not.25, label %.preheader.26, label %.preheader.30

.preheader.26:                                    ; preds = %.preheader.25
  %.not.26 = icmp ult i32 %0, 16
  br i1 %.not.26, label %.preheader.27, label %.preheader.30

.preheader.27:                                    ; preds = %.preheader.26
  %.not.27 = icmp ult i32 %0, 8
  br i1 %.not.27, label %.preheader.28, label %.preheader.30

.preheader.28:                                    ; preds = %.preheader.27
  %.not.28 = icmp ult i32 %0, 4
  br i1 %.not.28, label %.preheader.29, label %.preheader.30

.preheader.29:                                    ; preds = %.preheader.28
  %sext = add nsw i32 %0, -1
  %.not.29.inv = icmp ugt i32 %0, 1
  %spec.select13 = select i1 %.not.29.inv, i32 1, i32 %sext
  br label %.preheader.30

.preheader.30:                                    ; preds = %.preheader.29, %.preheader.28, %.preheader.27, %.preheader.26, %.preheader.25, %.preheader.24, %.preheader.23, %.preheader.22, %.preheader.21, %.preheader.20, %.preheader.19, %.preheader.18, %.preheader.17, %.preheader.16, %.preheader.15, %.preheader.14, %.preheader.13, %.preheader.12, %.preheader.11, %.preheader.10, %.preheader.9, %.preheader.8, %.preheader.7, %.preheader.6, %.preheader.5, %.preheader.4, %.preheader.3, %.preheader.2, %.preheader.1, %.preheader.preheader
  %spec.select = phi i32 [ 30, %.preheader.preheader ], [ 29, %.preheader.1 ], [ 28, %.preheader.2 ], [ 27, %.preheader.3 ], [ 26, %.preheader.4 ], [ 25, %.preheader.5 ], [ 24, %.preheader.6 ], [ 23, %.preheader.7 ], [ 22, %.preheader.8 ], [ 21, %.preheader.9 ], [ 20, %.preheader.10 ], [ 19, %.preheader.11 ], [ 18, %.preheader.12 ], [ 17, %.preheader.13 ], [ 16, %.preheader.14 ], [ 15, %.preheader.15 ], [ 14, %.preheader.16 ], [ 13, %.preheader.17 ], [ 12, %.preheader.18 ], [ 11, %.preheader.19 ], [ 10, %.preheader.20 ], [ 9, %.preheader.21 ], [ 8, %.preheader.22 ], [ 7, %.preheader.23 ], [ 6, %.preheader.24 ], [ 5, %.preheader.25 ], [ 4, %.preheader.26 ], [ 3, %.preheader.27 ], [ 2, %.preheader.28 ], [ %spec.select13, %.preheader.29 ]
  ret i32 %spec.select
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #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 = { noreturn nounwind "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 = { noreturn 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)"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass