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

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

@tot = external dso_local global i32, align 4
@prime = external dso_local global [16001 x i32], align 16
@vis = external dso_local global [16001 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = 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
  %6 = 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 %7

7:                                                ; preds = %62, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 16001
  br i1 %9, label %11, label %10

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

11:                                               ; preds = %7
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [16001 x i8], ptr @vis, i64 0, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !9, !range !11, !noundef !12
  %16 = trunc i8 %15 to i1
  br i1 %16, label %23, label %17

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

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

24:                                               ; preds = %57, %23
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = load i32, ptr @tot, align 4, !tbaa !5
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %36

28:                                               ; preds = %24
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [16001 x i32], ptr @prime, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = mul nsw i32 %29, %33
  %35 = icmp slt i32 %34, 16001
  br label %36

36:                                               ; preds = %28, %24
  %37 = phi i1 [ false, %24 ], [ %35, %28 ]
  br i1 %37, label %39, label %38

38:                                               ; preds = %36
  store i32 5, ptr %3, align 4
  br label %60

39:                                               ; preds = %36
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [16001 x i32], ptr @prime, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = mul nsw i32 %40, %44
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [16001 x i8], ptr @vis, i64 0, i64 %46
  store i8 1, ptr %47, align 1, !tbaa !9
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [16001 x i32], ptr @prime, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = srem i32 %48, %52
  %54 = icmp eq i32 %53, 0
  br i1 %54, label %55, label %56

55:                                               ; preds = %39
  store i32 5, ptr %3, align 4
  br label %60

56:                                               ; preds = %39
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %4, align 4, !tbaa !5
  br label %24, !llvm.loop !13

60:                                               ; preds = %55, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %2, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !15

65:                                               ; preds = %10
  store i8 1, ptr getelementptr inbounds ([16001 x i8], ptr @vis, i64 0, i64 2), align 2, !tbaa !9
  store i8 1, ptr getelementptr inbounds ([16001 x i8], ptr @vis, i64 0, i64 1), align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  br label %66

66:                                               ; preds = %85, %65
  %67 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %6)
  %68 = icmp ne i32 %67, -1
  br i1 %68, label %69, label %72

69:                                               ; preds = %66
  %70 = load i32, ptr %6, align 4, !tbaa !5
  %71 = icmp sgt i32 %70, 0
  br label %72

72:                                               ; preds = %69, %66
  %73 = phi i1 [ false, %66 ], [ %71, %69 ]
  br i1 %73, label %75, label %74

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

75:                                               ; preds = %72
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [16001 x i8], ptr @vis, i64 0, i64 %78
  %80 = load i8, ptr %79, align 1, !tbaa !9, !range !11, !noundef !12
  %81 = trunc i8 %80 to i1
  %82 = zext i1 %81 to i64
  %83 = select i1 %81, ptr @.str.2, ptr @.str.3
  %84 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %76, ptr noundef %83)
  br label %85

85:                                               ; preds = %75
  %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 %66, !llvm.loop !16

88:                                               ; preds = %74
  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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

@tot = external dso_local local_unnamed_addr global i32, align 4
@prime = external dso_local local_unnamed_addr global [16001 x i32], align 16
@vis = external dso_local local_unnamed_addr global [16001 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = 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 {
  %1 = alloca i32, align 4
  %tot.promoted = load i32, ptr @tot, align 4, !tbaa !5
  br label %8

2:                                                ; preds = %.critedge
  store i8 1, ptr getelementptr inbounds (i8, ptr @vis, i64 2), align 2, !tbaa !9
  store i8 1, ptr getelementptr inbounds (i8, ptr @vis, i64 1), align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %4 = icmp ne i32 %3, -1
  %5 = load i32, ptr %1, align 4
  %6 = icmp sgt i32 %5, 0
  %7 = select i1 %4, i1 %6, i1 false
  br i1 %7, label %.lr.ph23, label %._crit_edge

8:                                                ; preds = %0, %.critedge
  %indvars.iv25 = phi i64 [ 2, %0 ], [ %indvars.iv.next26, %.critedge ]
  %9 = phi i32 [ %tot.promoted, %0 ], [ %19, %.critedge ]
  %10 = getelementptr inbounds [16001 x i8], ptr @vis, i64 0, i64 %indvars.iv25
  %11 = load i8, ptr %10, align 1, !tbaa !9, !range !11, !noundef !12
  %12 = trunc nuw i8 %11 to i1
  br i1 %12, label %18, label %13

13:                                               ; preds = %8
  %14 = add nsw i32 %9, 1
  store i32 %14, ptr @tot, align 4, !tbaa !5
  %15 = sext i32 %9 to i64
  %16 = getelementptr inbounds [16001 x i32], ptr @prime, i64 0, i64 %15
  %17 = trunc nuw nsw i64 %indvars.iv25 to i32
  store i32 %17, ptr %16, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %13, %8
  %19 = phi i32 [ %14, %13 ], [ %9, %8 ]
  %20 = icmp sgt i32 %19, 0
  br i1 %20, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %18
  %21 = zext nneg i32 %19 to i64
  %22 = trunc nuw nsw i64 %indvars.iv25 to i32
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %27
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %27 ]
  %23 = getelementptr inbounds [16001 x i32], ptr @prime, i64 0, i64 %indvars.iv
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = mul nsw i32 %24, %22
  %26 = icmp slt i32 %25, 16001
  br i1 %26, label %27, label %.critedge

27:                                               ; preds = %.lr.ph
  %28 = sext i32 %25 to i64
  %29 = getelementptr inbounds [16001 x i8], ptr @vis, i64 0, i64 %28
  store i8 1, ptr %29, align 1, !tbaa !9
  %30 = srem i32 %22, %24
  %31 = icmp ne i32 %30, 0
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %32 = icmp ult i64 %indvars.iv.next, %21
  %or.cond = select i1 %31, i1 %32, i1 false
  br i1 %or.cond, label %.lr.ph, label %.critedge, !llvm.loop !13

.critedge:                                        ; preds = %.lr.ph, %27, %18
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next26, 16001
  br i1 %exitcond.not, label %2, label %8, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph23, %2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  ret i32 0

.lr.ph23:                                         ; preds = %2, %.lr.ph23
  %33 = phi i32 [ %43, %.lr.ph23 ], [ %5, %2 ]
  %.022 = phi i32 [ %40, %.lr.ph23 ], [ 1, %2 ]
  %34 = zext nneg i32 %33 to i64
  %35 = getelementptr inbounds [16001 x i8], ptr @vis, i64 0, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !9, !range !11, !noundef !12
  %37 = trunc nuw i8 %36 to i1
  %38 = select i1 %37, ptr @.str.2, ptr @.str.3
  %39 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.022, ptr noundef nonnull %38)
  %40 = add nuw nsw i32 %.022, 1
  %41 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %42 = icmp ne i32 %41, -1
  %43 = load i32, ptr %1, align 4
  %44 = icmp sgt i32 %43, 0
  %45 = select i1 %42, i1 %44, i1 false
  br i1 %45, label %.lr.ph23, label %._crit_edge, !llvm.loop !16
}

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

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

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

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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" }
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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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