; LLVM IR from Jatin-Nagpal/CP-Devils :: Algorithms/Hashing.ll (Z8remRightRSt4pairIxxEc)

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

%"struct.std::pair" = type { i64, i64 }

@M = external dso_local global [2 x i64], align 16
@po = external dso_local global [2005 x [2 x i64]], align 16

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local { i64, i64 } @_Z8remRightRSt4pairIxxEc(ptr noundef nonnull align 8 dereferenceable(16) %0, i8 noundef signext %1) #2 {
  %3 = alloca %"struct.std::pair", align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %"struct.std::pair", ptr %7, i32 0, i32 0
  %9 = load i64, ptr %8, align 8, !tbaa !10
  %10 = load i64, ptr @M, align 16, !tbaa !13
  %11 = sdiv i64 %9, %10
  store i64 %11, ptr %6, align 8, !tbaa !13
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %"struct.std::pair", ptr %12, i32 0, i32 0
  %14 = load i64, ptr %13, align 8, !tbaa !10
  %15 = load i64, ptr @M, align 16, !tbaa !13
  %16 = srem i64 %14, %15
  %17 = load i64, ptr %6, align 8, !tbaa !13
  %18 = sub nsw i64 %17, 1
  %19 = getelementptr inbounds [2005 x [2 x i64]], ptr @po, i64 0, i64 %18
  %20 = getelementptr inbounds [2 x i64], ptr %19, i64 0, i64 0
  %21 = load i64, ptr %20, align 16, !tbaa !13
  %22 = load i8, ptr %5, align 1, !tbaa !9
  %23 = sext i8 %22 to i32
  %24 = sub nsw i32 %23, 97
  %25 = add nsw i32 %24, 1
  %26 = sext i32 %25 to i64
  %27 = mul nsw i64 %21, %26
  %28 = sub nsw i64 %16, %27
  %29 = load i64, ptr @M, align 16, !tbaa !13
  %30 = srem i64 %28, %29
  %31 = load i64, ptr @M, align 16, !tbaa !13
  %32 = add nsw i64 %30, %31
  %33 = load i64, ptr @M, align 16, !tbaa !13
  %34 = srem i64 %32, %33
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %"struct.std::pair", ptr %35, i32 0, i32 0
  store i64 %34, ptr %36, align 8, !tbaa !10
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %"struct.std::pair", ptr %37, i32 0, i32 1
  %39 = load i64, ptr %38, align 8, !tbaa !14
  %40 = load i64, ptr %6, align 8, !tbaa !13
  %41 = sub nsw i64 %40, 1
  %42 = getelementptr inbounds [2005 x [2 x i64]], ptr @po, i64 0, i64 %41
  %43 = getelementptr inbounds [2 x i64], ptr %42, i64 0, i64 1
  %44 = load i64, ptr %43, align 8, !tbaa !13
  %45 = load i8, ptr %5, align 1, !tbaa !9
  %46 = sext i8 %45 to i32
  %47 = sub nsw i32 %46, 97
  %48 = add nsw i32 %47, 1
  %49 = sext i32 %48 to i64
  %50 = mul nsw i64 %44, %49
  %51 = sub nsw i64 %39, %50
  %52 = load i64, ptr getelementptr inbounds ([2 x i64], ptr @M, i64 0, i64 1), align 8, !tbaa !13
  %53 = srem i64 %51, %52
  %54 = load i64, ptr getelementptr inbounds ([2 x i64], ptr @M, i64 0, i64 1), align 8, !tbaa !13
  %55 = add nsw i64 %53, %54
  %56 = load i64, ptr getelementptr inbounds ([2 x i64], ptr @M, i64 0, i64 1), align 8, !tbaa !13
  %57 = srem i64 %55, %56
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %"struct.std::pair", ptr %58, i32 0, i32 1
  store i64 %57, ptr %59, align 8, !tbaa !14
  %60 = load i64, ptr %6, align 8, !tbaa !13
  %61 = sub nsw i64 %60, 1
  %62 = load i64, ptr @M, align 16, !tbaa !13
  %63 = mul nsw i64 %61, %62
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %"struct.std::pair", ptr %64, i32 0, i32 0
  %66 = load i64, ptr %65, align 8, !tbaa !10
  %67 = add nsw i64 %66, %63
  store i64 %67, ptr %65, align 8, !tbaa !10
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr align 8 %68, i64 16, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %69 = load { i64, i64 }, ptr %3, align 8
  ret { i64, i64 } %69
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"_ZTSSt4pairIxxE", !12, i64 0, !12, i64 8}
!12 = !{!"long long", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!11, !12, i64 8}


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

@M = external dso_local local_unnamed_addr global [2 x i64], align 16
@po = external dso_local local_unnamed_addr global [2005 x [2 x i64]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local { i64, i64 } @_Z8remRightRSt4pairIxxEc(ptr nocapture noundef nonnull align 8 dereferenceable(16) %0, i8 noundef signext %1) local_unnamed_addr #0 {
  %3 = load i64, ptr %0, align 8, !tbaa !5
  %4 = load i64, ptr @M, align 16, !tbaa !10
  %5 = sdiv i64 %3, %4
  %6 = srem i64 %3, %4
  %7 = add nsw i64 %5, -1
  %8 = getelementptr inbounds [2005 x [2 x i64]], ptr @po, i64 0, i64 %7
  %9 = load i64, ptr %8, align 16, !tbaa !10
  %10 = sext i8 %1 to i64
  %11 = add nsw i64 %10, -96
  %12 = mul nsw i64 %9, %11
  %13 = sub nsw i64 %6, %12
  %14 = srem i64 %13, %4
  %15 = add nsw i64 %14, %4
  %16 = srem i64 %15, %4
  store i64 %16, ptr %0, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %8, i64 8
  %20 = load i64, ptr %19, align 8, !tbaa !10
  %21 = mul nsw i64 %20, %11
  %22 = sub nsw i64 %18, %21
  %23 = load i64, ptr getelementptr inbounds (i8, ptr @M, i64 8), align 8, !tbaa !10
  %24 = srem i64 %22, %23
  %25 = add nsw i64 %24, %23
  %26 = srem i64 %25, %23
  store i64 %26, ptr %17, align 8, !tbaa !11
  %27 = load i64, ptr @M, align 16, !tbaa !10
  %28 = mul nsw i64 %27, %7
  %29 = add nsw i64 %28, %16
  store i64 %29, ptr %0, align 8, !tbaa !5
  %.fca.0.insert = insertvalue { i64, i64 } poison, i64 %29, 0
  %.fca.1.insert = insertvalue { i64, i64 } %.fca.0.insert, i64 %26, 1
  ret { i64, i64 } %.fca.1.insert
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, 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, !7, i64 0}
!6 = !{!"_ZTSSt4pairIxxE", !7, i64 0, !7, i64 8}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!6, !7, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass