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

; 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 [60000001 x i64], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z5iSqrtx(i64 noundef) #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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %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 8, ptr %2) #4
  br label %7

7:                                                ; preds = %63, %0
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  %9 = icmp eq i32 %8, 1
  br i1 %9, label %10, label %66

10:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %11 = load i64, ptr %2, align 8, !tbaa !5
  %12 = call noundef i64 @_Z5iSqrtx(i64 noundef %11)
  %13 = trunc i64 %12 to i32
  store i32 %13, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %14 = load i32, ptr %3, align 4, !tbaa !9
  %15 = load i32, ptr %3, align 4, !tbaa !9
  %16 = and i32 %15, 1
  %17 = icmp ne i32 %16, 0
  %18 = xor i1 %17, true
  %19 = zext i1 %18 to i32
  %20 = sub nsw i32 %14, %19
  store i32 %20, ptr %4, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %60, %10
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = icmp sge i32 %22, 1
  br i1 %23, label %25, label %24

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

25:                                               ; preds = %21
  %26 = load i64, ptr %2, align 8, !tbaa !5
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = sdiv i64 %26, %28
  %30 = load i32, ptr %4, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = sdiv i64 %29, %31
  %33 = call noundef i64 @_Z4calcx(i64 noundef %32)
  %34 = load i32, ptr %4, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [60000001 x i64], ptr @f, i64 0, i64 %35
  store i64 %33, ptr %36, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %37 = load i32, ptr %4, align 4, !tbaa !9
  %38 = mul nsw i32 %37, 3
  store i32 %38, ptr %6, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %54, %25
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = load i32, ptr %3, align 4, !tbaa !9
  %42 = icmp sle i32 %40, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %39
  store i32 7, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %59

44:                                               ; preds = %39
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [60000001 x i64], ptr @f, i64 0, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !5
  %49 = load i32, ptr %4, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [60000001 x i64], ptr @f, i64 0, i64 %50
  %52 = load i64, ptr %51, align 8, !tbaa !5
  %53 = sub nsw i64 %52, %48
  store i64 %53, ptr %51, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %44
  %55 = load i32, ptr %4, align 4, !tbaa !9
  %56 = mul nsw i32 %55, 2
  %57 = load i32, ptr %6, align 4, !tbaa !9
  %58 = add nsw i32 %57, %56
  store i32 %58, ptr %6, align 4, !tbaa !9
  br label %39, !llvm.loop !11

59:                                               ; preds = %43
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %4, align 4, !tbaa !9
  %62 = sub nsw i32 %61, 2
  store i32 %62, ptr %4, align 4, !tbaa !9
  br label %21, !llvm.loop !13

63:                                               ; preds = %24
  %64 = load i64, ptr getelementptr inbounds ([60000001 x i64], ptr @f, i64 0, i64 1), align 8, !tbaa !5
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %64)
  br label %7, !llvm.loop !14

66:                                               ; preds = %7
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %67 = load i32, ptr %1, align 4
  ret i32 %67
}

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


; 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 [60000001 x i64], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z5iSqrtx(i64 noundef) local_unnamed_addr #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: mustprogress uwtable
declare dso_local noundef i64 @_Z4calcx(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = icmp eq i32 %2, 1
  br i1 %3, label %.lr.ph23, label %._crit_edge24

.lr.ph23:                                         ; preds = %0, %._crit_edge21
  %4 = load i64, ptr %1, align 8, !tbaa !5
  %5 = call noundef i64 @_Z5iSqrtx(i64 noundef %4)
  %6 = trunc i64 %5 to i32
  %7 = and i32 %6, 1
  %8 = xor i32 %7, 1
  %9 = sub nsw i32 %6, %8
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph20.preheader, label %._crit_edge21

.lr.ph20.preheader:                               ; preds = %.lr.ph23
  %11 = mul i32 %6, 3
  %.neg = mul nuw nsw i32 %8, -3
  %12 = add i32 %.neg, %11
  %13 = sub i32 %6, %8
  %14 = shl i32 %13, 1
  %15 = zext nneg i32 %9 to i64
  br label %.lr.ph20

._crit_edge21:                                    ; preds = %._crit_edge, %.lr.ph23
  %16 = load i64, ptr getelementptr inbounds (i8, ptr @f, i64 8), align 8, !tbaa !5
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %16)
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %19 = icmp eq i32 %18, 1
  br i1 %19, label %.lr.ph23, label %._crit_edge24, !llvm.loop !9

.lr.ph20:                                         ; preds = %.lr.ph20.preheader, %._crit_edge
  %indvars.iv30 = phi i64 [ %15, %.lr.ph20.preheader ], [ %indvars.iv.next31, %._crit_edge ]
  %indvars.iv25 = phi i32 [ %14, %.lr.ph20.preheader ], [ %indvars.iv.next26, %._crit_edge ]
  %indvars.iv = phi i32 [ %12, %.lr.ph20.preheader ], [ %indvars.iv.next, %._crit_edge ]
  %20 = zext i32 %indvars.iv25 to i64
  %21 = load i64, ptr %1, align 8, !tbaa !5
  %22 = sdiv i64 %21, %indvars.iv30
  %23 = sdiv i64 %22, %indvars.iv30
  %24 = call noundef i64 @_Z4calcx(i64 noundef %23)
  %25 = getelementptr inbounds [60000001 x i64], ptr @f, i64 0, i64 %indvars.iv30
  store i64 %24, ptr %25, align 8, !tbaa !5
  %26 = trunc i64 %indvars.iv30 to i32
  %27 = mul i32 %26, 3
  %.not16 = icmp sgt i32 %27, %6
  br i1 %.not16, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph20
  %28 = zext i32 %indvars.iv to i64
  br label %31

._crit_edge:                                      ; preds = %31, %.lr.ph20
  %indvars.iv.next31 = add nsw i64 %indvars.iv30, -2
  %29 = trunc nuw i64 %indvars.iv30 to i32
  %30 = icmp sgt i32 %29, 2
  %indvars.iv.next = add i32 %indvars.iv, -6
  %indvars.iv.next26 = add i32 %indvars.iv25, -4
  br i1 %30, label %.lr.ph20, label %._crit_edge21, !llvm.loop !11

31:                                               ; preds = %.lr.ph, %31
  %indvars.iv27 = phi i64 [ %28, %.lr.ph ], [ %indvars.iv.next28, %31 ]
  %32 = phi i64 [ %24, %.lr.ph ], [ %35, %31 ]
  %33 = getelementptr inbounds [60000001 x i64], ptr @f, i64 0, i64 %indvars.iv27
  %34 = load i64, ptr %33, align 8, !tbaa !5
  %35 = sub nsw i64 %32, %34
  store i64 %35, ptr %25, align 8, !tbaa !5
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, %20
  %36 = trunc nuw i64 %indvars.iv.next28 to i32
  %.not = icmp sgt i32 %36, %6
  br i1 %.not, label %._crit_edge, label %31, !llvm.loop !12

._crit_edge24:                                    ; preds = %._crit_edge21, %0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  ret i32 0
}

; 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 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 = { 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 = { 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 = !{!"long long", !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}


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