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

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

; 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) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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
@D = 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 } @_Z7addLeftRSt4pairIxxEc(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 = load i64, ptr @D, align 16, !tbaa !10
  %8 = mul nsw i64 %7, %6
  %9 = sext i8 %1 to i64
  %10 = add nsw i64 %9, -96
  %11 = add nsw i64 %8, %10
  %12 = srem i64 %11, %4
  store i64 %12, ptr %0, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load i64, ptr %13, align 8, !tbaa !11
  %15 = load i64, ptr getelementptr inbounds (i8, ptr @D, i64 8), align 8, !tbaa !10
  %16 = mul nsw i64 %15, %14
  %17 = add nsw i64 %16, %10
  %18 = load i64, ptr getelementptr inbounds (i8, ptr @M, i64 8), align 8, !tbaa !10
  %19 = srem i64 %17, %18
  store i64 %19, ptr %13, align 8, !tbaa !11
  %20 = add nsw i64 %5, 1
  %21 = load i64, ptr @M, align 16, !tbaa !10
  %22 = mul nsw i64 %21, %20
  %23 = add nsw i64 %22, %12
  store i64 %23, ptr %0, align 8, !tbaa !5
  %.fca.0.insert = insertvalue { i64, i64 } poison, i64 %23, 0
  %.fca.1.insert = insertvalue { i64, i64 } %.fca.0.insert, i64 %19, 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