; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/Other/DIBZ2016/DZ16HITE (A)

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

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@p = external dso_local global [1000001 x double], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 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
  store double 0.000000e+00, ptr getelementptr inbounds ([1000001 x double], ptr @p, i64 0, i64 1), align 8, !tbaa !5
  store double 1.000000e+00, ptr getelementptr inbounds ([1000001 x double], ptr @p, i64 0, i64 2), align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 3, ptr %2, align 4, !tbaa !9
  br label %4

4:                                                ; preds = %25, %0
  %5 = load i32, ptr %2, align 4, !tbaa !9
  %6 = icmp slt i32 %5, 1000001
  br i1 %6, label %8, label %7

7:                                                ; preds = %4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %28

8:                                                ; preds = %4
  %9 = load i32, ptr %2, align 4, !tbaa !9
  %10 = sub nsw i32 %9, 1
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [1000001 x double], ptr @p, i64 0, i64 %11
  %13 = load double, ptr %12, align 8, !tbaa !5
  %14 = load i32, ptr %2, align 4, !tbaa !9
  %15 = sub nsw i32 %14, 2
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [1000001 x double], ptr @p, i64 0, i64 %16
  %18 = load double, ptr %17, align 8, !tbaa !5
  %19 = fadd double %13, %18
  %20 = fdiv double %19, 2.000000e+00
  %21 = fadd double 1.000000e+00, %20
  %22 = load i32, ptr %2, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [1000001 x double], ptr @p, i64 0, i64 %23
  store double %21, ptr %24, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %8
  %26 = load i32, ptr %2, align 4, !tbaa !9
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %2, align 4, !tbaa !9
  br label %4, !llvm.loop !11

28:                                               ; preds = %7
  %29 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %42, %28
  %31 = load i32, ptr %3, align 4, !tbaa !9
  %32 = load i32, ptr @t, align 4, !tbaa !9
  %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 %3) #3
  br label %45

35:                                               ; preds = %30
  %36 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %37 = load i32, ptr @n, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [1000001 x double], ptr @p, i64 0, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !5
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %40)
  br label %42

42:                                               ; preds = %35
  %43 = load i32, ptr %3, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %3, align 4, !tbaa !9
  br label %30, !llvm.loop !13

45:                                               ; preds = %34
  ret i32 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

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

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 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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"

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@p = external dso_local local_unnamed_addr global [1000001 x double], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  store <2 x double> <double 0.000000e+00, double 1.000000e+00>, ptr getelementptr inbounds (i8, ptr @p, i64 8), align 8, !tbaa !5
  br label %5

1:                                                ; preds = %5
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %3 = load i32, ptr @t, align 4, !tbaa !9
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

5:                                                ; preds = %5, %0
  %6 = phi double [ 1.000000e+00, %0 ], [ %19, %5 ]
  %indvars.iv = phi i64 [ 3, %0 ], [ %indvars.iv.next.1, %5 ]
  %7 = add nsw i64 %indvars.iv, -2
  %8 = getelementptr inbounds [1000001 x double], ptr @p, i64 0, i64 %7
  %9 = load double, ptr %8, align 8, !tbaa !5
  %10 = fadd double %6, %9
  %11 = fmul double %10, 5.000000e-01
  %12 = fadd double %11, 1.000000e+00
  %13 = getelementptr inbounds [1000001 x double], ptr @p, i64 0, i64 %indvars.iv
  store double %12, ptr %13, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %14 = add nsw i64 %indvars.iv, -1
  %15 = getelementptr inbounds [1000001 x double], ptr @p, i64 0, i64 %14
  %16 = load double, ptr %15, align 8, !tbaa !5
  %17 = fadd double %12, %16
  %18 = fmul double %17, 5.000000e-01
  %19 = fadd double %18, 1.000000e+00
  %20 = getelementptr inbounds [1000001 x double], ptr @p, i64 0, i64 %indvars.iv.next
  store double %19, ptr %20, align 8, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 1000001
  br i1 %exitcond.not.1, label %1, label %5, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %1
  ret i32 0

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.09 = phi i32 [ %27, %.lr.ph ], [ 0, %1 ]
  %21 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %22 = load i32, ptr @n, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [1000001 x double], ptr @p, i64 0, i64 %23
  %25 = load double, ptr %24, align 8, !tbaa !5
  %26 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %25)
  %27 = add nuw nsw i32 %.09, 1
  %28 = load i32, ptr @t, align 4, !tbaa !9
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %.lr.ph, label %._crit_edge, !llvm.loop !13
}

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

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

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 = { 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" }

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Effective O3 passes: BDCEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass