; LLVM IR from VastoLorde95/Competitive-Programming :: Codejam/APAC 2017/Round A/Problem C/C.ll (Z5solvev)

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

@m = external dso_local global i32, align 4
@c = external dso_local global [110 x double], align 16
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1

declare i32 @printf(ptr noundef, ...) #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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef x86_fp80 @_Z1fe(x86_fp80 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() #3 {
  %1 = alloca i32, align 4
  %2 = alloca x86_fp80, align 16
  %3 = alloca x86_fp80, align 16
  %4 = alloca x86_fp80, align 16
  %5 = alloca i32, align 4
  %6 = alloca x86_fp80, align 16
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %18, %0
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = load i32, ptr @m, align 4, !tbaa !5
  %11 = icmp sle i32 %9, %10
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %8
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [110 x double], ptr @c, i64 0, i64 %15
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %16)
  br label %18

18:                                               ; preds = %13
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %1, align 4, !tbaa !5
  br label %8, !llvm.loop !9

21:                                               ; preds = %12
  %22 = load double, ptr @c, align 16, !tbaa !11
  %23 = fneg double %22
  store double %23, ptr @c, align 16, !tbaa !11
  %24 = load i32, ptr @m, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds double, ptr @c, i64 %25
  %27 = getelementptr inbounds double, ptr %26, i64 1
  call void @_ZSt7reverseIPdEvT_S1_(ptr noundef @c, ptr noundef %27)
  call void @llvm.lifetime.start.p0(i64 16, ptr %2) #5
  store x86_fp80 0xK3FE189705F4136B4A800, ptr %2, align 16, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #5
  store x86_fp80 0xK3FFFFFFFFFFDDA3E8000, ptr %3, align 16, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %46, %21
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = icmp slt i32 %29, 100
  br i1 %30, label %32, label %31

31:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %49

32:                                               ; preds = %28
  %33 = load x86_fp80, ptr %2, align 16, !tbaa !13
  %34 = load x86_fp80, ptr %3, align 16, !tbaa !13
  %35 = fadd x86_fp80 %33, %34
  %36 = fdiv x86_fp80 %35, 0xK40008000000000000000
  store x86_fp80 %36, ptr %4, align 16, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #5
  %37 = load x86_fp80, ptr %4, align 16, !tbaa !13
  %38 = call noundef x86_fp80 @_Z1fe(x86_fp80 noundef %37)
  store x86_fp80 %38, ptr %6, align 16, !tbaa !13
  %39 = load x86_fp80, ptr %6, align 16, !tbaa !13
  %40 = fcmp ogt x86_fp80 %39, 0xK00000000000000000000
  br i1 %40, label %41, label %43

41:                                               ; preds = %32
  %42 = load x86_fp80, ptr %4, align 16, !tbaa !13
  store x86_fp80 %42, ptr %2, align 16, !tbaa !13
  br label %45

43:                                               ; preds = %32
  %44 = load x86_fp80, ptr %4, align 16, !tbaa !13
  store x86_fp80 %44, ptr %3, align 16, !tbaa !13
  br label %45

45:                                               ; preds = %43, %41
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #5
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %5, align 4, !tbaa !5
  br label %28, !llvm.loop !15

49:                                               ; preds = %31
  %50 = load x86_fp80, ptr %4, align 16, !tbaa !13
  %51 = fptrunc x86_fp80 %50 to double
  %52 = fsub double %51, 1.000000e+00
  %53 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, double noundef %52)
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %2) #5
  ret void
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt7reverseIPdEvT_S1_(ptr noundef, ptr noundef) #4

attributes #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 = { 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 = { mustprogress 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 #4 = { inlinehint mustprogress 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 #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 = !{!"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 = !{!"double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long double", !7, i64 0}
!15 = distinct !{!15, !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"

@m = external dso_local global i32, align 4
@c = external dso_local global [110 x double], align 16
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef x86_fp80 @_Z1fe(x86_fp80 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() local_unnamed_addr #2 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @m)
  %2 = load i32, ptr @m, align 4, !tbaa !5
  %.not17 = icmp slt i32 %2, 0
  br i1 %.not17, label %.._crit_edge_crit_edge, label %.lr.ph

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre = sext i32 %2 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.._crit_edge_crit_edge ], [ %10, %.lr.ph ]
  %3 = load double, ptr @c, align 16, !tbaa !9
  %4 = fneg double %3
  store double %4, ptr @c, align 16, !tbaa !9
  %5 = getelementptr inbounds double, ptr @c, i64 %.pre-phi
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  tail call void @_ZSt7reverseIPdEvT_S1_(ptr noundef nonnull @c, ptr noundef nonnull %6)
  br label %15

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %7 = getelementptr inbounds [110 x double], ptr @c, i64 0, i64 %indvars.iv
  %8 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %7)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %9 = load i32, ptr @m, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %.not.not = icmp slt i64 %indvars.iv, %10
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !11

11:                                               ; preds = %15
  %12 = fptrunc x86_fp80 %17 to double
  %13 = fadd double %12, -1.000000e+00
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, double noundef %13)
  ret void

15:                                               ; preds = %._crit_edge, %15
  %.01221 = phi x86_fp80 [ 0xK3FE189705F4136B4A800, %._crit_edge ], [ %..012, %15 ]
  %.01320 = phi i32 [ 0, %._crit_edge ], [ %20, %15 ]
  %.01519 = phi x86_fp80 [ 0xK3FFFFFFFFFFDDA3E8000, %._crit_edge ], [ %.015., %15 ]
  %16 = fadd x86_fp80 %.01519, %.01221
  %17 = fmul x86_fp80 %16, 0xK3FFE8000000000000000
  %18 = tail call noundef x86_fp80 @_Z1fe(x86_fp80 noundef %17)
  %19 = fcmp ogt x86_fp80 %18, 0xK00000000000000000000
  %.015. = select i1 %19, x86_fp80 %.01519, x86_fp80 %17
  %..012 = select i1 %19, x86_fp80 %17, x86_fp80 %.01221
  %20 = add nuw nsw i32 %.01320, 1
  %exitcond.not = icmp eq i32 %20, 100
  br i1 %exitcond.not, label %11, label %15, !llvm.loop !13
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt7reverseIPdEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #3

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


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