; LLVM IR from Izaron/ACM-ICPC :: Timus Online Judge/Volume 4/1330. Intervals (main)

; 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 [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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

12:                                               ; preds = %22, %0
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %12
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [10000 x i32], ptr %3, i64 0, i64 %19
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %20)
  br label %22

22:                                               ; preds = %17
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %5, align 4, !tbaa !5
  br label %12, !llvm.loop !9

25:                                               ; preds = %16
  %26 = getelementptr inbounds [10000 x i32], ptr %3, i64 0, i64 0
  %27 = load i32, ptr %26, align 16, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [10000 x i64], ptr %4, i64 0, i64 0
  store i64 %28, ptr %29, align 16, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %50, %25
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %53

35:                                               ; preds = %30
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = sub nsw i32 %36, 1
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [10000 x i64], ptr %4, i64 0, i64 %38
  %40 = load i64, ptr %39, align 8, !tbaa !11
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [10000 x i32], ptr %3, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = add nsw i64 %40, %45
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [10000 x i64], ptr %4, i64 0, i64 %48
  store i64 %46, ptr %49, align 8, !tbaa !11
  br label %50

50:                                               ; preds = %35
  %51 = load i32, ptr %6, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %6, align 4, !tbaa !5
  br label %30, !llvm.loop !13

53:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %54 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %7)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %85, %53
  %56 = load i32, ptr %8, align 4, !tbaa !5
  %57 = load i32, ptr %7, align 4, !tbaa !5
  %58 = icmp slt i32 %56, %57
  br i1 %58, label %60, label %59

59:                                               ; preds = %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %88

60:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %61 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %9, ptr noundef %10)
  %62 = load i32, ptr %9, align 4, !tbaa !5
  %63 = icmp sge i32 %62, 2
  br i1 %63, label %64, label %77

64:                                               ; preds = %60
  %65 = load i32, ptr %10, align 4, !tbaa !5
  %66 = sub nsw i32 %65, 1
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [10000 x i64], ptr %4, i64 0, i64 %67
  %69 = load i64, ptr %68, align 8, !tbaa !11
  %70 = load i32, ptr %9, align 4, !tbaa !5
  %71 = sub nsw i32 %70, 2
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [10000 x i64], ptr %4, i64 0, i64 %72
  %74 = load i64, ptr %73, align 8, !tbaa !11
  %75 = sub nsw i64 %69, %74
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %75)
  br label %84

77:                                               ; preds = %60
  %78 = load i32, ptr %10, align 4, !tbaa !5
  %79 = sub nsw i32 %78, 1
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [10000 x i64], ptr %4, i64 0, i64 %80
  %82 = load i64, ptr %81, align 8, !tbaa !11
  %83 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %82)
  br label %84

84:                                               ; preds = %77, %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %8, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %8, align 4, !tbaa !5
  br label %55, !llvm.loop !14

88:                                               ; preds = %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 80000, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 40000, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  %89 = load i32, ptr %1, align 4
  ret i32 %89
}

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"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}


; 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 [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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca i32, align 4
  %2 = alloca [10000 x i32], align 16
  %3 = alloca [10000 x i64], align 16
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  call void @llvm.lifetime.start.p0(i64 40000, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 80000, ptr nonnull %3) #3
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %0
  store i64 0, ptr %3, align 16, !tbaa !9
  br label %._crit_edge18

._crit_edge:                                      ; preds = %.lr.ph
  %.pre = load i32, ptr %2, align 16, !tbaa !5
  %10 = sext i32 %.pre to i64
  store i64 %10, ptr %3, align 16, !tbaa !9
  %11 = icmp sgt i32 %17, 1
  br i1 %11, label %.lr.ph17.preheader, label %._crit_edge18

.lr.ph17.preheader:                               ; preds = %._crit_edge
  %wide.trip.count = zext nneg i32 %17 to i64
  %12 = add nsw i64 %wide.trip.count, -1
  %13 = add nsw i64 %wide.trip.count, -2
  %xtraiter = and i64 %12, 3
  %14 = icmp ult i64 %13, 3
  br i1 %14, label %._crit_edge18.loopexit.unr-lcssa, label %.lr.ph17.preheader.new

.lr.ph17.preheader.new:                           ; preds = %.lr.ph17.preheader
  %unroll_iter = and i64 %12, -4
  br label %.lr.ph17

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %15 = getelementptr inbounds [10000 x i32], ptr %2, i64 0, i64 %indvars.iv
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %15)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = icmp slt i64 %indvars.iv.next, %18
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge18.loopexit.unr-lcssa:                 ; preds = %.lr.ph17, %.lr.ph17.preheader
  %.unr = phi i64 [ %10, %.lr.ph17.preheader ], [ %48, %.lr.ph17 ]
  %indvars.iv25.unr = phi i64 [ 1, %.lr.ph17.preheader ], [ %indvars.iv.next26.3, %.lr.ph17 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge18, label %.lr.ph17.epil

.lr.ph17.epil:                                    ; preds = %._crit_edge18.loopexit.unr-lcssa, %.lr.ph17.epil
  %20 = phi i64 [ %24, %.lr.ph17.epil ], [ %.unr, %._crit_edge18.loopexit.unr-lcssa ]
  %indvars.iv25.epil = phi i64 [ %indvars.iv.next26.epil, %.lr.ph17.epil ], [ %indvars.iv25.unr, %._crit_edge18.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph17.epil ], [ 0, %._crit_edge18.loopexit.unr-lcssa ]
  %21 = getelementptr inbounds [10000 x i32], ptr %2, i64 0, i64 %indvars.iv25.epil
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = add nsw i64 %20, %23
  %25 = getelementptr inbounds [10000 x i64], ptr %3, i64 0, i64 %indvars.iv25.epil
  store i64 %24, ptr %25, align 8, !tbaa !9
  %indvars.iv.next26.epil = add nuw nsw i64 %indvars.iv25.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge18, label %.lr.ph17.epil, !llvm.loop !13

._crit_edge18:                                    ; preds = %._crit_edge18.loopexit.unr-lcssa, %.lr.ph17.epil, %._crit_edge.thread, %._crit_edge
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %26 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %4)
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %.lr.ph21, label %._crit_edge22

.lr.ph17:                                         ; preds = %.lr.ph17, %.lr.ph17.preheader.new
  %29 = phi i64 [ %10, %.lr.ph17.preheader.new ], [ %48, %.lr.ph17 ]
  %indvars.iv25 = phi i64 [ 1, %.lr.ph17.preheader.new ], [ %indvars.iv.next26.3, %.lr.ph17 ]
  %niter = phi i64 [ 0, %.lr.ph17.preheader.new ], [ %niter.next.3, %.lr.ph17 ]
  %30 = getelementptr inbounds [10000 x i32], ptr %2, i64 0, i64 %indvars.iv25
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = add nsw i64 %29, %32
  %34 = getelementptr inbounds [10000 x i64], ptr %3, i64 0, i64 %indvars.iv25
  store i64 %33, ptr %34, align 8, !tbaa !9
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %35 = getelementptr inbounds [10000 x i32], ptr %2, i64 0, i64 %indvars.iv.next26
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = add nsw i64 %33, %37
  %39 = getelementptr inbounds [10000 x i64], ptr %3, i64 0, i64 %indvars.iv.next26
  store i64 %38, ptr %39, align 8, !tbaa !9
  %indvars.iv.next26.1 = add nuw nsw i64 %indvars.iv25, 2
  %40 = getelementptr inbounds [10000 x i32], ptr %2, i64 0, i64 %indvars.iv.next26.1
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = add nsw i64 %38, %42
  %44 = getelementptr inbounds [10000 x i64], ptr %3, i64 0, i64 %indvars.iv.next26.1
  store i64 %43, ptr %44, align 8, !tbaa !9
  %indvars.iv.next26.2 = add nuw nsw i64 %indvars.iv25, 3
  %45 = getelementptr inbounds [10000 x i32], ptr %2, i64 0, i64 %indvars.iv.next26.2
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = add nsw i64 %43, %47
  %49 = getelementptr inbounds [10000 x i64], ptr %3, i64 0, i64 %indvars.iv.next26.2
  store i64 %48, ptr %49, align 8, !tbaa !9
  %indvars.iv.next26.3 = add nuw nsw i64 %indvars.iv25, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge18.loopexit.unr-lcssa, label %.lr.ph17, !llvm.loop !15

._crit_edge22:                                    ; preds = %64, %._crit_edge18
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 80000, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 40000, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  ret i32 0

.lr.ph21:                                         ; preds = %._crit_edge18, %64
  %.019 = phi i32 [ %66, %64 ], [ 0, %._crit_edge18 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  %50 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %5, ptr noundef nonnull %6)
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = icmp sgt i32 %51, 1
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = add nsw i32 %53, -1
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [10000 x i64], ptr %3, i64 0, i64 %55
  %57 = load i64, ptr %56, align 8, !tbaa !9
  br i1 %52, label %58, label %64

58:                                               ; preds = %.lr.ph21
  %59 = add nsw i32 %51, -2
  %60 = zext nneg i32 %59 to i64
  %61 = getelementptr inbounds [10000 x i64], ptr %3, i64 0, i64 %60
  %62 = load i64, ptr %61, align 8, !tbaa !9
  %63 = sub nsw i64 %57, %62
  br label %64

64:                                               ; preds = %.lr.ph21, %58
  %.sink = phi i64 [ %63, %58 ], [ %57, %.lr.ph21 ]
  %65 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %.sink)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  %66 = add nuw nsw i32 %.019, 1
  %67 = load i32, ptr %4, align 4, !tbaa !5
  %68 = icmp slt i32 %66, %67
  br i1 %68, label %.lr.ph21, label %._crit_edge22, !llvm.loop !16
}

; 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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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, !14}
!14 = !{!"llvm.loop.unroll.disable"}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}


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