; LLVM IR from tangjz/acm-icpc :: codeforces/complete (297E)

; 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
@f = external dso_local global [233333 x i32], align 16
@ans = external dso_local global i64, align 8
@ans1 = external dso_local global i64, align 8
@ans2 = 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 [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5queryi(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
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = sub nsw i32 %12, 1
  %14 = sext i32 %13 to i64
  %15 = mul nsw i64 %11, %14
  %16 = sdiv i64 %15, 2
  %17 = load i32, ptr @n, align 4, !tbaa !5
  %18 = sub nsw i32 %17, 2
  %19 = sext i32 %18 to i64
  %20 = mul nsw i64 %16, %19
  %21 = sdiv i64 %20, 3
  store i64 %21, ptr @ans, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  br label %22

22:                                               ; preds = %37, %0
  %23 = load i32, ptr %2, 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 %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %40

27:                                               ; preds = %22
  %28 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3, ptr noundef %4)
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [233333 x i32], ptr @f, i64 0, i64 %31
  store i32 %29, ptr %32, align 4, !tbaa !5
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [233333 x i32], ptr @f, i64 0, i64 %35
  store i32 %33, ptr %36, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %27
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %2, align 4, !tbaa !5
  br label %22, !llvm.loop !11

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

41:                                               ; preds = %101, %40
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = load i32, ptr @n, align 4, !tbaa !5
  %44 = shl i32 %43, 1
  %45 = icmp sle i32 %42, %44
  br i1 %45, label %47, label %46

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

47:                                               ; preds = %41
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [233333 x i32], ptr @f, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = icmp slt i32 %48, %52
  br i1 %53, label %54, label %55

54:                                               ; preds = %47
  br label %101

55:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = call noundef i32 @_Z5queryi(i32 noundef %56)
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [233333 x i32], ptr @f, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = sub nsw i32 %61, 1
  %63 = call noundef i32 @_Z5queryi(i32 noundef %62)
  %64 = sub nsw i32 %57, %63
  store i32 %64, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %65 = load i32, ptr %5, align 4, !tbaa !5
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [233333 x i32], ptr @f, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = sub nsw i32 %65, %69
  %71 = sub nsw i32 %70, 1
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = mul nsw i32 %72, 2
  %74 = sub nsw i32 %71, %73
  store i32 %74, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %75 = load i32, ptr @n, align 4, !tbaa !5
  %76 = sub nsw i32 %75, 1
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = sub nsw i32 %76, %77
  %79 = load i32, ptr %7, align 4, !tbaa !5
  %80 = sub nsw i32 %78, %79
  store i32 %80, ptr %8, align 4, !tbaa !5
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [233333 x i32], ptr @f, i64 0, i64 %82
  %84 = load i32, ptr %83, align 4, !tbaa !5
  call void @_Z6updateii(i32 noundef %84, i32 noundef 1)
  %85 = load i32, ptr %7, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = load i32, ptr %6, align 4, !tbaa !5
  %88 = load i32, ptr %8, align 4, !tbaa !5
  %89 = add nsw i32 %87, %88
  %90 = sext i32 %89 to i64
  %91 = mul nsw i64 %86, %90
  %92 = load i64, ptr @ans1, align 8, !tbaa !9
  %93 = add nsw i64 %92, %91
  store i64 %93, ptr @ans1, align 8, !tbaa !9
  %94 = load i32, ptr %6, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = load i32, ptr %8, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = mul nsw i64 %95, %97
  %99 = load i64, ptr @ans2, align 8, !tbaa !9
  %100 = add nsw i64 %99, %98
  store i64 %100, ptr @ans2, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %101

101:                                              ; preds = %55, %54
  %102 = load i32, ptr %5, align 4, !tbaa !5
  %103 = add nsw i32 %102, 1
  store i32 %103, ptr %5, align 4, !tbaa !5
  br label %41, !llvm.loop !13

104:                                              ; preds = %46
  %105 = load i64, ptr @ans, align 8, !tbaa !9
  %106 = load i64, ptr @ans1, align 8, !tbaa !9
  %107 = sdiv i64 %106, 2
  %108 = sub nsw i64 %105, %107
  %109 = load i64, ptr @ans2, align 8, !tbaa !9
  %110 = sub nsw i64 %108, %109
  %111 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %110)
  ret i32 0
}

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

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


; 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
@f = external dso_local local_unnamed_addr global [233333 x i32], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8
@ans1 = external dso_local local_unnamed_addr global i64, align 8
@ans2 = 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 [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5queryi(i32 noundef) local_unnamed_addr #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: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = add nsw i32 %4, -1
  %7 = sext i32 %6 to i64
  %8 = mul nsw i64 %7, %5
  %9 = sdiv i64 %8, 2
  %10 = add nsw i32 %4, -2
  %11 = sext i32 %10 to i64
  %12 = mul nsw i64 %9, %11
  %13 = sdiv i64 %12, 3
  store i64 %13, ptr @ans, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %14 = icmp sgt i32 %4, 0
  br i1 %14, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %15 = phi i32 [ %4, %0 ], [ %25, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  %16 = shl i32 %15, 1
  %.not24 = icmp slt i32 %16, 1
  br i1 %.not24, label %._crit_edge28, label %.lr.ph27

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.023 = phi i32 [ %24, %.lr.ph ], [ 0, %0 ]
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [233333 x i32], ptr @f, i64 0, i64 %20
  store i32 %18, ptr %21, align 4, !tbaa !5
  %22 = sext i32 %18 to i64
  %23 = getelementptr inbounds [233333 x i32], ptr @f, i64 0, i64 %22
  store i32 %19, ptr %23, align 4, !tbaa !5
  %24 = add nuw nsw i32 %.023, 1
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge28:                                    ; preds = %65, %._crit_edge
  %27 = load i64, ptr @ans, align 8, !tbaa !9
  %28 = load i64, ptr @ans1, align 8, !tbaa !9
  %.neg = sdiv i64 %28, -2
  %29 = add i64 %.neg, %27
  %30 = load i64, ptr @ans2, align 8, !tbaa !9
  %31 = sub i64 %29, %30
  %32 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %31)
  ret i32 0

.lr.ph27:                                         ; preds = %._crit_edge, %65
  %33 = phi i32 [ %66, %65 ], [ %15, %._crit_edge ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %65 ], [ 1, %._crit_edge ]
  %34 = getelementptr inbounds [233333 x i32], ptr @f, i64 0, i64 %indvars.iv
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = icmp slt i64 %indvars.iv, %36
  br i1 %37, label %65, label %38

38:                                               ; preds = %.lr.ph27
  %39 = trunc nuw nsw i64 %indvars.iv to i32
  %40 = call noundef i32 @_Z5queryi(i32 noundef %39)
  %41 = load i32, ptr %34, align 4, !tbaa !5
  %42 = add nsw i32 %41, -1
  %43 = call noundef i32 @_Z5queryi(i32 noundef %42)
  %44 = sub nsw i32 %40, %43
  %45 = load i32, ptr %34, align 4, !tbaa !5
  %46 = xor i32 %45, -1
  %47 = add i32 %39, %46
  %48 = shl i32 %44, 1
  %49 = sub i32 %47, %48
  %50 = load i32, ptr @n, align 4, !tbaa !5
  %51 = xor i32 %44, -1
  %52 = add i32 %50, %51
  %53 = sub i32 %52, %49
  call void @_Z6updateii(i32 noundef %45, i32 noundef 1)
  %54 = sext i32 %49 to i64
  %55 = add nsw i32 %53, %44
  %56 = sext i32 %55 to i64
  %57 = mul nsw i64 %56, %54
  %58 = load i64, ptr @ans1, align 8, !tbaa !9
  %59 = add nsw i64 %57, %58
  store i64 %59, ptr @ans1, align 8, !tbaa !9
  %60 = sext i32 %44 to i64
  %61 = sext i32 %53 to i64
  %62 = mul nsw i64 %61, %60
  %63 = load i64, ptr @ans2, align 8, !tbaa !9
  %64 = add nsw i64 %63, %62
  store i64 %64, ptr @ans2, align 8, !tbaa !9
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %.lr.ph27, %38
  %66 = phi i32 [ %33, %.lr.ph27 ], [ %.pre, %38 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %67 = shl i32 %66, 1
  %68 = sext i32 %67 to i64
  %.not.not = icmp slt i64 %indvars.iv, %68
  br i1 %.not.not, label %.lr.ph27, label %._crit_edge28, !llvm.loop !13
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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