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

; 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
@pr = external dso_local global [1000001 x i32], align 16
@d = external dso_local global [1000001 x i32], align 16
@.str = external hidden unnamed_addr constant [6 x i8], align 1

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z5solvex(i64 noundef) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %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
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %6

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

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

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

16:                                               ; preds = %10
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [1000001 x i32], ptr @d, i64 0, i64 %19
  store i32 %17, ptr %20, 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 @pr, i64 0, i64 %23
  store i32 %17, ptr %24, align 4, !tbaa !5
  br label %25

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

26:                                               ; preds = %54, %25
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [1000001 x i32], ptr @pr, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = mul nsw i32 %27, %31
  store i32 %32, ptr %5, align 4, !tbaa !5
  %33 = icmp slt i32 %32, 1000001
  br i1 %33, label %35, label %34

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

35:                                               ; preds = %26
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [1000001 x i32], ptr @pr, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1000001 x i32], ptr @d, i64 0, i64 %41
  store i32 %39, ptr %42, align 4, !tbaa !5
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1000001 x i32], ptr @d, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [1000001 x i32], ptr @pr, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = icmp eq i32 %46, %50
  br i1 %51, label %52, label %53

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

53:                                               ; preds = %35
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %4, align 4, !tbaa !5
  br label %26, !llvm.loop !9

57:                                               ; preds = %52, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %58

58:                                               ; preds = %57
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !11

62:                                               ; preds = %9
  %63 = call noundef i64 @_Z5solvex(i64 noundef 1000000000000)
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %63)
  ret i32 0
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #2 = { 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 #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}


; 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
@pr = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@d = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@.str = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z5solvex(i64 noundef) local_unnamed_addr #0

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

1:                                                ; preds = %._crit_edge
  %2 = tail call noundef i64 @_Z5solvex(i64 noundef 1000000000000)
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %2)
  ret i32 0

4:                                                ; preds = %0, %._crit_edge
  %indvars.iv18 = phi i64 [ 2, %0 ], [ %indvars.iv.next19, %._crit_edge ]
  %5 = phi i32 [ %tot.promoted, %0 ], [ %13, %._crit_edge ]
  %6 = getelementptr inbounds [1000001 x i32], ptr @d, i64 0, i64 %indvars.iv18
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %.not = icmp eq i32 %7, 0
  %8 = trunc nuw nsw i64 %indvars.iv18 to i32
  br i1 %.not, label %9, label %._crit_edge21

9:                                                ; preds = %4
  store i32 %8, ptr %6, align 4, !tbaa !5
  %10 = add nsw i32 %5, 1
  store i32 %10, ptr @tot, align 4, !tbaa !5
  %11 = sext i32 %5 to i64
  %12 = getelementptr inbounds [1000001 x i32], ptr @pr, i64 0, i64 %11
  store i32 %8, ptr %12, align 4, !tbaa !5
  br label %._crit_edge21

._crit_edge21:                                    ; preds = %4, %9
  %13 = phi i32 [ %10, %9 ], [ %5, %4 ]
  %14 = load i32, ptr @pr, align 16, !tbaa !5
  %15 = mul nsw i32 %14, %8
  %16 = icmp slt i32 %15, 1000001
  br i1 %16, label %.lr.ph, label %._crit_edge

17:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = getelementptr inbounds [1000001 x i32], ptr @pr, i64 0, i64 %indvars.iv.next
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = mul nsw i32 %19, %8
  %21 = icmp slt i32 %20, 1000001
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.lr.ph:                                           ; preds = %._crit_edge21, %17
  %indvars.iv = phi i64 [ %indvars.iv.next, %17 ], [ 0, %._crit_edge21 ]
  %22 = phi i32 [ %20, %17 ], [ %15, %._crit_edge21 ]
  %23 = phi i32 [ %19, %17 ], [ %14, %._crit_edge21 ]
  %24 = sext i32 %22 to i64
  %25 = getelementptr inbounds [1000001 x i32], ptr @d, i64 0, i64 %24
  store i32 %23, ptr %25, align 4, !tbaa !5
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = icmp eq i32 %26, %23
  br i1 %27, label %._crit_edge, label %17

._crit_edge:                                      ; preds = %17, %.lr.ph, %._crit_edge21
  %indvars.iv.next19 = add nuw nsw i64 %indvars.iv18, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next19, 1000001
  br i1 %exitcond.not, label %1, label %4, !llvm.loop !11
}

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

attributes #0 = { mustprogress 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 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 #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" }

!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}


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