; LLVM IR from tangjz/acm-icpc :: self_training/2015-02-01/G.ll (Z5checkv)

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

@q = external dso_local global i32, align 4
@now = external dso_local global i32, align 4
@c = external dso_local global double, align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z4dijkd(double 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 uwtable
define dso_local noundef zeroext i1 @_Z5checkv() #0 {
  %1 = alloca double, align 8
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  store double 0.000000e+00, ptr %1, align 8, !tbaa !5
  store i32 0, ptr @now, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %37, %0
  %7 = load i32, ptr @now, align 4, !tbaa !9
  %8 = load i32, ptr @q, align 4, !tbaa !9
  %9 = icmp slt i32 %7, %8
  br i1 %9, label %10, label %40

10:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #2
  store double 0.000000e+00, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store double 1.000000e+09, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %27, %10
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = icmp slt i32 %12, 100
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %30

15:                                               ; preds = %11
  %16 = load double, ptr %2, align 8, !tbaa !5
  %17 = load double, ptr %3, align 8, !tbaa !5
  %18 = fadd double %16, %17
  %19 = fdiv double %18, 2.000000e+00
  store double %19, ptr %4, align 8, !tbaa !5
  %20 = load double, ptr %4, align 8, !tbaa !5
  %21 = call noundef zeroext i1 @_Z4dijkd(double noundef %20)
  br i1 %21, label %22, label %24

22:                                               ; preds = %15
  %23 = load double, ptr %4, align 8, !tbaa !5
  store double %23, ptr %3, align 8, !tbaa !5
  br label %26

24:                                               ; preds = %15
  %25 = load double, ptr %4, align 8, !tbaa !5
  store double %25, ptr %2, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %24, %22
  br label %27

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

30:                                               ; preds = %14
  %31 = load double, ptr %2, align 8, !tbaa !5
  %32 = load double, ptr %3, align 8, !tbaa !5
  %33 = fadd double %31, %32
  %34 = fdiv double %33, 2.000000e+00
  %35 = load double, ptr %1, align 8, !tbaa !5
  %36 = fadd double %35, %34
  store double %36, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  br label %37

37:                                               ; preds = %30
  %38 = load i32, ptr @now, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr @now, align 4, !tbaa !9
  br label %6, !llvm.loop !13

40:                                               ; preds = %6
  %41 = load double, ptr %1, align 8, !tbaa !5
  %42 = load double, ptr @c, align 8, !tbaa !5
  %43 = fadd double %42, 0x3EB0C6F7A0B5ED8D
  %44 = fcmp ole double %41, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  ret i1 %44
}

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

@q = external dso_local local_unnamed_addr global i32, align 4
@now = external dso_local local_unnamed_addr global i32, align 4
@c = external dso_local local_unnamed_addr global double, align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z4dijkd(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z5checkv() local_unnamed_addr #0 {
  store i32 0, ptr @now, align 4, !tbaa !5
  %1 = load i32, ptr @q, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.preheader, label %._crit_edge

.preheader:                                       ; preds = %0, %3
  %.01017 = phi double [ %6, %3 ], [ 0.000000e+00, %0 ]
  br label %11

3:                                                ; preds = %11
  %4 = fadd double %.012., %..011
  %5 = fmul double %4, 5.000000e-01
  %6 = fadd double %.01017, %5
  %7 = load i32, ptr @now, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr @now, align 4, !tbaa !5
  %9 = load i32, ptr @q, align 4, !tbaa !5
  %10 = icmp slt i32 %8, %9
  br i1 %10, label %.preheader, label %._crit_edge, !llvm.loop !9

11:                                               ; preds = %.preheader, %11
  %.016 = phi i32 [ 0, %.preheader ], [ %15, %11 ]
  %.01115 = phi double [ 1.000000e+09, %.preheader ], [ %..011, %11 ]
  %.01214 = phi double [ 0.000000e+00, %.preheader ], [ %.012., %11 ]
  %12 = fadd double %.01214, %.01115
  %13 = fmul double %12, 5.000000e-01
  %14 = tail call noundef zeroext i1 @_Z4dijkd(double noundef %13)
  %.012. = select i1 %14, double %.01214, double %13
  %..011 = select i1 %14, double %13, double %.01115
  %15 = add nuw nsw i32 %.016, 1
  %exitcond.not = icmp eq i32 %15, 100
  br i1 %exitcond.not, label %3, label %11, !llvm.loop !11

._crit_edge:                                      ; preds = %3, %0
  %.010.lcssa = phi double [ 0.000000e+00, %0 ], [ %6, %3 ]
  %16 = load double, ptr @c, align 8, !tbaa !12
  %17 = fadd double %16, 0x3EB0C6F7A0B5ED8D
  %18 = fcmp ole double %.010.lcssa, %17
  ret i1 %18
}

attributes #0 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !7, i64 0}


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