; LLVM IR from tangjz/acm-icpc :: lydsy/3207.ll (Z4Hashv)

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

@b = external dso_local global i64, align 8
@tmp = external dso_local global %"struct.std::pair", align 8
@k = external dso_local global i32, align 4

; 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 uwtable
define dso_local void @_Z4Hashv() #1 {
  %1 = alloca i32, align 4
  store i64 0, ptr getelementptr inbounds (%"struct.std::pair", ptr @tmp, i32 0, i32 1), align 8, !tbaa !5
  store i64 0, ptr @tmp, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !11
  br label %2

2:                                                ; preds = %16, %0
  %3 = load i32, ptr %1, align 4, !tbaa !11
  %4 = load i32, ptr @k, align 4, !tbaa !11
  %5 = icmp slt i32 %3, %4
  br i1 %5, label %7, label %6

6:                                                ; preds = %2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %19

7:                                                ; preds = %2
  call void @_Z6getintIyEvRT_(ptr noundef nonnull align 8 dereferenceable(8) @b)
  %8 = load i64, ptr @tmp, align 8, !tbaa !10
  %9 = mul i64 %8, 13
  %10 = load i64, ptr @b, align 8, !tbaa !13
  %11 = add i64 %9, %10
  store i64 %11, ptr @tmp, align 8, !tbaa !10
  %12 = load i64, ptr getelementptr inbounds (%"struct.std::pair", ptr @tmp, i32 0, i32 1), align 8, !tbaa !5
  %13 = mul i64 %12, 29
  %14 = load i64, ptr @b, align 8, !tbaa !13
  %15 = add i64 %13, %14
  store i64 %15, ptr getelementptr inbounds (%"struct.std::pair", ptr @tmp, i32 0, i32 1), align 8, !tbaa !5
  br label %16

16:                                               ; preds = %7
  %17 = load i32, ptr %1, align 4, !tbaa !11
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %1, align 4, !tbaa !11
  br label %2, !llvm.loop !14

19:                                               ; preds = %6
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6getintIyEvRT_(ptr noundef nonnull align 8 dereferenceable(8)) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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, !7, i64 8}
!6 = !{!"_ZTSSt4pairIyyE", !7, i64 0, !7, i64 8}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

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

@b = external dso_local global i64, align 8
@tmp = external dso_local local_unnamed_addr global %"struct.std::pair", align 8
@k = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4Hashv() local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) @tmp, i8 0, i64 16, i1 false)
  %1 = load i32, ptr @k, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  ret void

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.02 = phi i32 [ %10, %.lr.ph ], [ 0, %0 ]
  tail call void @_Z6getintIyEvRT_(ptr noundef nonnull align 8 dereferenceable(8) @b)
  %3 = load i64, ptr @tmp, align 8, !tbaa !9
  %4 = mul i64 %3, 13
  %5 = load i64, ptr @b, align 8, !tbaa !12
  %6 = add i64 %4, %5
  store i64 %6, ptr @tmp, align 8, !tbaa !9
  %7 = load i64, ptr getelementptr inbounds (i8, ptr @tmp, i64 8), align 8, !tbaa !13
  %8 = mul i64 %7, 29
  %9 = add i64 %8, %5
  store i64 %9, ptr getelementptr inbounds (i8, ptr @tmp, i64 8), align 8, !tbaa !13
  %10 = add nuw nsw i32 %.02, 1
  %11 = load i32, ptr @k, align 4, !tbaa !5
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %.lr.ph, label %._crit_edge, !llvm.loop !14
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6getintIyEvRT_(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { mustprogress 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 nounwind willreturn memory(argmem: write) }

!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"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTSSt4pairIyyE", !11, i64 0, !11, i64 8}
!11 = !{!"long long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass