; LLVM IR from tangjz/acm-icpc :: hdu/6070.ll (Z5checkd)

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

@n = external dso_local global i32, align 4
@a = external dso_local global [60001 x i32], align 16
@pos = external dso_local global [60001 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z8seg_initii(i32 noundef, i32 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
declare dso_local void @_Z7seg_updiiiid(i32 noundef, i32 noundef, i32 noundef, i32 noundef, double noundef) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3sgnd(double noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z7seg_queiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z5checkd(double noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  store double %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %8 = load double, ptr %3, align 8, !tbaa !5
  %9 = fdiv double 1.000000e+00, %8
  store double %9, ptr %4, align 8, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !9
  %11 = sext i32 %10 to i64
  %12 = mul i64 %11, 4
  call void @llvm.memset.p0.i64(ptr align 4 getelementptr inbounds (i32, ptr @pos, i64 1), i8 0, i64 %12, i1 false)
  %13 = load i32, ptr @n, align 4, !tbaa !9
  call void @_Z8seg_initii(i32 noundef 1, i32 noundef %13)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %62, %1
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = load i32, ptr @n, align 4, !tbaa !9
  %17 = icmp sle i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  store i32 2, ptr %6, align 4
  br label %65

19:                                               ; preds = %14
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [60001 x i32], ptr @a, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [60001 x i32], ptr @pos, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %39

28:                                               ; preds = %19
  %29 = load i32, ptr @n, align 4, !tbaa !9
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [60001 x i32], ptr @a, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [60001 x i32], ptr @pos, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = load double, ptr %4, align 8, !tbaa !5
  %38 = fneg double %37
  call void @_Z7seg_updiiiid(i32 noundef 1, i32 noundef %29, i32 noundef 1, i32 noundef %36, double noundef %38)
  br label %39

39:                                               ; preds = %28, %19
  %40 = load i32, ptr @n, align 4, !tbaa !9
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = load double, ptr %4, align 8, !tbaa !5
  %43 = fsub double %42, 1.000000e+00
  call void @_Z7seg_updiiiid(i32 noundef 1, i32 noundef %40, i32 noundef 1, i32 noundef %41, double noundef %43)
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [60001 x i32], ptr @a, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [60001 x i32], ptr @pos, i64 0, i64 %49
  store i32 %44, ptr %50, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %51 = load i32, ptr @n, align 4, !tbaa !9
  %52 = load i32, ptr %5, align 4, !tbaa !9
  %53 = call noundef double @_Z7seg_queiiii(i32 noundef 1, i32 noundef %51, i32 noundef 1, i32 noundef %52)
  store double %53, ptr %7, align 8, !tbaa !5
  %54 = load double, ptr %7, align 8, !tbaa !5
  %55 = call noundef i32 @_Z3sgnd(double noundef %54)
  %56 = icmp sle i32 %55, 0
  br i1 %56, label %57, label %58

57:                                               ; preds = %39
  store i1 true, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %59

58:                                               ; preds = %39
  store i32 0, ptr %6, align 4
  br label %59

59:                                               ; preds = %58, %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %60 = load i32, ptr %6, align 4
  switch i32 %60, label %65 [
    i32 0, label %61
  ]

61:                                               ; preds = %59
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %5, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %5, align 4, !tbaa !9
  br label %14, !llvm.loop !11

65:                                               ; preds = %59, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %66 = load i32, ptr %6, align 4
  switch i32 %66, label %68 [
    i32 2, label %67
  ]

67:                                               ; preds = %65
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %68

68:                                               ; preds = %67, %65
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %69 = load i1, ptr %2, align 1
  ret i1 %69
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { inlinehint 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"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"}


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

@n = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [60001 x i32], align 16
@pos = external dso_local local_unnamed_addr global [60001 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z8seg_initii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7seg_updiiiid(i32 noundef, i32 noundef, i32 noundef, i32 noundef, double noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3sgnd(double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z7seg_queiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z5checkd(double noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = sext i32 %2 to i64
  %4 = shl nsw i64 %3, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 getelementptr inbounds (i8, ptr @pos, i64 4), i8 0, i64 %4, i1 false)
  tail call void @_Z8seg_initii(i32 noundef 1, i32 noundef %2)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %.not21 = icmp sgt i32 %5, 0
  br i1 %.not21, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %1
  %6 = fdiv double 1.000000e+00, %0
  %7 = fneg double %6
  %8 = fadd double %6, -1.000000e+00
  br label %12

9:                                                ; preds = %20
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %.not = icmp slt i64 %indvars.iv, %11
  br i1 %.not, label %12, label %.critedge, !llvm.loop !9

12:                                               ; preds = %.lr.ph, %9
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %9 ]
  %13 = phi i32 [ %5, %.lr.ph ], [ %10, %9 ]
  %14 = getelementptr inbounds [60001 x i32], ptr @a, i64 0, i64 %indvars.iv
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [60001 x i32], ptr @pos, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %.not20 = icmp eq i32 %18, 0
  br i1 %.not20, label %20, label %19

19:                                               ; preds = %12
  tail call void @_Z7seg_updiiiid(i32 noundef 1, i32 noundef %13, i32 noundef 1, i32 noundef %18, double noundef %7)
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %19, %12
  %21 = phi i32 [ %.pre, %19 ], [ %13, %12 ]
  %22 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void @_Z7seg_updiiiid(i32 noundef 1, i32 noundef %21, i32 noundef 1, i32 noundef %22, double noundef %8)
  %23 = load i32, ptr %14, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [60001 x i32], ptr @pos, i64 0, i64 %24
  store i32 %22, ptr %25, align 4, !tbaa !5
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = tail call noundef double @_Z7seg_queiiii(i32 noundef 1, i32 noundef %26, i32 noundef 1, i32 noundef %22)
  %28 = tail call noundef i32 @_Z3sgnd(double noundef %27)
  %29 = icmp slt i32 %28, 1
  br i1 %29, label %.critedge, label %9

.critedge:                                        ; preds = %20, %9, %1
  %.not.lcssa = phi i1 [ false, %1 ], [ %29, %9 ], [ %29, %20 ]
  ret i1 %.not.lcssa
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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 = { inlinehint 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 nocallback nofree nounwind willreturn memory(argmem: write) }

!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"}


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