; LLVM IR from abeaumont/competitive-programming :: cses/1670.ll (Z5indexRSt6vectorIiSaIiEE)

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

@n = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z5indexRSt6vectorIiSaIiEE(ptr noundef nonnull align 8 dereferenceable(24) %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %9 = load i32, ptr @n, align 4, !tbaa !9
  %10 = sdiv i32 %9, 9
  store i32 %10, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %42, %1
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = icmp slt i32 %12, 8
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %45

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %16, i64 noundef %18) #3
  %20 = load i32, ptr %19, align 4, !tbaa !9
  store i32 %20, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = shl i32 1, %23
  %25 = sub nsw i32 %24, 1
  %26 = and i32 %22, %25
  %27 = call i32 @llvm.ctpop.i32(i32 %26)
  %28 = sub nsw i32 %21, %27
  store i32 %28, ptr %8, align 4, !tbaa !9
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = mul nsw i32 %29, %30
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = add nsw i32 %32, %31
  store i32 %33, ptr %4, align 4, !tbaa !9
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = sub nsw i32 8, %34
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = sdiv i32 %36, %35
  store i32 %37, ptr %5, align 4, !tbaa !9
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = shl i32 1, %38
  %40 = load i32, ptr %3, align 4, !tbaa !9
  %41 = or i32 %40, %39
  store i32 %41, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %42

42:                                               ; preds = %15
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %6, align 4, !tbaa !9
  br label %11, !llvm.loop !11

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.ctpop.i32(i32) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@n = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z5indexRSt6vectorIiSaIiEE(ptr noundef nonnull align 8 dereferenceable(24) %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = sdiv i32 %2, 9
  %4 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 0) #2
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = shl nuw i32 1, %5
  %7 = and i32 %6, 1
  %8 = xor i32 %7, 1
  %9 = sub nsw i32 %5, %8
  %10 = mul nsw i32 %9, %3
  %11 = sdiv i32 %2, 72
  %12 = or i32 %6, 1
  %13 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 1) #2
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = shl nuw i32 1, %14
  %16 = add nsw i32 %15, -1
  %17 = and i32 %16, %12
  %18 = tail call range(i32 0, 33) i32 @llvm.ctpop.i32(i32 %17)
  %19 = sub nsw i32 %14, %18
  %20 = mul nsw i32 %19, %11
  %21 = add nsw i32 %20, %10
  %22 = sdiv i32 %2, 504
  %23 = or i32 %15, %12
  %24 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 2) #2
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = shl nuw i32 1, %25
  %27 = add nsw i32 %26, -1
  %28 = and i32 %27, %23
  %29 = tail call range(i32 0, 33) i32 @llvm.ctpop.i32(i32 %28)
  %30 = sub nsw i32 %25, %29
  %31 = mul nsw i32 %30, %22
  %32 = add nsw i32 %31, %21
  %33 = sdiv i32 %2, 3024
  %34 = or i32 %26, %23
  %35 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 3) #2
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = shl nuw i32 1, %36
  %38 = add nsw i32 %37, -1
  %39 = and i32 %38, %34
  %40 = tail call range(i32 0, 33) i32 @llvm.ctpop.i32(i32 %39)
  %41 = sub nsw i32 %36, %40
  %42 = mul nsw i32 %41, %33
  %43 = add nsw i32 %42, %32
  %44 = sdiv i32 %2, 15120
  %45 = or i32 %37, %34
  %46 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 4) #2
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = shl nuw i32 1, %47
  %49 = add nsw i32 %48, -1
  %50 = and i32 %49, %45
  %51 = tail call range(i32 0, 33) i32 @llvm.ctpop.i32(i32 %50)
  %52 = sub nsw i32 %47, %51
  %53 = mul nsw i32 %52, %44
  %54 = add nsw i32 %53, %43
  %55 = sdiv i32 %2, 60480
  %56 = or i32 %48, %45
  %57 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 5) #2
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = shl nuw i32 1, %58
  %60 = add nsw i32 %59, -1
  %61 = and i32 %60, %56
  %62 = tail call range(i32 0, 33) i32 @llvm.ctpop.i32(i32 %61)
  %63 = sub nsw i32 %58, %62
  %64 = mul nsw i32 %63, %55
  %65 = add nsw i32 %64, %54
  %66 = sdiv i32 %2, 181440
  %67 = or i32 %59, %56
  %68 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 6) #2
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = shl nuw i32 1, %69
  %71 = add nsw i32 %70, -1
  %72 = and i32 %71, %67
  %73 = tail call range(i32 0, 33) i32 @llvm.ctpop.i32(i32 %72)
  %74 = sub nsw i32 %69, %73
  %75 = mul nsw i32 %74, %66
  %76 = add nsw i32 %75, %65
  %77 = sdiv i32 %2, 362880
  %78 = or i32 %70, %67
  %79 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 7) #2
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %notmask = shl nsw i32 -1, %80
  %81 = xor i32 %notmask, -1
  %82 = and i32 %78, %81
  %83 = tail call range(i32 0, 33) i32 @llvm.ctpop.i32(i32 %82)
  %84 = sub nsw i32 %80, %83
  %85 = mul nsw i32 %84, %77
  %86 = add nsw i32 %85, %76
  ret i32 %86
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.ctpop.i32(i32) #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass