; LLVM IR from DionysiosB/CodeForces :: 1000-1099 (1099A-Snowball)

; 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 [8 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 i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %4, ptr noundef %5)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %6, ptr noundef %7)
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = add nsw i64 %11, 1
  store i64 %12, ptr %3, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %40, %0
  %14 = load i64, ptr %3, align 8, !tbaa !5
  %15 = add nsw i64 %14, -1
  store i64 %15, ptr %3, align 8, !tbaa !5
  %16 = icmp ne i64 %14, 0
  br i1 %16, label %17, label %41

17:                                               ; preds = %13
  %18 = load i64, ptr %3, align 8, !tbaa !5
  %19 = load i64, ptr %2, align 8, !tbaa !5
  %20 = add nsw i64 %19, %18
  store i64 %20, ptr %2, align 8, !tbaa !5
  %21 = load i64, ptr %3, align 8, !tbaa !5
  %22 = load i64, ptr %5, align 8, !tbaa !5
  %23 = icmp eq i64 %21, %22
  br i1 %23, label %24, label %28

24:                                               ; preds = %17
  %25 = load i64, ptr %4, align 8, !tbaa !5
  %26 = load i64, ptr %2, align 8, !tbaa !5
  %27 = sub nsw i64 %26, %25
  store i64 %27, ptr %2, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %24, %17
  %29 = load i64, ptr %3, align 8, !tbaa !5
  %30 = load i64, ptr %7, align 8, !tbaa !5
  %31 = icmp eq i64 %29, %30
  br i1 %31, label %32, label %36

32:                                               ; preds = %28
  %33 = load i64, ptr %6, align 8, !tbaa !5
  %34 = load i64, ptr %2, align 8, !tbaa !5
  %35 = sub nsw i64 %34, %33
  store i64 %35, ptr %2, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %32, %28
  %37 = load i64, ptr %2, align 8, !tbaa !5
  %38 = icmp slt i64 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %36
  store i64 0, ptr %2, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %39, %36
  br label %13, !llvm.loop !9

41:                                               ; preds = %13
  %42 = load i64, ptr %2, align 8, !tbaa !5
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %42)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  ret i32 0
}

; 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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 = { 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"}


; 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 [8 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 i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %3, ptr noundef nonnull %4)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %5, ptr noundef nonnull %6)
  %10 = load i64, ptr %2, align 8, !tbaa !5
  %.not5 = icmp eq i64 %10, -1
  %.pre = load i64, ptr %1, align 8, !tbaa !5
  br i1 %.not5, label %._crit_edge8, label %.lr.ph

.lr.ph:                                           ; preds = %0
  %11 = load i64, ptr %4, align 8, !tbaa !5
  %12 = load i64, ptr %3, align 8
  %13 = load i64, ptr %6, align 8, !tbaa !5
  %14 = load i64, ptr %5, align 8
  %15 = and i64 %10, 1
  %lcmp.mod.not.not = icmp eq i64 %15, 0
  br i1 %lcmp.mod.not.not, label %thread-pre-split.prol, label %thread-pre-split.prol.loopexit

thread-pre-split.prol:                            ; preds = %.lr.ph
  %16 = add nsw i64 %.pre, %10
  %17 = icmp eq i64 %10, %11
  %18 = select i1 %17, i64 %12, i64 0
  %19 = icmp eq i64 %10, %13
  %20 = select i1 %19, i64 %14, i64 0
  %21 = add i64 %18, %20
  %22 = sub i64 %16, %21
  %.pr14.prol = call i64 @llvm.smax.i64(i64 %22, i64 0)
  %23 = add nsw i64 %10, -1
  br label %thread-pre-split.prol.loopexit

thread-pre-split.prol.loopexit:                   ; preds = %thread-pre-split.prol, %.lr.ph
  %.pr14.lcssa.unr = phi i64 [ poison, %.lr.ph ], [ %.pr14.prol, %thread-pre-split.prol ]
  %.unr = phi i64 [ %10, %.lr.ph ], [ %23, %thread-pre-split.prol ]
  %.pr136.unr = phi i64 [ %.pre, %.lr.ph ], [ %.pr14.prol, %thread-pre-split.prol ]
  %24 = icmp eq i64 %10, 0
  br i1 %24, label %._crit_edge, label %thread-pre-split

thread-pre-split:                                 ; preds = %thread-pre-split.prol.loopexit, %thread-pre-split
  %25 = phi i64 [ %41, %thread-pre-split ], [ %.unr, %thread-pre-split.prol.loopexit ]
  %.pr136 = phi i64 [ %.pr14.1, %thread-pre-split ], [ %.pr136.unr, %thread-pre-split.prol.loopexit ]
  %26 = add nsw i64 %.pr136, %25
  %27 = icmp eq i64 %25, %11
  %28 = select i1 %27, i64 %12, i64 0
  %29 = icmp eq i64 %25, %13
  %30 = select i1 %29, i64 %14, i64 0
  %31 = add i64 %28, %30
  %32 = sub i64 %26, %31
  %.pr14 = call i64 @llvm.smax.i64(i64 %32, i64 0)
  %33 = add nsw i64 %25, -1
  %34 = add nsw i64 %.pr14, %33
  %35 = icmp eq i64 %33, %11
  %36 = select i1 %35, i64 %12, i64 0
  %37 = icmp eq i64 %33, %13
  %38 = select i1 %37, i64 %14, i64 0
  %39 = add i64 %36, %38
  %40 = sub i64 %34, %39
  %.pr14.1 = call i64 @llvm.smax.i64(i64 %40, i64 0)
  %41 = add nsw i64 %25, -2
  %.not.1 = icmp eq i64 %33, 0
  br i1 %.not.1, label %._crit_edge, label %thread-pre-split, !llvm.loop !9

._crit_edge:                                      ; preds = %thread-pre-split, %thread-pre-split.prol.loopexit
  %.pr14.lcssa = phi i64 [ %.pr14.lcssa.unr, %thread-pre-split.prol.loopexit ], [ %.pr14.1, %thread-pre-split ]
  store i64 %.pr14.lcssa, ptr %1, align 8, !tbaa !5
  br label %._crit_edge8

._crit_edge8:                                     ; preds = %0, %._crit_edge
  %42 = phi i64 [ %.pr14.lcssa, %._crit_edge ], [ %.pre, %0 ]
  store i64 -1, ptr %2, align 8, !tbaa !5
  %43 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %42)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  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: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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

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

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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"}


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