; LLVM IR from tangjz/acm-icpc :: self_training/2015-02-09 (E)

; 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
@tot = external dso_local global i32, align 4
@prime = external dso_local global [1000001 x i32], align 16
@f = external dso_local global [1000001 x i32], align 16
@sum = external dso_local global [1000001 x i64], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 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
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %101, %0
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 1000001
  br i1 %7, label %9, label %8

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

9:                                                ; preds = %5
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %25, label %15

15:                                               ; preds = %9
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %18
  store i32 %16, ptr %19, align 4, !tbaa !5
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = load i32, ptr @tot, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr @tot, align 4, !tbaa !5
  %23 = sext i32 %21 to i64
  %24 = getelementptr inbounds [1000001 x i32], ptr @prime, i64 0, i64 %23
  store i32 %20, ptr %24, align 4, !tbaa !5
  br label %25

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

26:                                               ; preds = %78, %25
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = load i32, ptr @tot, align 4, !tbaa !5
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %30, label %40

30:                                               ; preds = %26
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1000001 x i32], ptr @prime, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = mul nsw i64 %32, %37
  %39 = icmp slt i64 %38, 1000001
  br label %40

40:                                               ; preds = %30, %26
  %41 = phi i1 [ false, %26 ], [ %39, %30 ]
  br i1 %41, label %43, label %42

42:                                               ; preds = %40
  store i32 5, ptr %3, align 4
  br label %81

43:                                               ; preds = %40
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [1000001 x i32], ptr @prime, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = icmp eq i32 %47, %51
  br i1 %52, label %53, label %58

53:                                               ; preds = %43
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [1000001 x i32], ptr @prime, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  br label %59

58:                                               ; preds = %43
  br label %59

59:                                               ; preds = %58, %53
  %60 = phi i32 [ %57, %53 ], [ 1, %58 ]
  %61 = load i32, ptr %2, align 4, !tbaa !5
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [1000001 x i32], ptr @prime, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = mul nsw i32 %61, %65
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %67
  store i32 %60, ptr %68, align 4, !tbaa !5
  %69 = load i32, ptr %2, align 4, !tbaa !5
  %70 = load i32, ptr %4, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [1000001 x i32], ptr @prime, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = srem i32 %69, %73
  %75 = icmp eq i32 %74, 0
  br i1 %75, label %76, label %77

76:                                               ; preds = %59
  store i32 5, ptr %3, align 4
  br label %81

77:                                               ; preds = %59
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %4, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %4, align 4, !tbaa !5
  br label %26, !llvm.loop !9

81:                                               ; preds = %76, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %2, align 4, !tbaa !5
  %84 = icmp sgt i32 %83, 2
  br i1 %84, label %85, label %100

85:                                               ; preds = %82
  %86 = load i32, ptr %2, align 4, !tbaa !5
  %87 = sub nsw i32 %86, 1
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [1000001 x i64], ptr @sum, i64 0, i64 %88
  %90 = load i64, ptr %89, align 8, !tbaa !11
  %91 = load i32, ptr %2, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %92
  %94 = load i32, ptr %93, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = add nsw i64 %90, %95
  %97 = load i32, ptr %2, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [1000001 x i64], ptr @sum, i64 0, i64 %98
  store i64 %96, ptr %99, align 8, !tbaa !11
  br label %100

100:                                              ; preds = %85, %82
  br label %101

101:                                              ; preds = %100
  %102 = load i32, ptr %2, align 4, !tbaa !5
  %103 = add nsw i32 %102, 1
  store i32 %103, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !13

104:                                              ; preds = %8
  br label %105

105:                                              ; preds = %108, %104
  %106 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %107 = icmp ne i32 %106, -1
  br i1 %107, label %108, label %114

108:                                              ; preds = %105
  %109 = load i32, ptr @n, align 4, !tbaa !5
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds [1000001 x i64], ptr @sum, i64 0, i64 %110
  %112 = load i64, ptr %111, align 8, !tbaa !11
  %113 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %112)
  br label %105, !llvm.loop !14

114:                                              ; preds = %105
  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 @printf(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 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !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 global i32, align 4
@tot = external dso_local local_unnamed_addr global i32, align 4
@prime = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@f = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@sum = external dso_local local_unnamed_addr global [1000001 x i64], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %tot.promoted = load i32, ptr @tot, align 4, !tbaa !5
  br label %2

.preheader:                                       ; preds = %39
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %.not28 = icmp eq i32 %1, -1
  br i1 %.not28, label %._crit_edge, label %.lr.ph29

2:                                                ; preds = %0, %39
  %indvars.iv31 = phi i64 [ 2, %0 ], [ %indvars.iv.next32, %39 ]
  %3 = phi i32 [ %tot.promoted, %0 ], [ %12, %39 ]
  %4 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %indvars.iv31
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %.not23 = icmp eq i32 %5, 0
  br i1 %.not23, label %6, label %11

6:                                                ; preds = %2
  %7 = trunc nuw nsw i64 %indvars.iv31 to i32
  store i32 %7, ptr %4, align 4, !tbaa !5
  %8 = add nsw i32 %3, 1
  store i32 %8, ptr @tot, align 4, !tbaa !5
  %9 = sext i32 %3 to i64
  %10 = getelementptr inbounds [1000001 x i32], ptr @prime, i64 0, i64 %9
  store i32 %7, ptr %10, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %6, %2
  %12 = phi i32 [ %8, %6 ], [ %3, %2 ]
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %11
  %14 = zext nneg i32 %12 to i64
  %15 = trunc nuw nsw i64 %indvars.iv31 to i32
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %21
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %21 ]
  %16 = getelementptr inbounds [1000001 x i32], ptr @prime, i64 0, i64 %indvars.iv
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = mul nsw i64 %indvars.iv31, %18
  %20 = icmp slt i64 %19, 1000001
  br i1 %20, label %21, label %.critedge

21:                                               ; preds = %.lr.ph
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = icmp eq i32 %22, %17
  %spec.select = select i1 %23, i32 %17, i32 1
  %24 = mul nsw i32 %17, %15
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %25
  store i32 %spec.select, ptr %26, align 4, !tbaa !5
  %27 = srem i32 %15, %17
  %28 = icmp ne i32 %27, 0
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %29 = icmp ult i64 %indvars.iv.next, %14
  %or.cond = select i1 %28, i1 %29, i1 false
  br i1 %or.cond, label %.lr.ph, label %.critedge, !llvm.loop !9

.critedge:                                        ; preds = %.lr.ph, %21, %11
  %30 = icmp ugt i64 %indvars.iv31, 2
  br i1 %30, label %31, label %39

31:                                               ; preds = %.critedge
  %32 = add nsw i64 %indvars.iv31, -1
  %33 = getelementptr inbounds [1000001 x i64], ptr @sum, i64 0, i64 %32
  %34 = load i64, ptr %33, align 8, !tbaa !11
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = add nsw i64 %34, %36
  %38 = getelementptr inbounds [1000001 x i64], ptr @sum, i64 0, i64 %indvars.iv31
  store i64 %37, ptr %38, align 8, !tbaa !11
  br label %39

39:                                               ; preds = %.critedge, %31
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next32, 1000001
  br i1 %exitcond.not, label %.preheader, label %2, !llvm.loop !13

.lr.ph29:                                         ; preds = %.preheader, %.lr.ph29
  %40 = load i32, ptr @n, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1000001 x i64], ptr @sum, i64 0, i64 %41
  %43 = load i64, ptr %42, align 8, !tbaa !11
  %44 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %43)
  %45 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %.not = icmp eq i32 %45, -1
  br i1 %.not, label %._crit_edge, label %.lr.ph29, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph29, %.preheader
  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 @printf(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 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass