; LLVM IR from tangjz/acm-icpc :: self_training/2015-03-03/P.ll (Z5checki)

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

@pre = external dso_local global [10001 x i32], align 16
@nxt = external dso_local global [20002 x i32], align 16
@to = external dso_local global [20002 x i32], align 16
@k = external dso_local global [10001 x double], align 16
@e = external dso_local global [10001 x double], align 16
@vis = external dso_local global [10001 x i8], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z5checki(i32 noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [10001 x i8], ptr @vis, i64 0, i64 %7
  store i8 1, ptr %8, align 1, !tbaa !9
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [10001 x double], ptr @e, i64 0, i64 %10
  %12 = load double, ptr %11, align 8, !tbaa !11
  %13 = fcmp une double %12, 0.000000e+00
  br i1 %13, label %14, label %15

14:                                               ; preds = %1
  store i1 true, ptr %2, align 1
  br label %57

15:                                               ; preds = %1
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [10001 x double], ptr @k, i64 0, i64 %17
  %19 = load double, ptr %18, align 8, !tbaa !11
  %20 = fcmp oeq double %19, 1.000000e+02
  br i1 %20, label %21, label %22

21:                                               ; preds = %15
  store i1 false, ptr %2, align 1
  br label %57

22:                                               ; preds = %15
  br label %23

23:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [10001 x i32], ptr @pre, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  store i32 %27, ptr %4, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %49, %23
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %32, label %31

31:                                               ; preds = %28
  store i32 2, ptr %5, align 4
  br label %54

32:                                               ; preds = %28
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [20002 x i32], ptr @to, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [10001 x i8], ptr @vis, i64 0, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !9, !range !13, !noundef !14
  %40 = trunc i8 %39 to i1
  br i1 %40, label %48, label %41

41:                                               ; preds = %32
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [20002 x i32], ptr @to, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = call noundef zeroext i1 @_Z5checki(i32 noundef %45)
  br i1 %46, label %47, label %48

47:                                               ; preds = %41
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %54

48:                                               ; preds = %41, %32
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [20002 x i32], ptr @nxt, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  store i32 %53, ptr %4, align 4, !tbaa !5
  br label %28, !llvm.loop !15

54:                                               ; preds = %47, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %55 = load i32, ptr %5, align 4
  switch i32 %55, label %59 [
    i32 2, label %56
    i32 1, label %57
  ]

56:                                               ; preds = %54
  store i1 false, ptr %2, align 1
  br label %57

57:                                               ; preds = %56, %54, %21, %14
  %58 = load i1, ptr %2, align 1
  ret i1 %58

59:                                               ; preds = %54
  unreachable
}

; 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

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@pre = external dso_local local_unnamed_addr global [10001 x i32], align 16
@nxt = external dso_local local_unnamed_addr global [20002 x i32], align 16
@to = external dso_local local_unnamed_addr global [20002 x i32], align 16
@k = external dso_local local_unnamed_addr global [10001 x double], align 16
@e = external dso_local local_unnamed_addr global [10001 x double], align 16
@vis = external dso_local local_unnamed_addr global [10001 x i8], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z5checki(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [10001 x i8], ptr @vis, i64 0, i64 %2
  store i8 1, ptr %3, align 1, !tbaa !5
  %4 = getelementptr inbounds [10001 x double], ptr @e, i64 0, i64 %2
  %5 = load double, ptr %4, align 8, !tbaa !9
  %6 = fcmp une double %5, 0.000000e+00
  br i1 %6, label %.loopexit, label %7

7:                                                ; preds = %1
  %8 = getelementptr inbounds [10001 x double], ptr @k, i64 0, i64 %2
  %9 = load double, ptr %8, align 8, !tbaa !9
  %10 = fcmp oeq double %9, 1.000000e+02
  br i1 %10, label %.loopexit, label %11

11:                                               ; preds = %7
  %12 = getelementptr inbounds [10001 x i32], ptr @pre, i64 0, i64 %2
  %.0911 = load i32, ptr %12, align 4, !tbaa !11
  %.not12.not = icmp eq i32 %.0911, 0
  br i1 %.not12.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %11, %22
  %.0913 = phi i32 [ %.09, %22 ], [ %.0911, %11 ]
  %13 = sext i32 %.0913 to i64
  %14 = getelementptr inbounds [20002 x i32], ptr @to, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [10001 x i8], ptr @vis, i64 0, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !5, !range !13, !noundef !14
  %19 = trunc nuw i8 %18 to i1
  br i1 %19, label %22, label %20

20:                                               ; preds = %.lr.ph
  %21 = tail call noundef zeroext i1 @_Z5checki(i32 noundef %15)
  br i1 %21, label %.loopexit, label %22

22:                                               ; preds = %.lr.ph, %20
  %23 = getelementptr inbounds [20002 x i32], ptr @nxt, i64 0, i64 %13
  %.09 = load i32, ptr %23, align 4, !tbaa !11
  %.not.not = icmp eq i32 %.09, 0
  br i1 %.not.not, label %.loopexit, label %.lr.ph, !llvm.loop !15

.loopexit:                                        ; preds = %20, %22, %11, %7, %1
  %.1 = phi i1 [ true, %1 ], [ false, %7 ], [ false, %11 ], [ true, %20 ], [ false, %22 ]
  ret i1 %.1
}

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass