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

; 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 i64, align 8
@len = external dso_local global i64, align 8
@x = external dso_local global i64, align 8
@y = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@_ZL2dx = external hidden constant [6 x i32], align 16
@_ZL2dy = external hidden constant [6 x i32], align 16
@.str.2 = external hidden unnamed_addr constant [13 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
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %5 = load i64, ptr @n, align 8, !tbaa !5
  %6 = icmp ne i64 %5, 0
  br i1 %6, label %9, label %7

7:                                                ; preds = %0
  %8 = call i32 @puts(ptr noundef @.str.1)
  store i32 0, ptr %1, align 4
  br label %119

9:                                                ; preds = %0
  %10 = load i64, ptr @n, align 8, !tbaa !5
  %11 = sdiv i64 %10, 3
  %12 = call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %11)
  %13 = fptosi double %12 to i64
  store i64 %13, ptr @len, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %22, %9
  %15 = load i64, ptr @len, align 8, !tbaa !5
  %16 = load i64, ptr @len, align 8, !tbaa !5
  %17 = add nsw i64 %16, 1
  %18 = mul nsw i64 %15, %17
  %19 = mul nsw i64 %18, 3
  %20 = load i64, ptr @n, align 8, !tbaa !5
  %21 = icmp sgt i64 %19, %20
  br i1 %21, label %22, label %25

22:                                               ; preds = %14
  %23 = load i64, ptr @len, align 8, !tbaa !5
  %24 = add nsw i64 %23, -1
  store i64 %24, ptr @len, align 8, !tbaa !5
  br label %14, !llvm.loop !9

25:                                               ; preds = %14
  br label %26

26:                                               ; preds = %34, %25
  %27 = load i64, ptr @len, align 8, !tbaa !5
  %28 = load i64, ptr @len, align 8, !tbaa !5
  %29 = add nsw i64 %28, 1
  %30 = mul nsw i64 %27, %29
  %31 = mul nsw i64 %30, 3
  %32 = load i64, ptr @n, align 8, !tbaa !5
  %33 = icmp sle i64 %31, %32
  br i1 %33, label %34, label %37

34:                                               ; preds = %26
  %35 = load i64, ptr @len, align 8, !tbaa !5
  %36 = add nsw i64 %35, 1
  store i64 %36, ptr @len, align 8, !tbaa !5
  br label %26, !llvm.loop !11

37:                                               ; preds = %26
  %38 = load i64, ptr @len, align 8, !tbaa !5
  %39 = sub nsw i64 %38, 1
  %40 = mul nsw i64 %39, 2
  store i64 %40, ptr @x, align 8, !tbaa !5
  store i64 0, ptr @y, align 8, !tbaa !5
  %41 = load i64, ptr @len, align 8, !tbaa !5
  %42 = load i64, ptr @len, align 8, !tbaa !5
  %43 = sub nsw i64 %42, 1
  %44 = mul nsw i64 %41, %43
  %45 = mul nsw i64 %44, 3
  %46 = load i64, ptr @n, align 8, !tbaa !5
  %47 = sub nsw i64 %46, %45
  store i64 %47, ptr @n, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !12
  br label %48

48:                                               ; preds = %112, %37
  %49 = load i32, ptr %2, align 4, !tbaa !12
  %50 = icmp slt i32 %49, 6
  br i1 %50, label %51, label %54

51:                                               ; preds = %48
  %52 = load i64, ptr @n, align 8, !tbaa !5
  %53 = icmp ne i64 %52, 0
  br label %54

54:                                               ; preds = %51, %48
  %55 = phi i1 [ false, %48 ], [ %53, %51 ]
  br i1 %55, label %57, label %56

56:                                               ; preds = %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %115

57:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %58 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) @n, ptr noundef nonnull align 8 dereferenceable(8) @len)
  %59 = load i64, ptr %58, align 8, !tbaa !5
  %60 = trunc i64 %59 to i32
  store i32 %60, ptr %3, align 4, !tbaa !12
  %61 = load i32, ptr %2, align 4, !tbaa !12
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %88, label %63

63:                                               ; preds = %57
  %64 = load i32, ptr getelementptr inbounds ([6 x i32], ptr @_ZL2dx, i64 0, i64 5), align 4, !tbaa !12
  %65 = load i32, ptr %2, align 4, !tbaa !12
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [6 x i32], ptr @_ZL2dx, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !12
  %69 = load i32, ptr %3, align 4, !tbaa !12
  %70 = sub nsw i32 %69, 1
  %71 = mul nsw i32 %68, %70
  %72 = add nsw i32 %64, %71
  %73 = sext i32 %72 to i64
  %74 = load i64, ptr @x, align 8, !tbaa !5
  %75 = add nsw i64 %74, %73
  store i64 %75, ptr @x, align 8, !tbaa !5
  %76 = load i32, ptr getelementptr inbounds ([6 x i32], ptr @_ZL2dy, i64 0, i64 5), align 4, !tbaa !12
  %77 = load i32, ptr %2, align 4, !tbaa !12
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [6 x i32], ptr @_ZL2dy, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !12
  %81 = load i32, ptr %3, align 4, !tbaa !12
  %82 = sub nsw i32 %81, 1
  %83 = mul nsw i32 %80, %82
  %84 = add nsw i32 %76, %83
  %85 = sext i32 %84 to i64
  %86 = load i64, ptr @y, align 8, !tbaa !5
  %87 = add nsw i64 %86, %85
  store i64 %87, ptr @y, align 8, !tbaa !5
  br label %107

88:                                               ; preds = %57
  %89 = load i32, ptr %2, align 4, !tbaa !12
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [6 x i32], ptr @_ZL2dx, i64 0, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !12
  %93 = load i32, ptr %3, align 4, !tbaa !12
  %94 = mul nsw i32 %92, %93
  %95 = sext i32 %94 to i64
  %96 = load i64, ptr @x, align 8, !tbaa !5
  %97 = add nsw i64 %96, %95
  store i64 %97, ptr @x, align 8, !tbaa !5
  %98 = load i32, ptr %2, align 4, !tbaa !12
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [6 x i32], ptr @_ZL2dy, i64 0, i64 %99
  %101 = load i32, ptr %100, align 4, !tbaa !12
  %102 = load i32, ptr %3, align 4, !tbaa !12
  %103 = mul nsw i32 %101, %102
  %104 = sext i32 %103 to i64
  %105 = load i64, ptr @y, align 8, !tbaa !5
  %106 = add nsw i64 %105, %104
  store i64 %106, ptr @y, align 8, !tbaa !5
  br label %107

107:                                              ; preds = %88, %63
  %108 = load i32, ptr %3, align 4, !tbaa !12
  %109 = sext i32 %108 to i64
  %110 = load i64, ptr @n, align 8, !tbaa !5
  %111 = sub nsw i64 %110, %109
  store i64 %111, ptr @n, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %112

112:                                              ; preds = %107
  %113 = load i32, ptr %2, align 4, !tbaa !12
  %114 = add nsw i32 %113, 1
  store i32 %114, ptr %2, align 4, !tbaa !12
  br label %48, !llvm.loop !14

115:                                              ; preds = %56
  %116 = load i64, ptr @x, align 8, !tbaa !5
  %117 = load i64, ptr @y, align 8, !tbaa !5
  %118 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %116, i64 noundef %117)
  store i32 0, ptr %1, align 4
  br label %119

119:                                              ; preds = %115, %7
  %120 = load i32, ptr %1, align 4
  ret i32 %120
}

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

declare i32 @puts(ptr noundef) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef) #2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #2

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

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 = { inlinehint 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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long long", !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 = !{!"int", !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 i64, align 8
@len = external dso_local global i64, align 8
@x = external dso_local local_unnamed_addr global i64, align 8
@y = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@_ZL2dx = external hidden local_unnamed_addr constant [6 x i32], align 16
@_ZL2dy = external hidden local_unnamed_addr constant [6 x i32], align 16
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: mustprogress 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)
  %2 = load i64, ptr @n, align 8, !tbaa !5
  %.not = icmp eq i64 %2, 0
  br i1 %.not, label %3, label %5

3:                                                ; preds = %0
  %4 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %72

5:                                                ; preds = %0
  %6 = sdiv i64 %2, 3
  %7 = tail call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %6)
  %8 = fptosi double %7 to i64
  %9 = load i64, ptr @n, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %10, %5
  %storemerge = phi i64 [ %8, %5 ], [ %15, %10 ]
  %11 = add nsw i64 %storemerge, 1
  %12 = mul i64 %storemerge, 3
  %13 = mul i64 %12, %11
  %14 = icmp sgt i64 %13, %9
  %15 = add nsw i64 %storemerge, -1
  br i1 %14, label %10, label %.lr.ph, !llvm.loop !9

.lr.ph:                                           ; preds = %10, %.lr.ph
  %16 = phi i64 [ %17, %.lr.ph ], [ %11, %10 ]
  %17 = add nsw i64 %16, 1
  %18 = mul i64 %16, 3
  %19 = mul i64 %18, %17
  %.not14 = icmp sgt i64 %19, %9
  br i1 %.not14, label %20, label %.lr.ph, !llvm.loop !11

20:                                               ; preds = %.lr.ph
  store i64 %16, ptr @len, align 8, !tbaa !5
  %21 = shl i64 %16, 1
  %22 = add i64 %21, -2
  store i64 %22, ptr @x, align 8, !tbaa !5
  store i64 0, ptr @y, align 8, !tbaa !5
  %23 = add nsw i64 %16, -1
  %24 = mul i64 %16, -3
  %.neg = mul i64 %24, %23
  %25 = add i64 %.neg, %9
  store i64 %25, ptr @n, align 8, !tbaa !5
  %.not24 = icmp eq i64 %25, 0
  br i1 %.not24, label %._crit_edge23, label %26

26:                                               ; preds = %20
  %27 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL2dx, i64 20), align 4
  %28 = load i32, ptr @_ZL2dx, align 16
  %29 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL2dy, i64 20), align 4
  %30 = load i32, ptr @_ZL2dy, align 16
  %31 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) @n, ptr noundef nonnull align 8 dereferenceable(8) @len)
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = load i64, ptr @y, align 8, !tbaa !5
  %34 = trunc i64 %32 to i32
  %35 = add nsw i32 %34, -1
  %36 = mul nsw i32 %30, %35
  %37 = add nsw i32 %36, %29
  %38 = sext i32 %37 to i64
  %39 = add nsw i64 %33, %38
  %40 = load i64, ptr @x, align 8, !tbaa !5
  %41 = mul nsw i32 %28, %35
  %42 = add nsw i32 %41, %27
  %43 = sext i32 %42 to i64
  %44 = add nsw i64 %40, %43
  store i64 %44, ptr @x, align 8
  store i64 %39, ptr @y, align 8, !tbaa !5
  %sext.peel = shl i64 %32, 32
  %45 = ashr exact i64 %sext.peel, 32
  %46 = load i64, ptr @n, align 8, !tbaa !5
  %47 = sub nsw i64 %46, %45
  store i64 %47, ptr @n, align 8, !tbaa !5
  %.not29 = icmp eq i64 %46, %45
  br i1 %.not29, label %._crit_edge23, label %.peel.next

._crit_edge23:                                    ; preds = %.peel.next, %26, %20
  %48 = phi i64 [ 0, %20 ], [ %39, %26 ], [ %65, %.peel.next ]
  %49 = phi i64 [ %22, %20 ], [ %44, %26 ], [ %59, %.peel.next ]
  %50 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %49, i64 noundef %48)
  br label %72

.peel.next:                                       ; preds = %26, %.peel.next
  %indvars.iv = phi i64 [ %indvars.iv.next, %.peel.next ], [ 1, %26 ]
  %51 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) @n, ptr noundef nonnull align 8 dereferenceable(8) @len)
  %52 = load i64, ptr %51, align 8, !tbaa !5
  %53 = trunc i64 %52 to i32
  %54 = getelementptr inbounds [6 x i32], ptr @_ZL2dx, i64 0, i64 %indvars.iv
  %55 = load i32, ptr %54, align 4, !tbaa !12
  %56 = mul nsw i32 %55, %53
  %57 = sext i32 %56 to i64
  %58 = load i64, ptr @x, align 8, !tbaa !5
  %59 = add nsw i64 %58, %57
  %60 = getelementptr inbounds [6 x i32], ptr @_ZL2dy, i64 0, i64 %indvars.iv
  %61 = load i32, ptr %60, align 4, !tbaa !12
  %62 = mul nsw i32 %61, %53
  %63 = sext i32 %62 to i64
  %64 = load i64, ptr @y, align 8, !tbaa !5
  %65 = add nsw i64 %64, %63
  store i64 %59, ptr @x, align 8
  store i64 %65, ptr @y, align 8, !tbaa !5
  %sext = shl i64 %52, 32
  %66 = ashr exact i64 %sext, 32
  %67 = load i64, ptr @n, align 8, !tbaa !5
  %68 = sub nsw i64 %67, %66
  store i64 %68, ptr @n, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %69 = icmp ult i64 %indvars.iv, 5
  %70 = icmp ne i64 %67, %66
  %71 = select i1 %69, i1 %70, i1 false
  br i1 %71, label %.peel.next, label %._crit_edge23, !llvm.loop !14

72:                                               ; preds = %._crit_edge23, %3
  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 @puts(ptr nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

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

attributes #0 = { 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 #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" }
attributes #2 = { inlinehint 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" }

!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 = !{!"long long", !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 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !10, !15}
!15 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass