; LLVM IR from tangjz/acm-icpc :: poj (2262)

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

7:                                                ; preds = %62, %0
  %8 = load i32, ptr %2, align 4, !tbaa !9
  %9 = icmp slt i32 %8, 1000001
  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 !9
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !5, !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 !9
  %19 = load i32, ptr @tot, align 4, !tbaa !9
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr @tot, align 4, !tbaa !9
  %21 = sext i32 %19 to i64
  %22 = getelementptr inbounds [1000001 x i32], ptr @prime, i64 0, i64 %21
  store i32 %18, ptr %22, align 4, !tbaa !9
  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 !9
  br label %24

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

28:                                               ; preds = %24
  %29 = load i32, ptr %4, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [1000001 x i32], ptr @prime, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = load i32, ptr %2, align 4, !tbaa !9
  %34 = sdiv i32 1000000, %33
  %35 = icmp sle i32 %32, %34
  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 !9
  %41 = load i32, ptr %4, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [1000001 x i32], ptr @prime, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !9
  %45 = mul nsw i32 %40, %44
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %46
  store i8 1, ptr %47, align 1, !tbaa !5
  %48 = load i32, ptr %2, align 4, !tbaa !9
  %49 = load i32, ptr %4, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [1000001 x i32], ptr @prime, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !9
  %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 !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %4, align 4, !tbaa !9
  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 !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %2, align 4, !tbaa !9
  br label %7, !llvm.loop !15

65:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  br label %66

66:                                               ; preds = %119, %65
  %67 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %5)
  %68 = icmp eq i32 %67, 1
  br i1 %68, label %69, label %72

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

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

74:                                               ; preds = %72
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %75

75:                                               ; preds = %115, %74
  %76 = load i32, ptr %6, align 4, !tbaa !9
  %77 = load i32, ptr @tot, align 4, !tbaa !9
  %78 = icmp slt i32 %76, %77
  br i1 %78, label %79, label %87

79:                                               ; preds = %75
  %80 = load i32, ptr %6, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [1000001 x i32], ptr @prime, i64 0, i64 %81
  %83 = load i32, ptr %82, align 4, !tbaa !9
  %84 = load i32, ptr %5, align 4, !tbaa !9
  %85 = ashr i32 %84, 1
  %86 = icmp sle i32 %83, %85
  br label %87

87:                                               ; preds = %79, %75
  %88 = phi i1 [ false, %75 ], [ %86, %79 ]
  br i1 %88, label %90, label %89

89:                                               ; preds = %87
  store i32 10, ptr %3, align 4
  br label %118

90:                                               ; preds = %87
  %91 = load i32, ptr %5, align 4, !tbaa !9
  %92 = load i32, ptr %6, align 4, !tbaa !9
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [1000001 x i32], ptr @prime, i64 0, i64 %93
  %95 = load i32, ptr %94, align 4, !tbaa !9
  %96 = sub nsw i32 %91, %95
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %97
  %99 = load i8, ptr %98, align 1, !tbaa !5, !range !11, !noundef !12
  %100 = trunc i8 %99 to i1
  br i1 %100, label %114, label %101

101:                                              ; preds = %90
  %102 = load i32, ptr %5, align 4, !tbaa !9
  %103 = load i32, ptr %6, align 4, !tbaa !9
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [1000001 x i32], ptr @prime, i64 0, i64 %104
  %106 = load i32, ptr %105, align 4, !tbaa !9
  %107 = load i32, ptr %5, align 4, !tbaa !9
  %108 = load i32, ptr %6, align 4, !tbaa !9
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [1000001 x i32], ptr @prime, i64 0, i64 %109
  %111 = load i32, ptr %110, align 4, !tbaa !9
  %112 = sub nsw i32 %107, %111
  %113 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %102, i32 noundef %106, i32 noundef %112)
  store i32 10, ptr %3, align 4
  br label %118

114:                                              ; preds = %90
  br label %115

115:                                              ; preds = %114
  %116 = load i32, ptr %6, align 4, !tbaa !9
  %117 = add nsw i32 %116, 1
  store i32 %117, ptr %6, align 4, !tbaa !9
  br label %75, !llvm.loop !16

118:                                              ; preds = %101, %89
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %119

119:                                              ; preds = %118
  br label %66, !llvm.loop !17

120:                                              ; preds = %72
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %121 = load i32, ptr %1, align 4
  ret i32 %121
}

; 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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}
!17 = distinct !{!17, !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 [1000001 x i32], align 16
@vis = external dso_local local_unnamed_addr global [1000001 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 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
  store i8 1, ptr getelementptr inbounds (i8, ptr @vis, i64 1), align 1, !tbaa !5
  %tot.promoted = load i32, ptr @tot, align 4, !tbaa !9
  br label %8

2:                                                ; preds = %.critedge
  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 eq i32 %3, 1
  %5 = load i32, ptr %1, align 4
  %6 = icmp ne i32 %5, 0
  %7 = select i1 %4, i1 %6, i1 false
  br i1 %7, label %.preheader, label %._crit_edge

8:                                                ; preds = %0, %.critedge
  %indvars.iv37 = phi i64 [ 2, %0 ], [ %indvars.iv.next38, %.critedge ]
  %9 = phi i32 [ %tot.promoted, %0 ], [ %19, %.critedge ]
  %10 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %indvars.iv37
  %11 = load i8, ptr %10, align 1, !tbaa !5, !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 !9
  %15 = sext i32 %9 to i64
  %16 = getelementptr inbounds [1000001 x i32], ptr @prime, i64 0, i64 %15
  %17 = trunc nuw nsw i64 %indvars.iv37 to i32
  store i32 %17, ptr %16, align 4, !tbaa !9
  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, label %.critedge

.lr.ph:                                           ; preds = %18
  %21 = trunc nuw nsw i64 %indvars.iv37 to i32
  %22 = udiv i32 1000000, %21
  %23 = zext nneg i32 %19 to i64
  br label %24

24:                                               ; preds = %27, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %27 ], [ 0, %.lr.ph ]
  %25 = getelementptr inbounds [1000001 x i32], ptr @prime, i64 0, i64 %indvars.iv
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %.not25 = icmp sgt i32 %26, %22
  br i1 %.not25, label %.critedge, label %27

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

.critedge:                                        ; preds = %24, %27, %18
  %indvars.iv.next38 = add nuw nsw i64 %indvars.iv37, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next38, 1000001
  br i1 %exitcond.not, label %2, label %8, !llvm.loop !15

.preheader:                                       ; preds = %2, %.critedge2
  %34 = phi i32 [ %52, %.critedge2 ], [ %5, %2 ]
  %35 = load i32, ptr @tot, align 4, !tbaa !9
  %36 = icmp sgt i32 %35, 0
  br i1 %36, label %.lr.ph32, label %.critedge2

.lr.ph32:                                         ; preds = %.preheader
  %37 = ashr i32 %34, 1
  %wide.trip.count = zext nneg i32 %35 to i64
  br label %39

38:                                               ; preds = %42
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %exitcond43.not = icmp eq i64 %indvars.iv.next41, %wide.trip.count
  br i1 %exitcond43.not, label %.critedge2, label %39, !llvm.loop !16

39:                                               ; preds = %.lr.ph32, %38
  %indvars.iv40 = phi i64 [ 0, %.lr.ph32 ], [ %indvars.iv.next41, %38 ]
  %40 = getelementptr inbounds [1000001 x i32], ptr @prime, i64 0, i64 %indvars.iv40
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %.not = icmp sgt i32 %41, %37
  br i1 %.not, label %.critedge2, label %42

42:                                               ; preds = %39
  %43 = sub nsw i32 %34, %41
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !5, !range !11, !noundef !12
  %47 = trunc nuw i8 %46 to i1
  br i1 %47, label %38, label %48

48:                                               ; preds = %42
  %49 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %34, i32 noundef %41, i32 noundef %43)
  br label %.critedge2

.critedge2:                                       ; preds = %38, %39, %.preheader, %48
  %50 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %51 = icmp eq i32 %50, 1
  %52 = load i32, ptr %1, align 4
  %53 = icmp ne i32 %52, 0
  %54 = select i1 %51, i1 %53, i1 false
  br i1 %54, label %.preheader, label %._crit_edge, !llvm.loop !17

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

; 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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}
!17 = distinct !{!17, !14}


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