; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd (964)

; 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.List = type { i64, i32 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@tot = external dso_local global i32, align 4
@lnk = external dso_local global [1000010 x i32], align 16
@str = external dso_local global [1000010 x [11 x i8]], align 16
@tmp = external dso_local global [11 x i8], align 1
@e = external dso_local global [1000010 x %struct.List], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z8BKDRHashPc(ptr noundef) #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i64, align 8
  %4 = alloca %struct.List, align 8
  %5 = alloca i8, align 1
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %9

9:                                                ; preds = %87, %0
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %12, label %88

12:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %44, %12
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %47

18:                                               ; preds = %13
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [1000010 x [11 x i8]], ptr @str, i64 0, i64 %20
  %22 = getelementptr inbounds [11 x i8], ptr %21, i64 0, i64 0
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %22)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [1000010 x [11 x i8]], ptr @str, i64 0, i64 %25
  %27 = getelementptr inbounds [11 x i8], ptr %26, i64 0, i64 0
  %28 = call noundef i64 @_Z8BKDRHashPc(ptr noundef %27)
  store i64 %28, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #5
  %29 = getelementptr inbounds %struct.List, ptr %4, i32 0, i32 0
  %30 = load i64, ptr %3, align 8, !tbaa !9
  store i64 %30, ptr %29, align 8, !tbaa !11
  %31 = getelementptr inbounds %struct.List, ptr %4, i32 0, i32 1
  %32 = load i64, ptr %3, align 8, !tbaa !9
  %33 = urem i64 %32, 1000010
  %34 = getelementptr inbounds [1000010 x i32], ptr @lnk, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  store i32 %35, ptr %31, align 8, !tbaa !13
  %36 = load i32, ptr @tot, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr @tot, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [1000010 x %struct.List], ptr @e, i64 0, i64 %38
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %39, ptr align 8 %4, i64 16, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #5
  %40 = load i32, ptr @tot, align 4, !tbaa !5
  %41 = load i64, ptr %3, align 8, !tbaa !9
  %42 = urem i64 %41, 1000010
  %43 = getelementptr inbounds [1000010 x i32], ptr @lnk, i64 0, i64 %42
  store i32 %40, ptr %43, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  br label %44

44:                                               ; preds = %18
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %2, align 4, !tbaa !5
  br label %13, !llvm.loop !15

47:                                               ; preds = %17
  %48 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @m)
  br label %49

49:                                               ; preds = %81, %47
  %50 = load i32, ptr @m, align 4, !tbaa !5
  %51 = add nsw i32 %50, -1
  store i32 %51, ptr @m, align 4, !tbaa !5
  %52 = icmp ne i32 %50, 0
  br i1 %52, label %53, label %87

53:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #5
  store i8 0, ptr %5, align 1, !tbaa !17
  %54 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @tmp)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %55 = call noundef i64 @_Z8BKDRHashPc(ptr noundef @tmp)
  store i64 %55, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %56 = load i64, ptr %6, align 8, !tbaa !9
  %57 = urem i64 %56, 1000010
  %58 = getelementptr inbounds [1000010 x i32], ptr @lnk, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  store i32 %59, ptr %7, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %74, %53
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %64, label %63

63:                                               ; preds = %60
  store i32 9, ptr %8, align 4
  br label %80

64:                                               ; preds = %60
  %65 = load i32, ptr %7, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [1000010 x %struct.List], ptr @e, i64 0, i64 %66
  %68 = getelementptr inbounds %struct.List, ptr %67, i32 0, i32 0
  %69 = load i64, ptr %68, align 16, !tbaa !11
  %70 = load i64, ptr %6, align 8, !tbaa !9
  %71 = icmp eq i64 %69, %70
  br i1 %71, label %72, label %73

72:                                               ; preds = %64
  store i8 1, ptr %5, align 1, !tbaa !17
  store i32 9, ptr %8, align 4
  br label %80

73:                                               ; preds = %64
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %7, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [1000010 x %struct.List], ptr @e, i64 0, i64 %76
  %78 = getelementptr inbounds %struct.List, ptr %77, i32 0, i32 1
  %79 = load i32, ptr %78, align 8, !tbaa !13
  store i32 %79, ptr %7, align 4, !tbaa !5
  br label %60, !llvm.loop !19

80:                                               ; preds = %72, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %81

81:                                               ; preds = %80
  %82 = load i8, ptr %5, align 1, !tbaa !17, !range !20, !noundef !21
  %83 = trunc i8 %82 to i1
  %84 = zext i1 %83 to i64
  %85 = select i1 %83, ptr @.str.2, ptr @.str.3
  %86 = call i32 @puts(ptr noundef %85)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #5
  br label %49, !llvm.loop !22

87:                                               ; preds = %49
  br label %9, !llvm.loop !23

88:                                               ; preds = %9
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #3

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

declare i32 @puts(ptr noundef) #3

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress norecurse 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 = { "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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS4List", !10, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = !{i64 0, i64 8, !9, i64 8, i64 4, !5}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !18, i64 0}
!18 = !{!"bool", !7, i64 0}
!19 = distinct !{!19, !16}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = distinct !{!22, !16}
!23 = distinct !{!23, !16}


; 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.List = type { i64, i32 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@tot = external dso_local local_unnamed_addr global i32, align 4
@lnk = external dso_local local_unnamed_addr global [1000010 x i32], align 16
@str = external dso_local global [1000010 x [11 x i8]], align 16
@tmp = external dso_local global [11 x i8], align 1
@e = external dso_local local_unnamed_addr global [1000010 x %struct.List], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z8BKDRHashPc(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = icmp eq i32 %1, 1
  br i1 %2, label %.preheader, label %._crit_edge28

.loopexit:                                        ; preds = %._crit_edge22, %._crit_edge
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %4 = icmp eq i32 %3, 1
  br i1 %4, label %.preheader, label %._crit_edge28, !llvm.loop !5

.preheader:                                       ; preds = %0, %.loopexit
  %5 = load i32, ptr @n, align 4, !tbaa !7
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %7 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @m)
  %8 = load i32, ptr @m, align 4, !tbaa !7
  %9 = add nsw i32 %8, -1
  store i32 %9, ptr @m, align 4, !tbaa !7
  %.not25 = icmp eq i32 %8, 0
  br i1 %.not25, label %.loopexit, label %.lr.ph27

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader ]
  %10 = getelementptr inbounds [1000010 x [11 x i8]], ptr @str, i64 0, i64 %indvars.iv
  %11 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %10)
  %12 = tail call noundef i64 @_Z8BKDRHashPc(ptr noundef nonnull %10)
  %13 = urem i64 %12, 1000010
  %14 = getelementptr inbounds [1000010 x i32], ptr @lnk, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !7
  %16 = load i32, ptr @tot, align 4, !tbaa !7
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr @tot, align 4, !tbaa !7
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1000010 x %struct.List], ptr @e, i64 0, i64 %18
  store i64 %12, ptr %19, align 16, !tbaa !11
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %19, i64 8
  store i32 %15, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !7
  store i32 %17, ptr %14, align 4, !tbaa !7
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = load i32, ptr @n, align 4, !tbaa !7
  %21 = sext i32 %20 to i64
  %22 = icmp slt i64 %indvars.iv.next, %21
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !13

.lr.ph27:                                         ; preds = %._crit_edge, %._crit_edge22
  %23 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @tmp)
  %24 = tail call noundef i64 @_Z8BKDRHashPc(ptr noundef nonnull @tmp)
  %25 = urem i64 %24, 1000010
  %26 = getelementptr inbounds [1000010 x i32], ptr @lnk, i64 0, i64 %25
  %.017 = load i32, ptr %26, align 4, !tbaa !7
  %.not15.not18 = icmp eq i32 %.017, 0
  br i1 %.not15.not18, label %._crit_edge22, label %.lr.ph21

27:                                               ; preds = %.lr.ph21
  %28 = getelementptr inbounds i8, ptr %30, i64 8
  %.0 = load i32, ptr %28, align 8, !tbaa !7
  %.not15.not = icmp eq i32 %.0, 0
  br i1 %.not15.not, label %._crit_edge22, label %.lr.ph21, !llvm.loop !14

.lr.ph21:                                         ; preds = %.lr.ph27, %27
  %.019 = phi i32 [ %.0, %27 ], [ %.017, %.lr.ph27 ]
  %29 = sext i32 %.019 to i64
  %30 = getelementptr inbounds [1000010 x %struct.List], ptr @e, i64 0, i64 %29
  %31 = load i64, ptr %30, align 16, !tbaa !15
  %32 = icmp eq i64 %31, %24
  br i1 %32, label %._crit_edge22, label %27

._crit_edge22:                                    ; preds = %27, %.lr.ph21, %.lr.ph27
  %33 = phi ptr [ @.str.3, %.lr.ph27 ], [ @.str.2, %.lr.ph21 ], [ @.str.3, %27 ]
  %34 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %33)
  %35 = load i32, ptr @m, align 4, !tbaa !7
  %36 = add nsw i32 %35, -1
  store i32 %36, ptr @m, align 4, !tbaa !7
  %.not = icmp eq i32 %35, 0
  br i1 %.not, label %.loopexit, label %.lr.ph27, !llvm.loop !17

._crit_edge28:                                    ; preds = %.loopexit, %0
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #2

attributes #0 = { 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 #1 = { mustprogress norecurse 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 = { nofree nounwind "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !9, i64 0}
!13 = distinct !{!13, !6}
!14 = distinct !{!14, !6}
!15 = !{!16, !12, i64 0}
!16 = !{!"_ZTS4List", !12, i64 0, !8, i64 8}
!17 = distinct !{!17, !6}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass