; LLVM IR from kazunetakahashi/atcoder :: 201510_201609/1014_KUPC_2013/B.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"

%struct.human = type { i32, i32, i32 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@X = external dso_local global [10 x %struct.human], align 16
@ori = external dso_local global [6 x i32], align 16
@ans = external dso_local global [6 x i32], align 16
@maximum = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5checkv() #0 {
  %1 = alloca i32, align 4
  %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
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %8

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

12:                                               ; preds = %8
  store i32 2, ptr %2, align 4
  br label %54

13:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [10 x %struct.human], ptr @X, i64 0, i64 %15
  %17 = getelementptr inbounds %struct.human, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %18, ptr %4, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %35, %13
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [10 x %struct.human], ptr @X, i64 0, i64 %22
  %24 = getelementptr inbounds %struct.human, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = icmp sle i32 %20, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %19
  store i32 5, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %38

28:                                               ; preds = %19
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [6 x i32], ptr @ori, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = add nsw i32 %33, %32
  store i32 %34, ptr %3, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %28
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %4, align 4, !tbaa !5
  br label %19, !llvm.loop !12

38:                                               ; preds = %27
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = load i32, ptr %1, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [10 x %struct.human], ptr @X, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.human, ptr %42, i32 0, i32 2
  %44 = load i32, ptr %43, align 4, !tbaa !14
  %45 = icmp ne i32 %39, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %38
  store i32 1, ptr %2, align 4
  br label %48

47:                                               ; preds = %38
  store i32 0, ptr %2, align 4
  br label %48

48:                                               ; preds = %47, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  %49 = load i32, ptr %2, align 4
  switch i32 %49, label %54 [
    i32 0, label %50
  ]

50:                                               ; preds = %48
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %1, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %1, align 4, !tbaa !5
  br label %8, !llvm.loop !15

54:                                               ; preds = %48, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  %55 = load i32, ptr %2, align 4
  switch i32 %55, label %97 [
    i32 2, label %56
    i32 1, label %96
  ]

56:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %57

57:                                               ; preds = %69, %56
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = load i32, ptr @n, align 4, !tbaa !5
  %60 = icmp slt i32 %58, %59
  br i1 %60, label %62, label %61

61:                                               ; preds = %57
  store i32 8, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %72

62:                                               ; preds = %57
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [6 x i32], ptr @ori, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = add nsw i32 %67, %66
  store i32 %68, ptr %5, align 4, !tbaa !5
  br label %69

69:                                               ; preds = %62
  %70 = load i32, ptr %6, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %6, align 4, !tbaa !5
  br label %57, !llvm.loop !16

72:                                               ; preds = %61
  %73 = load i32, ptr @maximum, align 4, !tbaa !5
  %74 = load i32, ptr %5, align 4, !tbaa !5
  %75 = icmp slt i32 %73, %74
  br i1 %75, label %76, label %95

76:                                               ; preds = %72
  %77 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %77, ptr @maximum, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %78

78:                                               ; preds = %91, %76
  %79 = load i32, ptr %7, align 4, !tbaa !5
  %80 = load i32, ptr @n, align 4, !tbaa !5
  %81 = icmp slt i32 %79, %80
  br i1 %81, label %83, label %82

82:                                               ; preds = %78
  store i32 11, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %94

83:                                               ; preds = %78
  %84 = load i32, ptr %7, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [6 x i32], ptr @ori, i64 0, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !5
  %88 = load i32, ptr %7, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [6 x i32], ptr @ans, i64 0, i64 %89
  store i32 %87, ptr %90, align 4, !tbaa !5
  br label %91

91:                                               ; preds = %83
  %92 = load i32, ptr %7, align 4, !tbaa !5
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %7, align 4, !tbaa !5
  br label %78, !llvm.loop !17

94:                                               ; preds = %82
  br label %95

95:                                               ; preds = %94, %72
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %96

96:                                               ; preds = %95, %54
  ret void

97:                                               ; 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 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 #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, !6, i64 0}
!10 = !{!"_ZTS5human", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!10, !6, i64 4}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!10, !6, i64 8}
!15 = distinct !{!15, !13}
!16 = distinct !{!16, !13}
!17 = distinct !{!17, !13}


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

%struct.human = type { i32, i32, i32 }

@n = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@X = external dso_local local_unnamed_addr global [10 x %struct.human], align 16
@ori = external dso_local local_unnamed_addr global [6 x i32], align 16
@ans = external dso_local local_unnamed_addr global [6 x i32], align 16
@maximum = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z5checkv() local_unnamed_addr #0 {
  %1 = load i32, ptr @m, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph38.preheader, label %.preheader

.lr.ph38.preheader:                               ; preds = %0
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.lr.ph38

3:                                                ; preds = %._crit_edge
  %indvars.iv.next52 = add nuw nsw i64 %indvars.iv51, 1
  %exitcond54.not = icmp eq i64 %indvars.iv.next52, %wide.trip.count
  br i1 %exitcond54.not, label %.preheader, label %.lr.ph38, !llvm.loop !9

.preheader:                                       ; preds = %3, %0
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph41.preheader, label %._crit_edge42.thread

.lr.ph41.preheader:                               ; preds = %.preheader
  %wide.trip.count58 = zext nneg i32 %4 to i64
  %min.iters.check73 = icmp ult i32 %4, 8
  br i1 %min.iters.check73, label %.lr.ph41.preheader88, label %vector.ph74

.lr.ph41.preheader88:                             ; preds = %middle.block71, %.lr.ph41.preheader
  %indvars.iv55.ph = phi i64 [ 0, %.lr.ph41.preheader ], [ %n.vec76, %middle.block71 ]
  %.02339.ph = phi i32 [ 0, %.lr.ph41.preheader ], [ %11, %middle.block71 ]
  br label %.lr.ph41

vector.ph74:                                      ; preds = %.lr.ph41.preheader
  %n.vec76 = and i64 %wide.trip.count58, 2147483640
  br label %vector.body78

vector.body78:                                    ; preds = %vector.body78, %vector.ph74
  %index79 = phi i64 [ 0, %vector.ph74 ], [ %index.next84, %vector.body78 ]
  %vec.phi80 = phi <4 x i32> [ zeroinitializer, %vector.ph74 ], [ %8, %vector.body78 ]
  %vec.phi81 = phi <4 x i32> [ zeroinitializer, %vector.ph74 ], [ %9, %vector.body78 ]
  %6 = getelementptr inbounds [6 x i32], ptr @ori, i64 0, i64 %index79
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  %wide.load82 = load <4 x i32>, ptr %6, align 16, !tbaa !5
  %wide.load83 = load <4 x i32>, ptr %7, align 16, !tbaa !5
  %8 = add <4 x i32> %wide.load82, %vec.phi80
  %9 = add <4 x i32> %wide.load83, %vec.phi81
  %index.next84 = add nuw i64 %index79, 8
  %10 = icmp eq i64 %index.next84, %n.vec76
  br i1 %10, label %middle.block71, label %vector.body78, !llvm.loop !11

middle.block71:                                   ; preds = %vector.body78
  %bin.rdx85 = add <4 x i32> %9, %8
  %11 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx85)
  %cmp.n86 = icmp eq i64 %n.vec76, %wide.trip.count58
  br i1 %cmp.n86, label %._crit_edge42, label %.lr.ph41.preheader88

.lr.ph38:                                         ; preds = %.lr.ph38.preheader, %3
  %indvars.iv51 = phi i64 [ 0, %.lr.ph38.preheader ], [ %indvars.iv.next52, %3 ]
  %12 = getelementptr inbounds [10 x %struct.human], ptr @X, i64 0, i64 %indvars.iv51
  %13 = load i32, ptr %12, align 4, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %12, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !16
  %.not33 = icmp sgt i32 %13, %15
  br i1 %.not33, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.lr.ph38
  %16 = sext i32 %13 to i64
  %17 = add i32 %15, 1
  %18 = sub i32 %15, %13
  %19 = zext i32 %18 to i64
  %20 = add nuw nsw i64 %19, 1
  %min.iters.check = icmp ult i32 %18, 7
  br i1 %min.iters.check, label %.lr.ph.preheader92, label %vector.ph

.lr.ph.preheader92:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ %16, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.02534.ph = phi i32 [ 0, %.lr.ph.preheader ], [ %26, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %20, 8589934584
  %ind.end = add nsw i64 %n.vec, %16
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %23, %vector.body ]
  %vec.phi69 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %24, %vector.body ]
  %offset.idx = add i64 %index, %16
  %21 = getelementptr inbounds [6 x i32], ptr @ori, i64 0, i64 %offset.idx
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  %wide.load = load <4 x i32>, ptr %21, align 4, !tbaa !5
  %wide.load70 = load <4 x i32>, ptr %22, align 4, !tbaa !5
  %23 = add <4 x i32> %wide.load, %vec.phi
  %24 = add <4 x i32> %wide.load70, %vec.phi69
  %index.next = add nuw i64 %index, 8
  %25 = icmp eq i64 %index.next, %n.vec
  br i1 %25, label %middle.block, label %vector.body, !llvm.loop !17

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %24, %23
  %26 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %20, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader92

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %.lr.ph38
  %.025.lcssa = phi i32 [ 0, %.lr.ph38 ], [ %26, %middle.block ], [ %31, %.lr.ph ]
  %27 = getelementptr inbounds i8, ptr %12, i64 8
  %28 = load i32, ptr %27, align 4, !tbaa !18
  %.not28 = icmp eq i32 %.025.lcssa, %28
  br i1 %.not28, label %3, label %.thread

.lr.ph:                                           ; preds = %.lr.ph.preheader92, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader92 ]
  %.02534 = phi i32 [ %31, %.lr.ph ], [ %.02534.ph, %.lr.ph.preheader92 ]
  %29 = getelementptr inbounds [6 x i32], ptr @ori, i64 0, i64 %indvars.iv
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = add nsw i32 %30, %.02534
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
  %exitcond.not = icmp eq i32 %17, %lftr.wideiv
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !19

._crit_edge42:                                    ; preds = %.lr.ph41, %middle.block71
  %.lcssa = phi i32 [ %11, %middle.block71 ], [ %38, %.lr.ph41 ]
  %32 = load i32, ptr @maximum, align 4, !tbaa !5
  %33 = icmp slt i32 %32, %.lcssa
  br i1 %33, label %39, label %.thread

._crit_edge42.thread:                             ; preds = %.preheader
  %34 = load i32, ptr @maximum, align 4, !tbaa !5
  %35 = icmp slt i32 %34, 0
  br i1 %35, label %.thread65, label %.thread

.thread65:                                        ; preds = %._crit_edge42.thread
  store i32 0, ptr @maximum, align 4, !tbaa !5
  br label %.thread

.lr.ph41:                                         ; preds = %.lr.ph41.preheader88, %.lr.ph41
  %indvars.iv55 = phi i64 [ %indvars.iv.next56, %.lr.ph41 ], [ %indvars.iv55.ph, %.lr.ph41.preheader88 ]
  %.02339 = phi i32 [ %38, %.lr.ph41 ], [ %.02339.ph, %.lr.ph41.preheader88 ]
  %36 = getelementptr inbounds [6 x i32], ptr @ori, i64 0, i64 %indvars.iv55
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = add nsw i32 %37, %.02339
  %indvars.iv.next56 = add nuw nsw i64 %indvars.iv55, 1
  %exitcond59.not = icmp eq i64 %indvars.iv.next56, %wide.trip.count58
  br i1 %exitcond59.not, label %._crit_edge42, label %.lr.ph41, !llvm.loop !20

39:                                               ; preds = %._crit_edge42
  store i32 %.lcssa, ptr @maximum, align 4, !tbaa !5
  br i1 %5, label %.lr.ph47.preheader, label %.thread

.lr.ph47.preheader:                               ; preds = %39
  %40 = zext nneg i32 %4 to i64
  %41 = shl nuw nsw i64 %40, 2
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 @ans, ptr nonnull align 16 @ori, i64 %41, i1 false), !tbaa !5
  br label %.thread

.thread:                                          ; preds = %._crit_edge, %.thread65, %._crit_edge42.thread, %.lr.ph47.preheader, %39, %._crit_edge42
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #2

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

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


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