; LLVM IR from yourtion/LearningMasteringAlgorithms-C :: source (bit)

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

7:                                                ; preds = %17, %2
  %8 = load i32, ptr %6, align 4, !tbaa !9
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = srem i32 %9, 8
  %11 = icmp slt i32 %8, %10
  br i1 %11, label %12, label %20

12:                                               ; preds = %7
  %13 = load i8, ptr %5, align 1, !tbaa !11
  %14 = zext i8 %13 to i32
  %15 = ashr i32 %14, 1
  %16 = trunc i32 %15 to i8
  store i8 %16, ptr %5, align 1, !tbaa !11
  br label %17

17:                                               ; preds = %12
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %6, align 4, !tbaa !9
  br label %7, !llvm.loop !12

20:                                               ; preds = %7
  %21 = load i8, ptr %5, align 1, !tbaa !11
  %22 = zext i8 %21 to i32
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = sdiv i32 %24, 8
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i8, ptr %23, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = zext i8 %28 to i32
  %30 = and i32 %22, %29
  %31 = load i8, ptr %5, align 1, !tbaa !11
  %32 = zext i8 %31 to i32
  %33 = icmp eq i32 %30, %32
  %34 = zext i1 %33 to i64
  %35 = select i1 %33, i32 1, i32 0
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #2
  ret i32 %35
}

; 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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(argmem: read) uwtable
define dso_local range(i32 0, 2) i32 @bit_get(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = srem i32 %1, 8
  %4 = sdiv i32 %1, 8
  %5 = icmp sgt i32 %3, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  switch i32 %3, label %.lr.ph.6 [
    i32 1, label %._crit_edge
    i32 2, label %._crit_edge.loopexit.fold.split
    i32 3, label %._crit_edge.loopexit.fold.split10
    i32 4, label %._crit_edge.loopexit.fold.split11
    i32 5, label %._crit_edge.loopexit.fold.split12
    i32 6, label %._crit_edge.loopexit.fold.split13
  ]

.lr.ph.6:                                         ; preds = %.lr.ph
  br label %._crit_edge

._crit_edge.loopexit.fold.split:                  ; preds = %.lr.ph
  br label %._crit_edge

._crit_edge.loopexit.fold.split10:                ; preds = %.lr.ph
  br label %._crit_edge

._crit_edge.loopexit.fold.split11:                ; preds = %.lr.ph
  br label %._crit_edge

._crit_edge.loopexit.fold.split12:                ; preds = %.lr.ph
  br label %._crit_edge

._crit_edge.loopexit.fold.split13:                ; preds = %.lr.ph
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.6, %._crit_edge.loopexit.fold.split, %._crit_edge.loopexit.fold.split10, %._crit_edge.loopexit.fold.split11, %._crit_edge.loopexit.fold.split12, %._crit_edge.loopexit.fold.split13, %.lr.ph, %2
  %.07.lcssa = phi i8 [ -128, %2 ], [ 64, %.lr.ph ], [ 1, %.lr.ph.6 ], [ 32, %._crit_edge.loopexit.fold.split ], [ 16, %._crit_edge.loopexit.fold.split10 ], [ 8, %._crit_edge.loopexit.fold.split11 ], [ 4, %._crit_edge.loopexit.fold.split12 ], [ 2, %._crit_edge.loopexit.fold.split13 ]
  %6 = sext i32 %4 to i64
  %7 = getelementptr inbounds i8, ptr %0, i64 %6
  %8 = load i8, ptr %7, align 1, !tbaa !5
  %9 = and i8 %8, %.07.lcssa
  %10 = icmp ne i8 %9, 0
  %11 = zext i1 %10 to i32
  ret i32 %11
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: read) 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 = !{!6, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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