; LLVM IR from tangjz/acm-icpc :: hdu (5685)

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

@inv = external dso_local global [9973 x i32], align 16
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@h = external dso_local global [100002 x i32], align 16
@str = external dso_local global [100002 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  store i32 1, ptr getelementptr inbounds ([9973 x i32], ptr @inv, i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %24, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 9973
  br i1 %8, label %10, label %9

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

10:                                               ; preds = %6
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sdiv i32 9973, %11
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = srem i32 9973, %13
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [9973 x i32], ptr @inv, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = mul nsw i32 %12, %17
  %19 = srem i32 %18, 9973
  %20 = sub nsw i32 9973, %19
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [9973 x i32], ptr @inv, i64 0, i64 %22
  store i32 %20, ptr %23, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %10
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !9

27:                                               ; preds = %9
  br label %28

28:                                               ; preds = %81, %27
  %29 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @m, ptr noundef getelementptr inbounds (i8, ptr @str, i64 1))
  %30 = icmp eq i32 %29, 2
  br i1 %30, label %31, label %82

31:                                               ; preds = %28
  %32 = call i64 @strlen(ptr noundef getelementptr inbounds (i8, ptr @str, i64 1)) #5
  %33 = trunc i64 %32 to i32
  store i32 %33, ptr @n, align 4, !tbaa !5
  store i32 1, ptr @h, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %56, %31
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = load i32, ptr @n, align 4, !tbaa !5
  %37 = icmp sle i32 %35, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %59

39:                                               ; preds = %34
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = sub nsw i32 %40, 1
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [100002 x i32], ptr @h, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [100002 x i8], ptr @str, i64 0, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !11
  %49 = sext i8 %48 to i32
  %50 = sub nsw i32 %49, 28
  %51 = mul nsw i32 %44, %50
  %52 = srem i32 %51, 9973
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [100002 x i32], ptr @h, i64 0, i64 %54
  store i32 %52, ptr %55, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %39
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %3, align 4, !tbaa !5
  br label %34, !llvm.loop !12

59:                                               ; preds = %38
  br label %60

60:                                               ; preds = %64, %59
  %61 = load i32, ptr @m, align 4, !tbaa !5
  %62 = add nsw i32 %61, -1
  store i32 %62, ptr @m, align 4, !tbaa !5
  %63 = icmp ne i32 %61, 0
  br i1 %63, label %64, label %81

64:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %65 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %4, ptr noundef %5)
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [100002 x i32], ptr @h, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = load i32, ptr %4, align 4, !tbaa !5
  %71 = sub nsw i32 %70, 1
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [100002 x i32], ptr @h, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [9973 x i32], ptr @inv, i64 0, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !5
  %78 = mul nsw i32 %69, %77
  %79 = srem i32 %78, 9973
  %80 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %79)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %60, !llvm.loop !13

81:                                               ; preds = %60
  br label %28, !llvm.loop !14

82:                                               ; preds = %28
  ret i32 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

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

declare i32 @printf(ptr noundef, ...) #2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 willreturn memory(read) "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 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

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


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

@inv = external dso_local local_unnamed_addr global [9973 x i32], align 16
@n = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local global i32, align 4
@h = external dso_local local_unnamed_addr global [100002 x i32], align 16
@str = external dso_local global [100002 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store i32 1, ptr getelementptr inbounds (i8, ptr @inv, i64 4), align 4, !tbaa !5
  br label %5

.preheader14:                                     ; preds = %5
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @m, ptr noundef nonnull getelementptr inbounds (i8, ptr @str, i64 1))
  %4 = icmp eq i32 %3, 2
  br i1 %4, label %.lr.ph20, label %._crit_edge

5:                                                ; preds = %0, %5
  %indvars.iv = phi i64 [ 2, %0 ], [ %indvars.iv.next, %5 ]
  %.rhs.trunc = trunc i64 %indvars.iv to i16
  %6 = udiv i16 9973, %.rhs.trunc
  %.zext = zext nneg i16 %6 to i32
  %7 = urem i16 9973, %.rhs.trunc
  %8 = zext nneg i16 %7 to i64
  %9 = getelementptr inbounds [9973 x i32], ptr @inv, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = mul nsw i32 %10, %.zext
  %12 = srem i32 %11, 9973
  %13 = sub nsw i32 9973, %12
  %14 = getelementptr inbounds [9973 x i32], ptr @inv, i64 0, i64 %indvars.iv
  store i32 %13, ptr %14, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 9973
  br i1 %exitcond.not, label %.preheader14, label %5, !llvm.loop !9

.loopexit:                                        ; preds = %.lr.ph19, %.preheader
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @m, ptr noundef nonnull getelementptr inbounds (i8, ptr @str, i64 1))
  %16 = icmp eq i32 %15, 2
  br i1 %16, label %.lr.ph20, label %._crit_edge, !llvm.loop !11

.lr.ph20:                                         ; preds = %.preheader14, %.loopexit
  %17 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @str, i64 1)) #4
  %18 = trunc i64 %17 to i32
  store i32 %18, ptr @n, align 4, !tbaa !5
  store i32 1, ptr @h, align 16, !tbaa !5
  %.not16 = icmp slt i32 %18, 1
  br i1 %.not16, label %.preheader, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.lr.ph20
  %19 = add nuw nsw i64 %17, 1
  %wide.trip.count = and i64 %19, 4294967295
  %20 = add nsw i64 %wide.trip.count, -1
  %xtraiter = and i64 %20, 1
  %21 = icmp eq i64 %wide.trip.count, 2
  br i1 %21, label %.preheader.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %20, -2
  br label %.lr.ph

.preheader.loopexit.unr-lcssa:                    ; preds = %.lr.ph, %.lr.ph.preheader
  %.unr = phi i32 [ 1, %.lr.ph.preheader ], [ %44, %.lr.ph ]
  %indvars.iv22.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next23.1, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.preheader.loopexit.unr-lcssa
  %22 = getelementptr inbounds [100002 x i8], ptr @str, i64 0, i64 %indvars.iv22.unr
  %23 = load i8, ptr %22, align 1, !tbaa !12
  %24 = sext i8 %23 to i32
  %25 = add nsw i32 %24, -28
  %26 = mul nsw i32 %25, %.unr
  %27 = srem i32 %26, 9973
  %28 = getelementptr inbounds [100002 x i32], ptr @h, i64 0, i64 %indvars.iv22.unr
  store i32 %27, ptr %28, align 4, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.lr.ph.epil, %.preheader.loopexit.unr-lcssa, %.lr.ph20
  %29 = load i32, ptr @m, align 4, !tbaa !5
  %30 = add nsw i32 %29, -1
  store i32 %30, ptr @m, align 4, !tbaa !5
  %.not1118 = icmp eq i32 %29, 0
  br i1 %.not1118, label %.loopexit, label %.lr.ph19

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %31 = phi i32 [ 1, %.lr.ph.preheader.new ], [ %44, %.lr.ph ]
  %indvars.iv22 = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next23.1, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %32 = getelementptr inbounds [100002 x i8], ptr @str, i64 0, i64 %indvars.iv22
  %33 = load i8, ptr %32, align 1, !tbaa !12
  %34 = sext i8 %33 to i32
  %35 = add nsw i32 %34, -28
  %36 = mul nsw i32 %35, %31
  %37 = srem i32 %36, 9973
  %38 = getelementptr inbounds [100002 x i32], ptr @h, i64 0, i64 %indvars.iv22
  store i32 %37, ptr %38, align 4, !tbaa !5
  %indvars.iv.next23 = add nuw nsw i64 %indvars.iv22, 1
  %39 = getelementptr inbounds [100002 x i8], ptr @str, i64 0, i64 %indvars.iv.next23
  %40 = load i8, ptr %39, align 1, !tbaa !12
  %41 = sext i8 %40 to i32
  %42 = add nsw i32 %41, -28
  %43 = mul nsw i32 %42, %37
  %44 = srem i32 %43, 9973
  %45 = getelementptr inbounds [100002 x i32], ptr @h, i64 0, i64 %indvars.iv.next23
  store i32 %44, ptr %45, align 4, !tbaa !5
  %indvars.iv.next23.1 = add nuw nsw i64 %indvars.iv22, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.preheader.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !13

.lr.ph19:                                         ; preds = %.preheader, %.lr.ph19
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  %46 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100002 x i32], ptr @h, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = load i32, ptr %1, align 4, !tbaa !5
  %52 = add nsw i32 %51, -1
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [100002 x i32], ptr @h, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [9973 x i32], ptr @inv, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = mul nsw i32 %58, %50
  %60 = srem i32 %59, 9973
  %61 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %60)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  %62 = load i32, ptr @m, align 4, !tbaa !5
  %63 = add nsw i32 %62, -1
  store i32 %63, ptr @m, align 4, !tbaa !5
  %.not11 = icmp eq i32 %62, 0
  br i1 %.not11, label %.loopexit, label %.lr.ph19, !llvm.loop !14

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

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

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #3

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

attributes #0 = { mustprogress nofree 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #3 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { nounwind willreturn memory(read) }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass