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

; 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 [7 x i8], align 1
@.str.1 = 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
  %7 = alloca i32, align 4
  %8 = 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 %9

9:                                                ; preds = %64, %0
  %10 = load i32, ptr %2, align 4, !tbaa !9
  %11 = icmp slt i32 %10, 1000001
  br i1 %11, label %13, label %12

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

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

19:                                               ; preds = %13
  %20 = load i32, ptr %2, align 4, !tbaa !9
  %21 = load i32, ptr @tot, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr @tot, align 4, !tbaa !9
  %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 !9
  br label %25

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

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

30:                                               ; preds = %26
  %31 = load i32, ptr %4, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1000001 x i32], ptr @prime, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = load i32, ptr %2, align 4, !tbaa !9
  %36 = sdiv i32 1000000, %35
  %37 = icmp sle i32 %34, %36
  br label %38

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

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

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

57:                                               ; preds = %41
  store i32 5, ptr %3, align 4
  br label %62

58:                                               ; preds = %41
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %4, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %4, align 4, !tbaa !9
  br label %26, !llvm.loop !13

62:                                               ; preds = %57, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %2, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %2, align 4, !tbaa !9
  br label %9, !llvm.loop !15

67:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  br label %68

68:                                               ; preds = %99, %67
  %69 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %5, ptr noundef %6, ptr noundef %7)
  %70 = icmp eq i32 %69, 3
  br i1 %70, label %71, label %78

71:                                               ; preds = %68
  %72 = load i32, ptr %5, align 4, !tbaa !9
  %73 = load i32, ptr %6, align 4, !tbaa !9
  %74 = add nsw i32 %72, %73
  %75 = load i32, ptr %7, align 4, !tbaa !9
  %76 = add nsw i32 %74, %75
  %77 = icmp ne i32 %76, 0
  br label %78

78:                                               ; preds = %71, %68
  %79 = phi i1 [ false, %68 ], [ %77, %71 ]
  br i1 %79, label %80, label %104

80:                                               ; preds = %78
  %81 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %81, ptr %8, align 4, !tbaa !9
  br label %82

82:                                               ; preds = %95, %80
  %83 = load i32, ptr %7, align 4, !tbaa !9
  %84 = icmp ne i32 %83, 0
  br i1 %84, label %85, label %99

85:                                               ; preds = %82
  %86 = load i32, ptr %8, align 4, !tbaa !9
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %87
  %89 = load i8, ptr %88, align 1, !tbaa !5, !range !11, !noundef !12
  %90 = trunc i8 %89 to i1
  br i1 %90, label %94, label %91

91:                                               ; preds = %85
  %92 = load i32, ptr %7, align 4, !tbaa !9
  %93 = add nsw i32 %92, -1
  store i32 %93, ptr %7, align 4, !tbaa !9
  br label %94

94:                                               ; preds = %91, %85
  br label %95

95:                                               ; preds = %94
  %96 = load i32, ptr %6, align 4, !tbaa !9
  %97 = load i32, ptr %8, align 4, !tbaa !9
  %98 = add nsw i32 %97, %96
  store i32 %98, ptr %8, align 4, !tbaa !9
  br label %82, !llvm.loop !16

99:                                               ; preds = %82
  %100 = load i32, ptr %6, align 4, !tbaa !9
  %101 = load i32, ptr %8, align 4, !tbaa !9
  %102 = sub nsw i32 %101, %100
  store i32 %102, ptr %8, align 4, !tbaa !9
  %103 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %102)
  br label %68, !llvm.loop !17

104:                                              ; preds = %78
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %105 = load i32, ptr %1, align 4
  ret i32 %105
}

; 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 [7 x i8], align 1
@.str.1 = 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
  %2 = alloca i32, align 4
  %3 = 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 %7

4:                                                ; preds = %.critedge
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %6 = icmp eq i32 %5, 3
  br i1 %6, label %.lr.ph35, label %.critedge2

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

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

17:                                               ; preds = %12, %7
  %18 = phi i32 [ %13, %12 ], [ %8, %7 ]
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %.lr.ph, label %.critedge

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

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

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

.critedge:                                        ; preds = %23, %26, %17
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next39, 1000001
  br i1 %exitcond.not, label %4, label %7, !llvm.loop !15

.lr.ph35:                                         ; preds = %4, %._crit_edge
  %33 = load i32, ptr %1, align 4, !tbaa !9
  %34 = load i32, ptr %2, align 4, !tbaa !9
  %35 = add nsw i32 %34, %33
  %36 = load i32, ptr %3, align 4, !tbaa !9
  %37 = sub i32 0, %36
  %.not = icmp eq i32 %35, %37
  br i1 %.not, label %.critedge2, label %.preheader

.preheader:                                       ; preds = %.lr.ph35
  %.not2230 = icmp eq i32 %36, 0
  br i1 %.not2230, label %._crit_edge, label %.lr.ph33.preheader

.lr.ph33.preheader:                               ; preds = %.preheader
  %38 = sext i32 %33 to i64
  %39 = sext i32 %34 to i64
  br label %.lr.ph33

.lr.ph33:                                         ; preds = %.lr.ph33.preheader, %46
  %indvars.iv41 = phi i64 [ %38, %.lr.ph33.preheader ], [ %indvars.iv.next42, %46 ]
  %40 = phi i32 [ %36, %.lr.ph33.preheader ], [ %.pr29, %46 ]
  %41 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %indvars.iv41
  %42 = load i8, ptr %41, align 1, !tbaa !5, !range !11, !noundef !12
  %43 = trunc nuw i8 %42 to i1
  br i1 %43, label %46, label %44

44:                                               ; preds = %.lr.ph33
  %45 = add nsw i32 %40, -1
  store i32 %45, ptr %3, align 4, !tbaa !9
  br label %46

46:                                               ; preds = %.lr.ph33, %44
  %.pr29 = phi i32 [ %40, %.lr.ph33 ], [ %45, %44 ]
  %indvars.iv.next42 = add nsw i64 %indvars.iv41, %39
  %.not22 = icmp eq i32 %.pr29, 0
  br i1 %.not22, label %._crit_edge.loopexit, label %.lr.ph33, !llvm.loop !16

._crit_edge.loopexit:                             ; preds = %46
  %47 = trunc nsw i64 %indvars.iv.next42 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %.0.lcssa = phi i32 [ %33, %.preheader ], [ %47, %._crit_edge.loopexit ]
  %48 = sub nsw i32 %.0.lcssa, %34
  %49 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %48)
  %50 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %51 = icmp eq i32 %50, 3
  br i1 %51, label %.lr.ph35, label %.critedge2, !llvm.loop !17

.critedge2:                                       ; preds = %.lr.ph35, %._crit_edge, %4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  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