; LLVM IR from tangjz/acm-icpc :: TDL_training/2015-11-01/E - charge-station - lzy.ll (Z3chkv)

; 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
@d = external dso_local global i32, align 4
@s = external dso_local global [139 x [139 x i32]], align 16
@f = external dso_local global [139 x i32], align 16
@g = external dso_local global [139 x i8], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z4findi(i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4joinii(i32 noundef, i32 noundef) #1

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

7:                                                ; preds = %17, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = icmp sle i32 %8, %9
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %7
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [139 x i32], ptr @f, i64 0, i64 %15
  store i32 %13, ptr %16, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %12
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !9

20:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %90, %20
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = icmp sle i32 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %93

26:                                               ; preds = %21
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [139 x i8], ptr @g, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !11, !range !13, !noundef !14
  %31 = trunc i8 %30 to i1
  br i1 %31, label %32, label %89

32:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %85, %32
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = load i32, ptr @n, align 4, !tbaa !5
  %36 = icmp sle i32 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %88

38:                                               ; preds = %33
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = call noundef i32 @_Z4findi(i32 noundef %39)
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = call noundef i32 @_Z4findi(i32 noundef %41)
  %43 = icmp ne i32 %40, %42
  br i1 %43, label %44, label %84

44:                                               ; preds = %38
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [139 x i8], ptr @g, i64 0, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !11, !range !13, !noundef !14
  %49 = trunc i8 %48 to i1
  br i1 %49, label %50, label %66

50:                                               ; preds = %44
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [139 x [139 x i32]], ptr @s, i64 0, i64 %52
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [139 x i32], ptr %53, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = load i32, ptr @d, align 4, !tbaa !5
  %59 = icmp sle i32 %57, %58
  br i1 %59, label %60, label %65

60:                                               ; preds = %50
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = call noundef i32 @_Z4findi(i32 noundef %61)
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = call noundef i32 @_Z4findi(i32 noundef %63)
  call void @_Z4joinii(i32 noundef %62, i32 noundef %64)
  br label %65

65:                                               ; preds = %60, %50
  br label %83

66:                                               ; preds = %44
  %67 = load i32, ptr %3, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [139 x [139 x i32]], ptr @s, i64 0, i64 %68
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [139 x i32], ptr %69, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = mul nsw i32 2, %73
  %75 = load i32, ptr @d, align 4, !tbaa !5
  %76 = icmp sle i32 %74, %75
  br i1 %76, label %77, label %82

77:                                               ; preds = %66
  %78 = load i32, ptr %3, align 4, !tbaa !5
  %79 = call noundef i32 @_Z4findi(i32 noundef %78)
  %80 = load i32, ptr %5, align 4, !tbaa !5
  %81 = call noundef i32 @_Z4findi(i32 noundef %80)
  call void @_Z4joinii(i32 noundef %79, i32 noundef %81)
  br label %82

82:                                               ; preds = %77, %66
  br label %83

83:                                               ; preds = %82, %65
  br label %84

84:                                               ; preds = %83, %38
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %5, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %5, align 4, !tbaa !5
  br label %33, !llvm.loop !15

88:                                               ; preds = %37
  br label %89

89:                                               ; preds = %88, %26
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %3, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %3, align 4, !tbaa !5
  br label %21, !llvm.loop !16

93:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %94

94:                                               ; preds = %106, %93
  %95 = load i32, ptr %6, align 4, !tbaa !5
  %96 = load i32, ptr @n, align 4, !tbaa !5
  %97 = icmp sle i32 %95, %96
  br i1 %97, label %99, label %98

98:                                               ; preds = %94
  store i32 11, ptr %4, align 4
  br label %109

99:                                               ; preds = %94
  %100 = load i32, ptr %6, align 4, !tbaa !5
  %101 = call noundef i32 @_Z4findi(i32 noundef %100)
  %102 = call noundef i32 @_Z4findi(i32 noundef 1)
  %103 = icmp ne i32 %101, %102
  br i1 %103, label %104, label %105

104:                                              ; preds = %99
  store i1 false, ptr %1, align 1
  store i32 1, ptr %4, align 4
  br label %109

105:                                              ; preds = %99
  br label %106

106:                                              ; preds = %105
  %107 = load i32, ptr %6, align 4, !tbaa !5
  %108 = add nsw i32 %107, 1
  store i32 %108, ptr %6, align 4, !tbaa !5
  br label %94, !llvm.loop !17

109:                                              ; preds = %104, %98
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %110 = load i32, ptr %4, align 4
  switch i32 %110, label %114 [
    i32 11, label %111
    i32 1, label %112
  ]

111:                                              ; preds = %109
  store i1 true, ptr %1, align 1
  br label %112

112:                                              ; preds = %111, %109
  %113 = load i1, ptr %1, align 1
  ret i1 %113

114:                                              ; preds = %109
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}
!17 = distinct !{!17, !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"

@n = external dso_local local_unnamed_addr global i32, align 4
@d = external dso_local local_unnamed_addr global i32, align 4
@s = external dso_local local_unnamed_addr global [139 x [139 x i32]], align 16
@f = external dso_local local_unnamed_addr global [139 x i32], align 16
@g = external dso_local local_unnamed_addr global [139 x i8], align 16

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4joinii(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3chkv() local_unnamed_addr #0 {
  %1 = load i32, ptr @n, align 4
  %.not38 = icmp slt i32 %1, 1
  br i1 %.not38, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %0
  %2 = add nuw i32 %1, 1
  %wide.trip.count = zext i32 %2 to i64
  %3 = zext nneg i32 %1 to i64
  %min.iters.check = icmp ult i32 %1, 8
  br i1 %min.iters.check, label %.lr.ph.preheader70, label %vector.ph

.lr.ph.preheader70:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 1, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %3, 2147483640
  %ind.end = or disjoint i64 %n.vec, 1
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <4 x i32> [ <i32 1, i32 2, i32 3, i32 4>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %step.add = add <4 x i32> %vec.ind, <i32 4, i32 4, i32 4, i32 4>
  %offset.idx = or disjoint i64 %index, 1
  %4 = getelementptr inbounds [139 x i32], ptr @f, i64 0, i64 %offset.idx
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  store <4 x i32> %vec.ind, ptr %4, align 4, !tbaa !5
  store <4 x i32> %step.add, ptr %5, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %vec.ind.next = add <4 x i32> %vec.ind, <i32 8, i32 8, i32 8, i32 8>
  %6 = icmp eq i64 %index.next, %n.vec
  br i1 %6, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %3
  br i1 %cmp.n, label %.preheader37, label %.lr.ph.preheader70

.preheader37:                                     ; preds = %.lr.ph, %middle.block
  br i1 %.not38, label %._crit_edge, label %.lr.ph46

.lr.ph:                                           ; preds = %.lr.ph.preheader70, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader70 ]
  %7 = getelementptr inbounds [139 x i32], ptr @f, i64 0, i64 %indvars.iv
  %8 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %8, ptr %7, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader37, label %.lr.ph, !llvm.loop !13

.preheader:                                       ; preds = %.loopexit
  %9 = icmp slt i32 %34, 1
  br i1 %9, label %._crit_edge, label %.lr.ph50

.lr.ph46:                                         ; preds = %.preheader37, %.loopexit
  %10 = phi i32 [ %34, %.loopexit ], [ %1, %.preheader37 ]
  %indvars.iv58 = phi i64 [ %indvars.iv.next59, %.loopexit ], [ 1, %.preheader37 ]
  %11 = getelementptr inbounds [139 x i8], ptr @g, i64 0, i64 %indvars.iv58
  %12 = load i8, ptr %11, align 1, !tbaa !14, !range !16, !noundef !17
  %13 = trunc nuw i8 %12 to i1
  %.not3240 = icmp sgt i32 %10, 0
  %or.cond.not = select i1 %13, i1 %.not3240, i1 false
  br i1 %or.cond.not, label %.lr.ph42.preheader, label %.lr.ph46..loopexit_crit_edge

.lr.ph46..loopexit_crit_edge:                     ; preds = %.lr.ph46
  %.pre = sext i32 %10 to i64
  br label %.loopexit

.lr.ph42.preheader:                               ; preds = %.lr.ph46
  %14 = trunc nuw nsw i64 %indvars.iv58 to i32
  br label %.lr.ph42

.lr.ph42:                                         ; preds = %.lr.ph42.preheader, %31
  %indvars.iv55 = phi i64 [ 1, %.lr.ph42.preheader ], [ %indvars.iv.next56, %31 ]
  %15 = tail call noundef i32 @_Z4findi(i32 noundef %14)
  %16 = trunc nuw nsw i64 %indvars.iv55 to i32
  %17 = tail call noundef i32 @_Z4findi(i32 noundef %16)
  %.not33 = icmp eq i32 %15, %17
  br i1 %.not33, label %31, label %18

18:                                               ; preds = %.lr.ph42
  %19 = getelementptr inbounds [139 x i8], ptr @g, i64 0, i64 %indvars.iv55
  %20 = load i8, ptr %19, align 1, !tbaa !14, !range !16, !noundef !17
  %21 = trunc nuw i8 %20 to i1
  %22 = getelementptr inbounds [139 x [139 x i32]], ptr @s, i64 0, i64 %indvars.iv58, i64 %indvars.iv55
  %23 = load i32, ptr %22, align 4, !tbaa !5
  br i1 %21, label %24, label %26

24:                                               ; preds = %18
  %25 = load i32, ptr @d, align 4, !tbaa !5
  %.not35 = icmp sgt i32 %23, %25
  br i1 %.not35, label %31, label %.sink.split

26:                                               ; preds = %18
  %27 = shl nsw i32 %23, 1
  %28 = load i32, ptr @d, align 4, !tbaa !5
  %.not34 = icmp sgt i32 %27, %28
  br i1 %.not34, label %31, label %.sink.split

.sink.split:                                      ; preds = %26, %24
  %29 = tail call noundef i32 @_Z4findi(i32 noundef %14)
  %30 = tail call noundef i32 @_Z4findi(i32 noundef %16)
  tail call void @_Z4joinii(i32 noundef %29, i32 noundef %30)
  br label %31

31:                                               ; preds = %.sink.split, %.lr.ph42, %26, %24
  %indvars.iv.next56 = add nuw nsw i64 %indvars.iv55, 1
  %32 = load i32, ptr @n, align 4
  %33 = sext i32 %32 to i64
  %.not32.not = icmp slt i64 %indvars.iv55, %33
  br i1 %.not32.not, label %.lr.ph42, label %.loopexit, !llvm.loop !18

.loopexit:                                        ; preds = %31, %.lr.ph46..loopexit_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.lr.ph46..loopexit_crit_edge ], [ %33, %31 ]
  %34 = phi i32 [ %10, %.lr.ph46..loopexit_crit_edge ], [ %32, %31 ]
  %indvars.iv.next59 = add nuw nsw i64 %indvars.iv58, 1
  %.not29.not = icmp slt i64 %indvars.iv58, %.pre-phi
  br i1 %.not29.not, label %.lr.ph46, label %.preheader, !llvm.loop !19

35:                                               ; preds = %.lr.ph50
  %36 = add nuw nsw i32 %.048, 1
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %.not30.not = icmp slt i32 %.048, %37
  br i1 %.not30.not, label %.lr.ph50, label %._crit_edge, !llvm.loop !20

.lr.ph50:                                         ; preds = %.preheader, %35
  %.048 = phi i32 [ %36, %35 ], [ 1, %.preheader ]
  %38 = tail call noundef i32 @_Z4findi(i32 noundef %.048)
  %39 = tail call noundef i32 @_Z4findi(i32 noundef 1)
  %.not31 = icmp eq i32 %38, %39
  br i1 %.not31, label %35, label %._crit_edge

._crit_edge:                                      ; preds = %35, %.lr.ph50, %0, %.preheader37, %.preheader
  %.not30.lcssa = phi i1 [ true, %.preheader ], [ true, %.preheader37 ], [ true, %0 ], [ %.not31, %.lr.ph50 ], [ %.not31, %35 ]
  ret i1 %.not30.lcssa
}

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

!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, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}
!14 = !{!15, !15, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !10}
!19 = distinct !{!19, !10}
!20 = distinct !{!20, !10}


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