; LLVM IR from wuzhouhui/leetcode :: 190_rev_bits (reverseBits)

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

@bits = external hidden global [16 x i8], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @reverseBits(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %20, %1
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = icmp ult i32 %6, 8
  br i1 %7, label %8, label %23

8:                                                ; preds = %5
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = shl i32 %9, 4
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = and i32 %11, 15
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds [16 x i8], ptr @bits, i64 0, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %16 = sext i8 %15 to i32
  %17 = add i32 %10, %16
  store i32 %17, ptr %4, align 4, !tbaa !5
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = lshr i32 %18, 4
  store i32 %19, ptr %2, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %8
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = add i32 %21, 1
  store i32 %22, ptr %3, align 4, !tbaa !5
  br label %5, !llvm.loop !10

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

; 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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"

@bits = external hidden local_unnamed_addr global [16 x i8], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local i32 @reverseBits(i32 noundef %0) local_unnamed_addr #0 {
  %2 = and i32 %0, 15
  %3 = zext nneg i32 %2 to i64
  %4 = getelementptr inbounds [16 x i8], ptr @bits, i64 0, i64 %3
  %5 = load i8, ptr %4, align 1, !tbaa !5
  %6 = sext i8 %5 to i32
  %7 = lshr i32 %0, 4
  %8 = and i32 %7, 15
  %9 = zext nneg i32 %8 to i64
  %10 = getelementptr inbounds [16 x i8], ptr @bits, i64 0, i64 %9
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = zext i8 %11 to i32
  %13 = lshr i32 %0, 8
  %14 = shl nsw i32 %6, 8
  %15 = shl nuw nsw i32 %12, 4
  %16 = add nsw i32 %14, %15
  %17 = and i32 %13, 15
  %18 = zext nneg i32 %17 to i64
  %19 = getelementptr inbounds [16 x i8], ptr @bits, i64 0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %21 = sext i8 %20 to i32
  %22 = add nsw i32 %16, %21
  %23 = lshr i32 %0, 12
  %24 = and i32 %23, 15
  %25 = zext nneg i32 %24 to i64
  %26 = getelementptr inbounds [16 x i8], ptr @bits, i64 0, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !5
  %28 = sext i8 %27 to i32
  %29 = lshr i32 %0, 16
  %30 = shl nsw i32 %22, 8
  %31 = shl nsw i32 %28, 4
  %32 = add nsw i32 %30, %31
  %33 = and i32 %29, 15
  %34 = zext nneg i32 %33 to i64
  %35 = getelementptr inbounds [16 x i8], ptr @bits, i64 0, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !5
  %37 = sext i8 %36 to i32
  %38 = add nsw i32 %32, %37
  %39 = lshr i32 %0, 20
  %40 = and i32 %39, 15
  %41 = zext nneg i32 %40 to i64
  %42 = getelementptr inbounds [16 x i8], ptr @bits, i64 0, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !5
  %44 = sext i8 %43 to i32
  %45 = lshr i32 %0, 24
  %46 = shl i32 %38, 8
  %47 = shl nsw i32 %44, 4
  %48 = add i32 %46, %47
  %49 = and i32 %45, 15
  %50 = zext nneg i32 %49 to i64
  %51 = getelementptr inbounds [16 x i8], ptr @bits, i64 0, i64 %50
  %52 = load i8, ptr %51, align 1, !tbaa !5
  %53 = sext i8 %52 to i32
  %54 = add i32 %48, %53
  %55 = lshr i32 %0, 28
  %56 = shl i32 %54, 4
  %57 = zext nneg i32 %55 to i64
  %58 = getelementptr inbounds [16 x i8], ptr @bits, i64 0, i64 %57
  %59 = load i8, ptr %58, align 1, !tbaa !5
  %60 = sext i8 %59 to i32
  %61 = add i32 %56, %60
  ret i32 %61
}

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


; Effective O3 passes: BDCEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass