; LLVM IR from DionysiosB/CodeForces :: 1400-1499 (1490B-BalancedRemainders)

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

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca [3 x i64], align 16
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  br label %12

12:                                               ; preds = %76, %0
  %13 = load i64, ptr %2, align 8, !tbaa !5
  %14 = add nsw i64 %13, -1
  store i64 %14, ptr %2, align 8, !tbaa !5
  %15 = icmp ne i64 %13, 0
  br i1 %15, label %16, label %79

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 24, ptr %4) #4
  call void @llvm.memset.p0.i64(ptr align 16 %4, i8 0, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store i64 0, ptr %5, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %30, %16
  %19 = load i64, ptr %5, align 8, !tbaa !5
  %20 = load i64, ptr %3, align 8, !tbaa !5
  %21 = icmp slt i64 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %33

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %24 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %6)
  %25 = load i64, ptr %6, align 8, !tbaa !5
  %26 = srem i64 %25, 3
  %27 = getelementptr inbounds [3 x i64], ptr %4, i64 0, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = add nsw i64 %28, 1
  store i64 %29, ptr %27, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %30

30:                                               ; preds = %23
  %31 = load i64, ptr %5, align 8, !tbaa !5
  %32 = add nsw i64 %31, 1
  store i64 %32, ptr %5, align 8, !tbaa !5
  br label %18, !llvm.loop !9

33:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 0, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 0, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 0, ptr %9, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %73, %33
  %35 = load i64, ptr %9, align 8, !tbaa !5
  %36 = icmp slt i64 %35, 10
  br i1 %36, label %38, label %37

37:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %76

38:                                               ; preds = %34
  %39 = load i64, ptr %8, align 8, !tbaa !5
  %40 = load i64, ptr %7, align 8, !tbaa !5
  %41 = add nsw i64 %40, %39
  store i64 %41, ptr %7, align 8, !tbaa !5
  %42 = load i64, ptr %8, align 8, !tbaa !5
  %43 = load i64, ptr %9, align 8, !tbaa !5
  %44 = srem i64 %43, 3
  %45 = getelementptr inbounds [3 x i64], ptr %4, i64 0, i64 %44
  %46 = load i64, ptr %45, align 8, !tbaa !5
  %47 = add nsw i64 %46, %42
  store i64 %47, ptr %45, align 8, !tbaa !5
  store i64 0, ptr %8, align 8, !tbaa !5
  %48 = load i64, ptr %9, align 8, !tbaa !5
  %49 = srem i64 %48, 3
  %50 = getelementptr inbounds [3 x i64], ptr %4, i64 0, i64 %49
  %51 = load i64, ptr %50, align 8, !tbaa !5
  %52 = load i64, ptr %3, align 8, !tbaa !5
  %53 = sdiv i64 %52, 3
  %54 = icmp sgt i64 %51, %53
  br i1 %54, label %55, label %72

55:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %56 = load i64, ptr %9, align 8, !tbaa !5
  %57 = srem i64 %56, 3
  %58 = getelementptr inbounds [3 x i64], ptr %4, i64 0, i64 %57
  %59 = load i64, ptr %58, align 8, !tbaa !5
  %60 = load i64, ptr %3, align 8, !tbaa !5
  %61 = sdiv i64 %60, 3
  %62 = sub nsw i64 %59, %61
  store i64 %62, ptr %10, align 8, !tbaa !5
  %63 = load i64, ptr %10, align 8, !tbaa !5
  %64 = load i64, ptr %8, align 8, !tbaa !5
  %65 = add nsw i64 %64, %63
  store i64 %65, ptr %8, align 8, !tbaa !5
  %66 = load i64, ptr %10, align 8, !tbaa !5
  %67 = load i64, ptr %9, align 8, !tbaa !5
  %68 = srem i64 %67, 3
  %69 = getelementptr inbounds [3 x i64], ptr %4, i64 0, i64 %68
  %70 = load i64, ptr %69, align 8, !tbaa !5
  %71 = sub nsw i64 %70, %66
  store i64 %71, ptr %69, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %72

72:                                               ; preds = %55, %38
  br label %73

73:                                               ; preds = %72
  %74 = load i64, ptr %9, align 8, !tbaa !5
  %75 = add nsw i64 %74, 1
  store i64 %75, ptr %9, align 8, !tbaa !5
  br label %34, !llvm.loop !11

76:                                               ; preds = %37
  %77 = load i64, ptr %7, align 8, !tbaa !5
  %78 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %77)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %12, !llvm.loop !12

79:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %80 = load i32, ptr %1, align 4
  ret i32 %80
}

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

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

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

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

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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", !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"

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca [3 x i64], align 16
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %6 = load i64, ptr %1, align 8, !tbaa !5
  %7 = add nsw i64 %6, -1
  store i64 %7, ptr %1, align 8, !tbaa !5
  %.not26 = icmp eq i64 %6, 0
  br i1 %.not26, label %._crit_edge, label %.lr.ph27.preheader

.lr.ph27.preheader:                               ; preds = %0
  %.phi.trans.insert = getelementptr inbounds i8, ptr %3, i64 8
  %.phi.trans.insert31 = getelementptr inbounds i8, ptr %3, i64 16
  br label %.lr.ph27

.lr.ph27:                                         ; preds = %.lr.ph27.preheader, %.preheader
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(24) %3, i8 0, i64 24, i1 false)
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = icmp sgt i64 %9, 0
  br i1 %10, label %.lr.ph, label %.preheader

.preheader.loopexit:                              ; preds = %.lr.ph
  %.pre = load i64, ptr %3, align 16, !tbaa !5
  %.pre30 = load i64, ptr %.phi.trans.insert, align 8, !tbaa !5
  %.pre32 = load i64, ptr %.phi.trans.insert31, align 16, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit, %.lr.ph27
  %11 = phi i64 [ 0, %.lr.ph27 ], [ %.pre32, %.preheader.loopexit ]
  %12 = phi i64 [ 0, %.lr.ph27 ], [ %.pre30, %.preheader.loopexit ]
  %13 = phi i64 [ 0, %.lr.ph27 ], [ %.pre, %.preheader.loopexit ]
  %.lcssa = phi i64 [ %9, %.lr.ph27 ], [ %59, %.preheader.loopexit ]
  %14 = sdiv i64 %.lcssa, 3
  %15 = icmp sgt i64 %13, %14
  %16 = sub nsw i64 %13, %14
  %spec.select = call i64 @llvm.smin.i64(i64 %13, i64 %14)
  %spec.select21 = select i1 %15, i64 %16, i64 0
  %17 = add nsw i64 %12, %spec.select21
  %18 = icmp sgt i64 %17, %14
  %19 = sub nsw i64 %17, %14
  %spec.select.1 = call i64 @llvm.smin.i64(i64 %17, i64 %14)
  %spec.select21.1 = select i1 %18, i64 %19, i64 0
  %20 = add nsw i64 %spec.select21.1, %spec.select21
  %21 = add nsw i64 %11, %spec.select21.1
  %22 = icmp sgt i64 %21, %14
  %23 = sub nsw i64 %21, %14
  %spec.select.2 = call i64 @llvm.smin.i64(i64 %21, i64 %14)
  %spec.select21.2 = select i1 %22, i64 %23, i64 0
  %24 = add nsw i64 %spec.select21.2, %20
  %25 = add nsw i64 %spec.select, %spec.select21.2
  %26 = icmp sgt i64 %25, %14
  %27 = sub nsw i64 %25, %14
  %spec.select.3 = call i64 @llvm.smin.i64(i64 %25, i64 %14)
  %spec.select21.3 = select i1 %26, i64 %27, i64 0
  %28 = add nsw i64 %spec.select21.3, %24
  %29 = add nsw i64 %spec.select.1, %spec.select21.3
  %30 = icmp sgt i64 %29, %14
  %31 = sub nsw i64 %29, %14
  %spec.select.4 = call i64 @llvm.smin.i64(i64 %29, i64 %14)
  %spec.select21.4 = select i1 %30, i64 %31, i64 0
  %32 = add nsw i64 %spec.select21.4, %28
  %33 = add nsw i64 %spec.select.2, %spec.select21.4
  %34 = icmp sgt i64 %33, %14
  %35 = sub nsw i64 %33, %14
  %spec.select.5 = call i64 @llvm.smin.i64(i64 %33, i64 %14)
  %spec.select21.5 = select i1 %34, i64 %35, i64 0
  %36 = add nsw i64 %spec.select21.5, %32
  %37 = add nsw i64 %spec.select.3, %spec.select21.5
  %38 = icmp sgt i64 %37, %14
  %39 = sub nsw i64 %37, %14
  %spec.select21.6 = select i1 %38, i64 %39, i64 0
  %40 = add nsw i64 %spec.select21.6, %36
  %41 = add nsw i64 %spec.select.4, %spec.select21.6
  %42 = icmp sgt i64 %41, %14
  %43 = sub nsw i64 %41, %14
  %spec.select21.7 = select i1 %42, i64 %43, i64 0
  %44 = add nsw i64 %spec.select21.7, %40
  %45 = add nsw i64 %spec.select.5, %spec.select21.7
  %46 = icmp sgt i64 %45, %14
  %47 = sub nsw i64 %45, %14
  %spec.select21.8 = select i1 %46, i64 %47, i64 0
  %48 = add nsw i64 %spec.select21.8, %44
  %49 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %48)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  %50 = load i64, ptr %1, align 8, !tbaa !5
  %51 = add nsw i64 %50, -1
  store i64 %51, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %50, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph27, !llvm.loop !9

.lr.ph:                                           ; preds = %.lr.ph27, %.lr.ph
  %.022 = phi i64 [ %58, %.lr.ph ], [ 0, %.lr.ph27 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  %52 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %4)
  %53 = load i64, ptr %4, align 8, !tbaa !5
  %54 = srem i64 %53, 3
  %55 = getelementptr inbounds [3 x i64], ptr %3, i64 0, i64 %54
  %56 = load i64, ptr %55, align 8, !tbaa !5
  %57 = add nsw i64 %56, 1
  store i64 %57, ptr %55, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  %58 = add nuw nsw i64 %.022, 1
  %59 = load i64, ptr %2, align 8, !tbaa !5
  %60 = icmp slt i64 %58, %59
  br i1 %60, label %.lr.ph, label %.preheader.loopexit, !llvm.loop !11

._crit_edge:                                      ; preds = %.preheader, %0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  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: 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: 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 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #4

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 nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"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}


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