; LLVM IR from tangjz/acm-icpc :: lanqiao (T123)

; 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
@h = external dso_local global [100001 x i32], align 16
@bit = external dso_local global [1000001 x i32], align 16
@d = external dso_local global [100001 x i32], align 16
@ans = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3addii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3sumi(i32 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 i32, align 4
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %6

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

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

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

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

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

20:                                               ; preds = %43, %19
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = icmp sle i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %46

25:                                               ; preds = %20
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = sub nsw i32 %26, 1
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [100001 x i32], ptr @h, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = call noundef i32 @_Z3sumi(i32 noundef %31)
  %33 = sub nsw i32 %27, %32
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [100001 x i32], ptr @d, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = add nsw i32 %37, %33
  store i32 %38, ptr %36, align 4, !tbaa !5
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [100001 x i32], ptr @h, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  call void @_Z3addii(i32 noundef %42, i32 noundef 1)
  br label %43

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

46:                                               ; preds = %24
  call void @llvm.memset.p0.i64(ptr align 16 @bit, i8 0, i64 4000004, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %47 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %47, ptr %4, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %83, %46
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = icmp sge i32 %49, 1
  br i1 %50, label %52, label %51

51:                                               ; preds = %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %86

52:                                               ; preds = %48
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [100001 x i32], ptr @h, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = sub nsw i32 %56, 1
  %58 = call noundef i32 @_Z3sumi(i32 noundef %57)
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [100001 x i32], ptr @d, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = add nsw i32 %62, %58
  store i32 %63, ptr %61, align 4, !tbaa !5
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [100001 x i32], ptr @h, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  call void @_Z3addii(i32 noundef %67, i32 noundef 1)
  %68 = load i32, ptr %4, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [100001 x i32], ptr @d, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [100001 x i32], ptr @d, i64 0, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = add nsw i64 %77, 1
  %79 = mul nsw i64 %72, %78
  %80 = ashr i64 %79, 1
  %81 = load i64, ptr @ans, align 8, !tbaa !12
  %82 = add nsw i64 %81, %80
  store i64 %82, ptr @ans, align 8, !tbaa !12
  br label %83

83:                                               ; preds = %52
  %84 = load i32, ptr %4, align 4, !tbaa !5
  %85 = add nsw i32 %84, -1
  store i32 %85, ptr %4, align 4, !tbaa !5
  br label %48, !llvm.loop !14

86:                                               ; preds = %51
  %87 = load i64, ptr @ans, align 8, !tbaa !12
  %88 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %87)
  ret i32 0
}

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

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

declare i32 @printf(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: write) }
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 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!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"

@n = external dso_local global i32, align 4
@h = external dso_local global [100001 x i32], align 16
@bit = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@d = external dso_local local_unnamed_addr global [100001 x i32], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3addii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3sumi(i32 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 = load i32, ptr @n, align 4, !tbaa !5
  %.not19 = icmp slt i32 %2, 1
  br i1 %.not19, label %._crit_edge.thread, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph
  %.not1821 = icmp slt i32 %5, 1
  br i1 %.not1821, label %._crit_edge.thread, label %.lr.ph23

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

._crit_edge.thread:                               ; preds = %.preheader, %0
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(4000004) @bit, i8 0, i64 4000004, i1 false)
  br label %._crit_edge.._crit_edge27_crit_edge

._crit_edge:                                      ; preds = %.lr.ph23
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(4000004) @bit, i8 0, i64 4000004, i1 false)
  %7 = icmp sgt i32 %19, 0
  br i1 %7, label %.lr.ph26.preheader, label %._crit_edge.._crit_edge27_crit_edge

._crit_edge.._crit_edge27_crit_edge:              ; preds = %._crit_edge.thread, %._crit_edge
  %.pre = load i64, ptr @ans, align 8, !tbaa !11
  br label %._crit_edge27

.lr.ph26.preheader:                               ; preds = %._crit_edge
  %8 = zext nneg i32 %19 to i64
  br label %.lr.ph26

.lr.ph23:                                         ; preds = %.preheader, %.lr.ph23
  %indvars.iv30 = phi i64 [ %indvars.iv.next31, %.lr.ph23 ], [ 1, %.preheader ]
  %9 = getelementptr inbounds [100001 x i32], ptr @h, i64 0, i64 %indvars.iv30
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = tail call noundef i32 @_Z3sumi(i32 noundef %10)
  %12 = xor i32 %11, -1
  %13 = trunc nuw nsw i64 %indvars.iv30 to i32
  %14 = add i32 %13, %12
  %15 = getelementptr inbounds [100001 x i32], ptr @d, i64 0, i64 %indvars.iv30
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = add nsw i32 %14, %16
  store i32 %17, ptr %15, align 4, !tbaa !5
  %18 = load i32, ptr %9, align 4, !tbaa !5
  tail call void @_Z3addii(i32 noundef %18, i32 noundef 1)
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %.not18.not = icmp slt i64 %indvars.iv30, %20
  br i1 %.not18.not, label %.lr.ph23, label %._crit_edge, !llvm.loop !13

._crit_edge27:                                    ; preds = %.lr.ph26, %._crit_edge.._crit_edge27_crit_edge
  %21 = phi i64 [ %.pre, %._crit_edge.._crit_edge27_crit_edge ], [ %37, %.lr.ph26 ]
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %21)
  ret i32 0

.lr.ph26:                                         ; preds = %.lr.ph26.preheader, %.lr.ph26
  %indvars.iv33 = phi i64 [ %8, %.lr.ph26.preheader ], [ %indvars.iv.next34, %.lr.ph26 ]
  %23 = getelementptr inbounds [100001 x i32], ptr @h, i64 0, i64 %indvars.iv33
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = add nsw i32 %24, -1
  %26 = tail call noundef i32 @_Z3sumi(i32 noundef %25)
  %27 = getelementptr inbounds [100001 x i32], ptr @d, i64 0, i64 %indvars.iv33
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = add nsw i32 %28, %26
  store i32 %29, ptr %27, align 4, !tbaa !5
  %30 = load i32, ptr %23, align 4, !tbaa !5
  tail call void @_Z3addii(i32 noundef %30, i32 noundef 1)
  %31 = load i32, ptr %27, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = add nsw i64 %32, 1
  %34 = mul nsw i64 %33, %32
  %35 = ashr i64 %34, 1
  %36 = load i64, ptr @ans, align 8, !tbaa !11
  %37 = add nsw i64 %35, %36
  store i64 %37, ptr @ans, align 8, !tbaa !11
  %indvars.iv.next34 = add nsw i64 %indvars.iv33, -1
  %38 = icmp ugt i64 %indvars.iv33, 1
  br i1 %38, label %.lr.ph26, label %._crit_edge27, !llvm.loop !14
}

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(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" }
attributes #3 = { mustprogress 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


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