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

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

@Mi = external dso_local global [2 x i64], align 16
@M = external dso_local global [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 } @_Z7remLeftRSt4pairIxxEc(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 i8, ptr %5, align 1, !tbaa !9
  %18 = sext i8 %17 to i32
  %19 = sub nsw i32 %18, 97
  %20 = add nsw i32 %19, 1
  %21 = sext i32 %20 to i64
  %22 = sub nsw i64 %16, %21
  %23 = load i64, ptr @Mi, align 16, !tbaa !13
  %24 = mul nsw i64 %22, %23
  %25 = load i64, ptr @M, align 16, !tbaa !13
  %26 = srem i64 %24, %25
  %27 = load i64, ptr @M, align 16, !tbaa !13
  %28 = add nsw i64 %26, %27
  %29 = load i64, ptr @M, align 16, !tbaa !13
  %30 = srem i64 %28, %29
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %"struct.std::pair", ptr %31, i32 0, i32 0
  store i64 %30, ptr %32, align 8, !tbaa !10
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %"struct.std::pair", ptr %33, i32 0, i32 1
  %35 = load i64, ptr %34, align 8, !tbaa !14
  %36 = load i8, ptr %5, align 1, !tbaa !9
  %37 = sext i8 %36 to i32
  %38 = sub nsw i32 %37, 97
  %39 = add nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = sub nsw i64 %35, %40
  %42 = load i64, ptr getelementptr inbounds ([2 x i64], ptr @Mi, i64 0, i64 1), align 8, !tbaa !13
  %43 = mul nsw i64 %41, %42
  %44 = load i64, ptr getelementptr inbounds ([2 x i64], ptr @M, i64 0, i64 1), align 8, !tbaa !13
  %45 = srem i64 %43, %44
  %46 = load i64, ptr getelementptr inbounds ([2 x i64], ptr @M, i64 0, i64 1), align 8, !tbaa !13
  %47 = add nsw i64 %45, %46
  %48 = load i64, ptr getelementptr inbounds ([2 x i64], ptr @M, i64 0, i64 1), align 8, !tbaa !13
  %49 = srem i64 %47, %48
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %"struct.std::pair", ptr %50, i32 0, i32 1
  store i64 %49, ptr %51, align 8, !tbaa !14
  %52 = load i64, ptr %6, align 8, !tbaa !13
  %53 = sub nsw i64 %52, 1
  %54 = load i64, ptr @M, align 16, !tbaa !13
  %55 = mul nsw i64 %53, %54
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %"struct.std::pair", ptr %56, i32 0, i32 0
  %58 = load i64, ptr %57, align 8, !tbaa !10
  %59 = add nsw i64 %58, %55
  store i64 %59, ptr %57, align 8, !tbaa !10
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr align 8 %60, i64 16, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %61 = load { i64, i64 }, ptr %3, align 8
  ret { i64, i64 } %61
}

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"

@Mi = external dso_local local_unnamed_addr global [2 x i64], align 16
@M = external dso_local local_unnamed_addr global [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 } @_Z7remLeftRSt4pairIxxEc(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 = sext i8 %1 to i64
  %8 = add nsw i64 %7, -96
  %9 = sub nsw i64 %6, %8
  %10 = load i64, ptr @Mi, align 16, !tbaa !10
  %11 = mul nsw i64 %9, %10
  %12 = srem i64 %11, %4
  %13 = add nsw i64 %12, %4
  %14 = srem i64 %13, %4
  store i64 %14, ptr %0, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load i64, ptr %15, align 8, !tbaa !11
  %17 = sub nsw i64 %16, %8
  %18 = load i64, ptr getelementptr inbounds (i8, ptr @Mi, i64 8), align 8, !tbaa !10
  %19 = mul nsw i64 %17, %18
  %20 = load i64, ptr getelementptr inbounds (i8, ptr @M, i64 8), align 8, !tbaa !10
  %21 = srem i64 %19, %20
  %22 = add nsw i64 %21, %20
  %23 = srem i64 %22, %20
  store i64 %23, ptr %15, align 8, !tbaa !11
  %24 = add nsw i64 %5, -1
  %25 = load i64, ptr @M, align 16, !tbaa !10
  %26 = mul nsw i64 %25, %24
  %27 = add nsw i64 %26, %14
  store i64 %27, ptr %0, align 8, !tbaa !5
  %.fca.0.insert = insertvalue { i64, i64 } poison, i64 %27, 0
  %.fca.1.insert = insertvalue { i64, i64 } %.fca.0.insert, i64 %23, 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