; LLVM IR from ravireddy07/cpp-book :: src/Code-Chef/OCT2020-Long/SEGCOMPR.ll (Z6mx_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"

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z6mx_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 eq i32 %6, 0
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  store i32 0, ptr %2, align 4
  br label %30

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

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

13:                                               ; preds = %10
  store i32 2, ptr %5, align 4
  br label %27

14:                                               ; preds = %10
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = ashr i32 %15, %16
  %18 = and i32 %17, 1
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %23

20:                                               ; preds = %14
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = shl i32 1, %21
  store i32 %22, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %27

23:                                               ; preds = %14
  br label %24

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

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

29:                                               ; preds = %27
  call void @__cxa_rethrow() #3
  unreachable

30:                                               ; preds = %27, %8
  %31 = load i32, ptr %2, align 4
  ret i32 %31

32:                                               ; preds = %27
  unreachable
}

; 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

declare void @__cxa_rethrow()

attributes #0 = { mustprogress 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 }
attributes #3 = { noreturn }

!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 uwtable
define dso_local noundef i32 @_Z6mx_biti(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq i32 %0, 0
  br i1 %2, label %.loopexit, label %.preheader.preheader

.preheader.preheader:                             ; preds = %1
  %3 = and i32 %0, 1073741824
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %.preheader.1, label %.loopexit

.preheader.1:                                     ; preds = %.preheader.preheader
  %4 = and i32 %0, 536870912
  %.not.1 = icmp eq i32 %4, 0
  br i1 %.not.1, label %.preheader.2, label %.loopexit

.preheader.2:                                     ; preds = %.preheader.1
  %5 = and i32 %0, 268435456
  %.not.2 = icmp eq i32 %5, 0
  br i1 %.not.2, label %.preheader.3, label %.loopexit

.preheader.3:                                     ; preds = %.preheader.2
  %6 = and i32 %0, 134217728
  %.not.3 = icmp eq i32 %6, 0
  br i1 %.not.3, label %.preheader.4, label %.loopexit

.preheader.4:                                     ; preds = %.preheader.3
  %7 = and i32 %0, 67108864
  %.not.4 = icmp eq i32 %7, 0
  br i1 %.not.4, label %.preheader.5, label %.loopexit

.preheader.5:                                     ; preds = %.preheader.4
  %8 = and i32 %0, 33554432
  %.not.5 = icmp eq i32 %8, 0
  br i1 %.not.5, label %.preheader.6, label %.loopexit

.preheader.6:                                     ; preds = %.preheader.5
  %9 = and i32 %0, 16777216
  %.not.6 = icmp eq i32 %9, 0
  br i1 %.not.6, label %.preheader.7, label %.loopexit

.preheader.7:                                     ; preds = %.preheader.6
  %10 = and i32 %0, 8388608
  %.not.7 = icmp eq i32 %10, 0
  br i1 %.not.7, label %.preheader.8, label %.loopexit

.preheader.8:                                     ; preds = %.preheader.7
  %11 = and i32 %0, 4194304
  %.not.8 = icmp eq i32 %11, 0
  br i1 %.not.8, label %.preheader.9, label %.loopexit

.preheader.9:                                     ; preds = %.preheader.8
  %12 = and i32 %0, 2097152
  %.not.9 = icmp eq i32 %12, 0
  br i1 %.not.9, label %.preheader.10, label %.loopexit

.preheader.10:                                    ; preds = %.preheader.9
  %13 = and i32 %0, 1048576
  %.not.10 = icmp eq i32 %13, 0
  br i1 %.not.10, label %.preheader.11, label %.loopexit

.preheader.11:                                    ; preds = %.preheader.10
  %14 = and i32 %0, 524288
  %.not.11 = icmp eq i32 %14, 0
  br i1 %.not.11, label %.preheader.12, label %.loopexit

.preheader.12:                                    ; preds = %.preheader.11
  %15 = and i32 %0, 262144
  %.not.12 = icmp eq i32 %15, 0
  br i1 %.not.12, label %.preheader.13, label %.loopexit

.preheader.13:                                    ; preds = %.preheader.12
  %16 = and i32 %0, 131072
  %.not.13 = icmp eq i32 %16, 0
  br i1 %.not.13, label %.preheader.14, label %.loopexit

.preheader.14:                                    ; preds = %.preheader.13
  %17 = and i32 %0, 65536
  %.not.14 = icmp eq i32 %17, 0
  br i1 %.not.14, label %.preheader.15, label %.loopexit

.preheader.15:                                    ; preds = %.preheader.14
  %18 = and i32 %0, 32768
  %.not.15 = icmp eq i32 %18, 0
  br i1 %.not.15, label %.preheader.16, label %.loopexit

.preheader.16:                                    ; preds = %.preheader.15
  %19 = and i32 %0, 16384
  %.not.16 = icmp eq i32 %19, 0
  br i1 %.not.16, label %.preheader.17, label %.loopexit

.preheader.17:                                    ; preds = %.preheader.16
  %20 = and i32 %0, 8192
  %.not.17 = icmp eq i32 %20, 0
  br i1 %.not.17, label %.preheader.18, label %.loopexit

.preheader.18:                                    ; preds = %.preheader.17
  %21 = and i32 %0, 4096
  %.not.18 = icmp eq i32 %21, 0
  br i1 %.not.18, label %.preheader.19, label %.loopexit

.preheader.19:                                    ; preds = %.preheader.18
  %22 = and i32 %0, 2048
  %.not.19 = icmp eq i32 %22, 0
  br i1 %.not.19, label %.preheader.20, label %.loopexit

.preheader.20:                                    ; preds = %.preheader.19
  %23 = and i32 %0, 1024
  %.not.20 = icmp eq i32 %23, 0
  br i1 %.not.20, label %.preheader.21, label %.loopexit

.preheader.21:                                    ; preds = %.preheader.20
  %24 = and i32 %0, 512
  %.not.21 = icmp eq i32 %24, 0
  br i1 %.not.21, label %.preheader.22, label %.loopexit

.preheader.22:                                    ; preds = %.preheader.21
  %25 = and i32 %0, 256
  %.not.22 = icmp eq i32 %25, 0
  br i1 %.not.22, label %.preheader.23, label %.loopexit

.preheader.23:                                    ; preds = %.preheader.22
  %26 = and i32 %0, 128
  %.not.23 = icmp eq i32 %26, 0
  br i1 %.not.23, label %.preheader.24, label %.loopexit

.preheader.24:                                    ; preds = %.preheader.23
  %27 = and i32 %0, 64
  %.not.24 = icmp eq i32 %27, 0
  br i1 %.not.24, label %.preheader.25, label %.loopexit

.preheader.25:                                    ; preds = %.preheader.24
  %28 = and i32 %0, 32
  %.not.25 = icmp eq i32 %28, 0
  br i1 %.not.25, label %.preheader.26, label %.loopexit

.preheader.26:                                    ; preds = %.preheader.25
  %29 = and i32 %0, 16
  %.not.26 = icmp eq i32 %29, 0
  br i1 %.not.26, label %.preheader.27, label %.loopexit

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

.preheader.28:                                    ; preds = %.preheader.27
  %31 = and i32 %0, 4
  %.not.28 = icmp eq i32 %31, 0
  br i1 %.not.28, label %.preheader.29, label %.loopexit

.preheader.29:                                    ; preds = %.preheader.28
  %32 = and i32 %0, 2
  %.not.29 = icmp eq i32 %32, 0
  br i1 %.not.29, label %.preheader.30, label %.loopexit

.preheader.30:                                    ; preds = %.preheader.29
  %33 = and i32 %0, 1
  %.not.30 = icmp eq i32 %33, 0
  br i1 %.not.30, label %34, label %.loopexit

34:                                               ; preds = %.preheader.30
  tail call void @__cxa_rethrow() #1
  unreachable

.loopexit:                                        ; preds = %.preheader.preheader, %.preheader.1, %.preheader.2, %.preheader.3, %.preheader.4, %.preheader.5, %.preheader.6, %.preheader.7, %.preheader.8, %.preheader.9, %.preheader.10, %.preheader.11, %.preheader.12, %.preheader.13, %.preheader.14, %.preheader.15, %.preheader.16, %.preheader.17, %.preheader.18, %.preheader.19, %.preheader.20, %.preheader.21, %.preheader.22, %.preheader.23, %.preheader.24, %.preheader.25, %.preheader.26, %.preheader.27, %.preheader.28, %.preheader.29, %.preheader.30, %1
  %.1 = phi i32 [ 0, %1 ], [ 1073741824, %.preheader.preheader ], [ 536870912, %.preheader.1 ], [ 268435456, %.preheader.2 ], [ 134217728, %.preheader.3 ], [ 67108864, %.preheader.4 ], [ 33554432, %.preheader.5 ], [ 16777216, %.preheader.6 ], [ 8388608, %.preheader.7 ], [ 4194304, %.preheader.8 ], [ 2097152, %.preheader.9 ], [ 1048576, %.preheader.10 ], [ 524288, %.preheader.11 ], [ 262144, %.preheader.12 ], [ 131072, %.preheader.13 ], [ 65536, %.preheader.14 ], [ 32768, %.preheader.15 ], [ 16384, %.preheader.16 ], [ 8192, %.preheader.17 ], [ 4096, %.preheader.18 ], [ 2048, %.preheader.19 ], [ 1024, %.preheader.20 ], [ 512, %.preheader.21 ], [ 256, %.preheader.22 ], [ 128, %.preheader.23 ], [ 64, %.preheader.24 ], [ 32, %.preheader.25 ], [ 16, %.preheader.26 ], [ 8, %.preheader.27 ], [ 4, %.preheader.28 ], [ 2, %.preheader.29 ], [ 1, %.preheader.30 ]
  ret i32 %.1
}

declare void @__cxa_rethrow() local_unnamed_addr

attributes #0 = { mustprogress 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 }

!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,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass