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

; 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 } @_Z8addRightRSt4pairIxxEc(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 = load i64, ptr %6, align 8, !tbaa !13
  %23 = getelementptr inbounds [2005 x [2 x i64]], ptr @po, i64 0, i64 %22
  %24 = getelementptr inbounds [2 x i64], ptr %23, i64 0, i64 0
  %25 = load i64, ptr %24, align 16, !tbaa !13
  %26 = mul nsw i64 %21, %25
  %27 = add nsw i64 %16, %26
  %28 = load i64, ptr @M, align 16, !tbaa !13
  %29 = srem i64 %27, %28
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %"struct.std::pair", ptr %30, i32 0, i32 0
  store i64 %29, ptr %31, align 8, !tbaa !10
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %"struct.std::pair", ptr %32, i32 0, i32 1
  %34 = load i64, ptr %33, align 8, !tbaa !14
  %35 = load i8, ptr %5, align 1, !tbaa !9
  %36 = sext i8 %35 to i32
  %37 = sub nsw i32 %36, 97
  %38 = add nsw i32 %37, 1
  %39 = sext i32 %38 to i64
  %40 = load i64, ptr %6, align 8, !tbaa !13
  %41 = getelementptr inbounds [2005 x [2 x i64]], ptr @po, i64 0, i64 %40
  %42 = getelementptr inbounds [2 x i64], ptr %41, i64 0, i64 1
  %43 = load i64, ptr %42, align 8, !tbaa !13
  %44 = mul nsw i64 %39, %43
  %45 = add nsw i64 %34, %44
  %46 = load i64, ptr getelementptr inbounds ([2 x i64], ptr @M, i64 0, i64 1), align 8, !tbaa !13
  %47 = srem i64 %45, %46
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %"struct.std::pair", ptr %48, i32 0, i32 1
  store i64 %47, ptr %49, align 8, !tbaa !14
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %"struct.std::pair", ptr %50, i32 0, i32 0
  %52 = load i64, ptr %51, align 8, !tbaa !10
  %53 = load i64, ptr %6, align 8, !tbaa !13
  %54 = add nsw i64 %53, 1
  %55 = load i64, ptr @M, align 16, !tbaa !13
  %56 = mul nsw i64 %54, %55
  %57 = add nsw i64 %52, %56
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %"struct.std::pair", ptr %58, i32 0, i32 0
  store i64 %57, ptr %59, 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"

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