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

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

@n = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@h = external dso_local global [100010 x i32], align 16
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 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

; 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
  store i32 0, ptr %1, align 4
  br label %4

4:                                                ; preds = %45, %0
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @k)
  %6 = icmp eq i32 %5, 2
  br i1 %6, label %7, label %50

7:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %18, %7
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = icmp sle i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %21

13:                                               ; preds = %8
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i32, ptr @h, i64 %15
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %16)
  br label %18

18:                                               ; preds = %13
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !9

21:                                               ; preds = %12
  store i32 0, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %42, %21
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %45

27:                                               ; preds = %22
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [100010 x i32], ptr @h, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [100010 x i32], ptr @h, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = icmp ne i32 %31, %36
  br i1 %37, label %38, label %41

38:                                               ; preds = %27
  %39 = load i32, ptr @ans, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr @ans, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %38, %27
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %3, align 4, !tbaa !5
  br label %22, !llvm.loop !11

45:                                               ; preds = %26
  %46 = load i32, ptr @ans, align 4, !tbaa !5
  %47 = load i32, ptr @k, align 4, !tbaa !5
  %48 = mul nsw i32 %46, %47
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %48)
  br label %4, !llvm.loop !12

50:                                               ; preds = %4
  ret i32 0
}

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

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

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

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

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 = { "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 nosync 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 = !{!"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 = distinct !{!12, !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"

@n = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@h = external dso_local global [100010 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [5 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

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

.preheader:                                       ; preds = %0, %._crit_edge14
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %.not9 = icmp slt i32 %3, 1
  br i1 %.not9, label %._crit_edge.thread, label %.lr.ph

._crit_edge.thread:                               ; preds = %.preheader
  store i32 0, ptr @ans, align 4, !tbaa !5
  br label %._crit_edge14

._crit_edge:                                      ; preds = %.lr.ph
  store i32 0, ptr @ans, align 4, !tbaa !5
  %4 = icmp sgt i32 %9, 1
  br i1 %4, label %.lr.ph13.preheader, label %._crit_edge14

.lr.ph13.preheader:                               ; preds = %._crit_edge
  %wide.trip.count = zext nneg i32 %9 to i64
  %.pre = load i32, ptr getelementptr inbounds (i8, ptr @h, i64 4), align 4, !tbaa !5
  %5 = add nsw i64 %wide.trip.count, -1
  %xtraiter = and i64 %5, 1
  %6 = icmp eq i32 %9, 2
  br i1 %6, label %._crit_edge14.loopexit.unr-lcssa, label %.lr.ph13.preheader.new

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

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %.preheader ]
  %7 = getelementptr inbounds i32, ptr @h, i64 %indvars.iv
  %8 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %7)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %.not.not = icmp slt i64 %indvars.iv, %10
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge14.loopexit.unr-lcssa:                 ; preds = %32, %.lr.ph13.preheader
  %.lcssa24.ph = phi i32 [ poison, %.lr.ph13.preheader ], [ %33, %32 ]
  %.unr = phi i32 [ %.pre, %.lr.ph13.preheader ], [ %29, %32 ]
  %indvars.iv18.unr = phi i64 [ 1, %.lr.ph13.preheader ], [ %indvars.iv.next19.1, %32 ]
  %.unr25 = phi i32 [ 0, %.lr.ph13.preheader ], [ %33, %32 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge14, label %.lr.ph13.epil

.lr.ph13.epil:                                    ; preds = %._crit_edge14.loopexit.unr-lcssa
  %indvars.iv.next19.epil = add nuw nsw i64 %indvars.iv18.unr, 1
  %11 = getelementptr inbounds [100010 x i32], ptr @h, i64 0, i64 %indvars.iv.next19.epil
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %.not8.epil = icmp eq i32 %.unr, %12
  br i1 %.not8.epil, label %._crit_edge14, label %13

13:                                               ; preds = %.lr.ph13.epil
  %14 = add nsw i32 %.unr25, 1
  store i32 %14, ptr @ans, align 4, !tbaa !5
  br label %._crit_edge14

._crit_edge14:                                    ; preds = %._crit_edge14.loopexit.unr-lcssa, %13, %.lr.ph13.epil, %._crit_edge.thread, %._crit_edge
  %15 = phi i32 [ 0, %._crit_edge ], [ 0, %._crit_edge.thread ], [ %.lcssa24.ph, %._crit_edge14.loopexit.unr-lcssa ], [ %.unr25, %.lr.ph13.epil ], [ %14, %13 ]
  %16 = load i32, ptr @k, align 4, !tbaa !5
  %17 = mul nsw i32 %16, %15
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %17)
  %19 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @k)
  %20 = icmp eq i32 %19, 2
  br i1 %20, label %.preheader, label %._crit_edge15, !llvm.loop !11

.lr.ph13:                                         ; preds = %32, %.lr.ph13.preheader.new
  %21 = phi i32 [ %.pre, %.lr.ph13.preheader.new ], [ %29, %32 ]
  %indvars.iv18 = phi i64 [ 1, %.lr.ph13.preheader.new ], [ %indvars.iv.next19.1, %32 ]
  %22 = phi i32 [ 0, %.lr.ph13.preheader.new ], [ %33, %32 ]
  %niter = phi i64 [ 0, %.lr.ph13.preheader.new ], [ %niter.next.1, %32 ]
  %indvars.iv.next19 = add nuw nsw i64 %indvars.iv18, 1
  %23 = getelementptr inbounds [100010 x i32], ptr @h, i64 0, i64 %indvars.iv.next19
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %.not8 = icmp eq i32 %21, %24
  br i1 %.not8, label %.lr.ph13.1, label %25

25:                                               ; preds = %.lr.ph13
  %26 = add nsw i32 %22, 1
  store i32 %26, ptr @ans, align 4, !tbaa !5
  br label %.lr.ph13.1

.lr.ph13.1:                                       ; preds = %.lr.ph13, %25
  %27 = phi i32 [ %22, %.lr.ph13 ], [ %26, %25 ]
  %indvars.iv.next19.1 = add nuw nsw i64 %indvars.iv18, 2
  %28 = getelementptr inbounds [100010 x i32], ptr @h, i64 0, i64 %indvars.iv.next19.1
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %.not8.1 = icmp eq i32 %24, %29
  br i1 %.not8.1, label %32, label %30

30:                                               ; preds = %.lr.ph13.1
  %31 = add nsw i32 %27, 1
  store i32 %31, ptr @ans, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %30, %.lr.ph13.1
  %33 = phi i32 [ %27, %.lr.ph13.1 ], [ %31, %30 ]
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge14.loopexit.unr-lcssa, label %.lr.ph13, !llvm.loop !12

._crit_edge15:                                    ; preds = %._crit_edge14, %0
  ret i32 0
}

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

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

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 = { 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 = !{!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 = distinct !{!12, !10}


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