; LLVM IR from tangjz/acm-icpc :: projecteuler (9)

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

@f = external dso_local global [3001 x i32], align 16
@Sqrt = external dso_local global [9006001 x i32], align 16
@.str = external hidden unnamed_addr constant [3 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
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.memset.p0.i64(ptr align 16 @f, i8 -1, i64 12004, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %22, %0
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = icmp slt i32 %12, 3001
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %25

15:                                               ; preds = %11
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = mul nsw i32 %17, %18
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [9006001 x i32], ptr @Sqrt, i64 0, i64 %20
  store i32 %16, ptr %21, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %15
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %2, align 4, !tbaa !5
  br label %11, !llvm.loop !9

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

26:                                               ; preds = %87, %25
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = icmp slt i32 %27, 3001
  br i1 %28, label %30, label %29

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

30:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %5, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %83, %30
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = add nsw i32 %34, %35
  %37 = icmp slt i32 %36, 3001
  br i1 %37, label %39, label %38

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

39:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = mul nsw i32 %40, %41
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = mul nsw i32 %43, %44
  %46 = add nsw i32 %42, %45
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [9006001 x i32], ptr @Sqrt, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  store i32 %49, ptr %6, align 4, !tbaa !5
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %82

52:                                               ; preds = %39
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = add nsw i32 %53, %54
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = add nsw i32 %55, %56
  %58 = icmp slt i32 %57, 3001
  br i1 %58, label %59, label %82

59:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = add nsw i32 %60, %61
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = add nsw i32 %62, %63
  store i32 %64, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = mul nsw i32 %65, %66
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = mul nsw i32 %67, %68
  store i32 %69, ptr %8, align 4, !tbaa !5
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [3001 x i32], ptr @f, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = load i32, ptr %8, align 4, !tbaa !5
  %75 = icmp slt i32 %73, %74
  br i1 %75, label %76, label %81

76:                                               ; preds = %59
  %77 = load i32, ptr %8, align 4, !tbaa !5
  %78 = load i32, ptr %7, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [3001 x i32], ptr @f, i64 0, i64 %79
  store i32 %77, ptr %80, align 4, !tbaa !5
  br label %81

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

82:                                               ; preds = %81, %52, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %83

83:                                               ; preds = %82
  %84 = load i32, ptr %5, align 4, !tbaa !5
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %5, align 4, !tbaa !5
  br label %33, !llvm.loop !11

86:                                               ; preds = %38
  br label %87

87:                                               ; preds = %86
  %88 = load i32, ptr %3, align 4, !tbaa !5
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %3, align 4, !tbaa !5
  br label %26, !llvm.loop !12

90:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %91 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %9)
  br label %92

92:                                               ; preds = %96, %90
  %93 = load i32, ptr %9, align 4, !tbaa !5
  %94 = add nsw i32 %93, -1
  store i32 %94, ptr %9, align 4, !tbaa !5
  %95 = icmp ne i32 %93, 0
  br i1 %95, label %96, label %103

96:                                               ; preds = %92
  %97 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %10)
  %98 = load i32, ptr %10, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [3001 x i32], ptr @f, i64 0, i64 %99
  %101 = load i32, ptr %100, align 4, !tbaa !5
  %102 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %101)
  br label %92, !llvm.loop !13

103:                                              ; preds = %92
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %104 = load i32, ptr %1, align 4
  ret i32 %104
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

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

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

declare i32 @printf(ptr noundef, ...) #3

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 nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 #4 = { 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 = distinct !{!12, !10}
!13 = distinct !{!13, !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"

@f = external dso_local local_unnamed_addr global [3001 x i32], align 16
@Sqrt = external dso_local local_unnamed_addr global [9006001 x i32], align 16
@.str = external hidden unnamed_addr constant [3 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
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(12004) @f, i8 -1, i64 12004, i1 false)
  br label %3

3:                                                ; preds = %3, %0
  %indvars.iv = phi i64 [ 1, %0 ], [ %indvars.iv.next.5, %3 ]
  %4 = mul nuw nsw i64 %indvars.iv, %indvars.iv
  %5 = getelementptr inbounds [9006001 x i32], ptr @Sqrt, i64 0, i64 %4
  %6 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %6, ptr %5, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %7 = mul nuw nsw i64 %indvars.iv.next, %indvars.iv.next
  %8 = getelementptr inbounds [9006001 x i32], ptr @Sqrt, i64 0, i64 %7
  %9 = trunc nuw nsw i64 %indvars.iv.next to i32
  store i32 %9, ptr %8, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %10 = mul nuw nsw i64 %indvars.iv.next.1, %indvars.iv.next.1
  %11 = getelementptr inbounds [9006001 x i32], ptr @Sqrt, i64 0, i64 %10
  %12 = trunc nuw nsw i64 %indvars.iv.next.1 to i32
  store i32 %12, ptr %11, align 4, !tbaa !5
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %13 = mul nuw nsw i64 %indvars.iv.next.2, %indvars.iv.next.2
  %14 = getelementptr inbounds [9006001 x i32], ptr @Sqrt, i64 0, i64 %13
  %15 = trunc nuw nsw i64 %indvars.iv.next.2 to i32
  store i32 %15, ptr %14, align 4, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %16 = mul nuw nsw i64 %indvars.iv.next.3, %indvars.iv.next.3
  %17 = getelementptr inbounds [9006001 x i32], ptr @Sqrt, i64 0, i64 %16
  %18 = trunc nuw nsw i64 %indvars.iv.next.3 to i32
  store i32 %18, ptr %17, align 4, !tbaa !5
  %indvars.iv.next.4 = add nuw nsw i64 %indvars.iv, 5
  %19 = mul nuw nsw i64 %indvars.iv.next.4, %indvars.iv.next.4
  %20 = getelementptr inbounds [9006001 x i32], ptr @Sqrt, i64 0, i64 %19
  %21 = trunc nuw nsw i64 %indvars.iv.next.4 to i32
  store i32 %21, ptr %20, align 4, !tbaa !5
  %indvars.iv.next.5 = add nuw nsw i64 %indvars.iv, 6
  %exitcond.not.5 = icmp eq i64 %indvars.iv.next.5, 3001
  br i1 %exitcond.not.5, label %.preheader, label %3, !llvm.loop !9

.loopexit:                                        ; preds = %47, %.preheader
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %indvars.iv.next52 = add nsw i64 %indvars.iv51, -1
  %exitcond58.not = icmp eq i64 %indvars.iv.next54, 3001
  br i1 %exitcond58.not, label %22, label %.preheader, !llvm.loop !11

22:                                               ; preds = %.loopexit
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %24 = load i32, ptr %1, align 4, !tbaa !5
  %25 = add nsw i32 %24, -1
  store i32 %25, ptr %1, align 4, !tbaa !5
  %.not40 = icmp eq i32 %24, 0
  br i1 %.not40, label %._crit_edge, label %.lr.ph41

.preheader:                                       ; preds = %3, %.loopexit
  %indvars.iv53 = phi i64 [ %indvars.iv.next54, %.loopexit ], [ 1, %3 ]
  %indvars.iv51 = phi i64 [ %indvars.iv.next52, %.loopexit ], [ 3000, %3 ]
  %indvars.iv43 = phi i64 [ %indvars.iv.next44, %.loopexit ], [ 2, %3 ]
  %indvars.iv.next54 = add nuw nsw i64 %indvars.iv53, 1
  %26 = add nuw nsw i64 %indvars.iv.next54, %indvars.iv53
  %27 = icmp ult i64 %26, 3001
  br i1 %27, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %28 = mul nuw nsw i64 %indvars.iv53, %indvars.iv53
  br label %29

29:                                               ; preds = %.lr.ph, %47
  %indvars.iv45 = phi i64 [ %indvars.iv43, %.lr.ph ], [ %indvars.iv.next46, %47 ]
  %.in = phi i64 [ %26, %.lr.ph ], [ %48, %47 ]
  %30 = mul nuw nsw i64 %indvars.iv45, %indvars.iv45
  %31 = add nuw nsw i64 %30, %28
  %32 = getelementptr inbounds [9006001 x i32], ptr @Sqrt, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %.not36 = icmp eq i32 %33, 0
  br i1 %.not36, label %47, label %34

34:                                               ; preds = %29
  %35 = trunc i64 %.in to i32
  %36 = add nsw i32 %33, %35
  %37 = icmp slt i32 %36, 3001
  br i1 %37, label %38, label %47

38:                                               ; preds = %34
  %39 = mul nuw nsw i64 %indvars.iv45, %indvars.iv53
  %40 = trunc nuw i64 %39 to i32
  %41 = mul nsw i32 %33, %40
  %42 = sext i32 %36 to i64
  %43 = getelementptr inbounds [3001 x i32], ptr @f, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = icmp slt i32 %44, %41
  br i1 %45, label %46, label %47

46:                                               ; preds = %38
  store i32 %41, ptr %43, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %38, %46, %34, %29
  %indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1
  %48 = add nuw nsw i64 %indvars.iv.next46, %indvars.iv53
  %exitcond50.not = icmp eq i64 %indvars.iv.next46, %indvars.iv51
  br i1 %exitcond50.not, label %.loopexit, label %29, !llvm.loop !12

.lr.ph41:                                         ; preds = %22, %.lr.ph41
  %49 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [3001 x i32], ptr @f, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %53)
  %55 = load i32, ptr %1, align 4, !tbaa !5
  %56 = add nsw i32 %55, -1
  store i32 %56, ptr %1, align 4, !tbaa !5
  %.not = icmp eq i32 %55, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph41, !llvm.loop !13

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

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

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

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

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 nounwind willreturn memory(argmem: write) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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