; LLVM IR from tangjz/acm-icpc :: self_training/2015-01-29 (H)

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

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@s = external dso_local global [1000010 x i32], align 16
@vis = external dso_local global [1000010 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #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
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %30, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = mul nsw i32 %7, 2
  %9 = icmp slt i32 %8, 1000010
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %33

11:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = mul nsw i32 %12, 2
  store i32 %13, ptr %4, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %25, %11
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = icmp slt i32 %15, 1000010
  br i1 %16, label %18, label %17

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

18:                                               ; preds = %14
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [1000010 x i32], ptr @s, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = add nsw i32 %23, %19
  store i32 %24, ptr %22, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %18
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = add nsw i32 %27, %26
  store i32 %28, ptr %4, align 4, !tbaa !5
  br label %14, !llvm.loop !9

29:                                               ; preds = %17
  br label %30

30:                                               ; preds = %29
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !11

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

34:                                               ; preds = %52, %33
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = icmp slt i32 %35, 1000010
  br i1 %36, label %38, label %37

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

38:                                               ; preds = %34
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [1000010 x i32], ptr @s, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = icmp slt i32 %42, 1001
  br i1 %43, label %44, label %51

44:                                               ; preds = %38
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [1000010 x i32], ptr @s, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [1000010 x i8], ptr @vis, i64 0, i64 %49
  store i8 1, ptr %50, align 1, !tbaa !12
  br label %51

51:                                               ; preds = %44, %38
  br label %52

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

55:                                               ; preds = %37
  %56 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %57

57:                                               ; preds = %61, %55
  %58 = load i32, ptr @t, align 4, !tbaa !5
  %59 = add nsw i32 %58, -1
  store i32 %59, ptr @t, align 4, !tbaa !5
  %60 = icmp ne i32 %58, 0
  br i1 %60, label %61, label %71

61:                                               ; preds = %57
  %62 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %63 = load i32, ptr @n, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [1000010 x i8], ptr @vis, i64 0, i64 %64
  %66 = load i8, ptr %65, align 1, !tbaa !12, !range !15, !noundef !16
  %67 = trunc i8 %66 to i1
  %68 = zext i1 %67 to i64
  %69 = select i1 %67, ptr @.str.1, ptr @.str.2
  %70 = call i32 @puts(ptr noundef %69)
  br label %57, !llvm.loop !17

71:                                               ; preds = %57
  ret i32 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

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

declare i32 @puts(ptr noundef) #2

attributes #0 = { mustprogress norecurse 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 = { "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 = { 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 = distinct !{!11, !10}
!12 = !{!13, !13, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = distinct !{!14, !10}
!15 = !{i8 0, i8 2}
!16 = !{}
!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"

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@s = external dso_local local_unnamed_addr global [1000010 x i32], align 16
@vis = external dso_local local_unnamed_addr global [1000010 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  br label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %._crit_edge.1, %0
  %indvars.iv23 = phi i64 [ 1, %0 ], [ %indvars.iv.next24.1, %._crit_edge.1 ]
  %indvars.iv = phi i64 [ 2, %0 ], [ %indvars.iv.next.1, %._crit_edge.1 ]
  %indvars28 = trunc i64 %indvars.iv23 to i32
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
  %indvars28.1 = trunc i64 %indvars.iv.next24 to i32
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %.lr.ph.1, %._crit_edge
  %indvars.iv25.1 = phi i64 [ %indvars.iv.next, %._crit_edge ], [ %indvars.iv.next26.1, %.lr.ph.1 ]
  %1 = getelementptr inbounds [1000010 x i32], ptr @s, i64 0, i64 %indvars.iv25.1
  %2 = load i32, ptr %1, align 4, !tbaa !5
  %3 = add nsw i32 %2, %indvars28.1
  store i32 %3, ptr %1, align 4, !tbaa !5
  %indvars.iv.next26.1 = add nuw nsw i64 %indvars.iv25.1, %indvars.iv.next24
  %4 = icmp ult i64 %indvars.iv.next26.1, 1000010
  br i1 %4, label %.lr.ph.1, label %._crit_edge.1, !llvm.loop !9

._crit_edge.1:                                    ; preds = %.lr.ph.1
  %indvars.iv.next24.1 = add nuw nsw i64 %indvars.iv23, 2
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next24.1, 500005
  br i1 %exitcond.not.1, label %vector.body, label %.lr.ph.preheader, !llvm.loop !11

vector.body:                                      ; preds = %._crit_edge.1, %pred.store.continue47
  %index = phi i64 [ %index.next, %pred.store.continue47 ], [ 0, %._crit_edge.1 ]
  %offset.idx = or disjoint i64 %index, 1
  %5 = getelementptr inbounds [1000010 x i32], ptr @s, i64 0, i64 %offset.idx
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  %wide.load = load <4 x i32>, ptr %5, align 4, !tbaa !5
  %wide.load33 = load <4 x i32>, ptr %6, align 4, !tbaa !5
  %7 = icmp slt <4 x i32> %wide.load, <i32 1001, i32 1001, i32 1001, i32 1001>
  %8 = icmp slt <4 x i32> %wide.load33, <i32 1001, i32 1001, i32 1001, i32 1001>
  %9 = extractelement <4 x i1> %7, i64 0
  br i1 %9, label %pred.store.if, label %pred.store.continue

pred.store.if:                                    ; preds = %vector.body
  %10 = extractelement <4 x i32> %wide.load, i64 0
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [1000010 x i8], ptr @vis, i64 0, i64 %11
  store i8 1, ptr %12, align 1, !tbaa !12
  br label %pred.store.continue

pred.store.continue:                              ; preds = %pred.store.if, %vector.body
  %13 = extractelement <4 x i1> %7, i64 1
  br i1 %13, label %pred.store.if34, label %pred.store.continue35

pred.store.if34:                                  ; preds = %pred.store.continue
  %14 = extractelement <4 x i32> %wide.load, i64 1
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [1000010 x i8], ptr @vis, i64 0, i64 %15
  store i8 1, ptr %16, align 1, !tbaa !12
  br label %pred.store.continue35

pred.store.continue35:                            ; preds = %pred.store.if34, %pred.store.continue
  %17 = extractelement <4 x i1> %7, i64 2
  br i1 %17, label %pred.store.if36, label %pred.store.continue37

pred.store.if36:                                  ; preds = %pred.store.continue35
  %18 = extractelement <4 x i32> %wide.load, i64 2
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [1000010 x i8], ptr @vis, i64 0, i64 %19
  store i8 1, ptr %20, align 1, !tbaa !12
  br label %pred.store.continue37

pred.store.continue37:                            ; preds = %pred.store.if36, %pred.store.continue35
  %21 = extractelement <4 x i1> %7, i64 3
  br i1 %21, label %pred.store.if38, label %pred.store.continue39

pred.store.if38:                                  ; preds = %pred.store.continue37
  %22 = extractelement <4 x i32> %wide.load, i64 3
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [1000010 x i8], ptr @vis, i64 0, i64 %23
  store i8 1, ptr %24, align 1, !tbaa !12
  br label %pred.store.continue39

pred.store.continue39:                            ; preds = %pred.store.if38, %pred.store.continue37
  %25 = extractelement <4 x i1> %8, i64 0
  br i1 %25, label %pred.store.if40, label %pred.store.continue41

pred.store.if40:                                  ; preds = %pred.store.continue39
  %26 = extractelement <4 x i32> %wide.load33, i64 0
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [1000010 x i8], ptr @vis, i64 0, i64 %27
  store i8 1, ptr %28, align 1, !tbaa !12
  br label %pred.store.continue41

pred.store.continue41:                            ; preds = %pred.store.if40, %pred.store.continue39
  %29 = extractelement <4 x i1> %8, i64 1
  br i1 %29, label %pred.store.if42, label %pred.store.continue43

pred.store.if42:                                  ; preds = %pred.store.continue41
  %30 = extractelement <4 x i32> %wide.load33, i64 1
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [1000010 x i8], ptr @vis, i64 0, i64 %31
  store i8 1, ptr %32, align 1, !tbaa !12
  br label %pred.store.continue43

pred.store.continue43:                            ; preds = %pred.store.if42, %pred.store.continue41
  %33 = extractelement <4 x i1> %8, i64 2
  br i1 %33, label %pred.store.if44, label %pred.store.continue45

pred.store.if44:                                  ; preds = %pred.store.continue43
  %34 = extractelement <4 x i32> %wide.load33, i64 2
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [1000010 x i8], ptr @vis, i64 0, i64 %35
  store i8 1, ptr %36, align 1, !tbaa !12
  br label %pred.store.continue45

pred.store.continue45:                            ; preds = %pred.store.if44, %pred.store.continue43
  %37 = extractelement <4 x i1> %8, i64 3
  br i1 %37, label %pred.store.if46, label %pred.store.continue47

pred.store.if46:                                  ; preds = %pred.store.continue45
  %38 = extractelement <4 x i32> %wide.load33, i64 3
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [1000010 x i8], ptr @vis, i64 0, i64 %39
  store i8 1, ptr %40, align 1, !tbaa !12
  br label %pred.store.continue47

pred.store.continue47:                            ; preds = %pred.store.if46, %pred.store.continue45
  %index.next = add nuw i64 %index, 8
  %41 = icmp eq i64 %index.next, 1000008
  br i1 %41, label %.preheader, label %vector.body, !llvm.loop !14

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv25 = phi i64 [ %indvars.iv, %.lr.ph.preheader ], [ %indvars.iv.next26, %.lr.ph ]
  %42 = getelementptr inbounds [1000010 x i32], ptr @s, i64 0, i64 %indvars.iv25
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = add nsw i32 %43, %indvars28
  store i32 %44, ptr %42, align 4, !tbaa !5
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, %indvars.iv23
  %45 = icmp ult i64 %indvars.iv.next26, 1000010
  br i1 %45, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.preheader:                                       ; preds = %pred.store.continue47
  %46 = load i32, ptr getelementptr inbounds (i8, ptr @s, i64 4000036), align 4, !tbaa !5
  %47 = icmp slt i32 %46, 1001
  br i1 %47, label %48, label %.loopexit

48:                                               ; preds = %.preheader
  %49 = sext i32 %46 to i64
  %50 = getelementptr inbounds [1000010 x i8], ptr @vis, i64 0, i64 %49
  store i8 1, ptr %50, align 1, !tbaa !12
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %48
  %51 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %52 = load i32, ptr @t, align 4, !tbaa !5
  %53 = add nsw i32 %52, -1
  store i32 %53, ptr @t, align 4, !tbaa !5
  %.not19 = icmp eq i32 %52, 0
  br i1 %.not19, label %._crit_edge22, label %.lr.ph21

.lr.ph21:                                         ; preds = %.loopexit, %.lr.ph21
  %54 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %55 = load i32, ptr @n, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1000010 x i8], ptr @vis, i64 0, i64 %56
  %58 = load i8, ptr %57, align 1, !tbaa !12, !range !17, !noundef !18
  %59 = trunc nuw i8 %58 to i1
  %60 = select i1 %59, ptr @.str.1, ptr @.str.2
  %61 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %60)
  %62 = load i32, ptr @t, align 4, !tbaa !5
  %63 = add nsw i32 %62, -1
  store i32 %63, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %62, 0
  br i1 %.not, label %._crit_edge22, label %.lr.ph21, !llvm.loop !19

._crit_edge22:                                    ; preds = %.lr.ph21, %.loopexit
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #1

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass