; LLVM IR from tangjz/acm-icpc :: Summer_Training/2016-07-21 (A - Acperience - liuzy)

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

@N = external dso_local global i32, align 4
@T = external dso_local global i32, align 4
@ans = external dso_local global i64, align 8
@sum = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @T)
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %62, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = load i32, ptr @T, align 4, !tbaa !5
  %10 = icmp sle i32 %8, %9
  br i1 %10, label %11, label %65

11:                                               ; preds = %7
  store i64 0, ptr @sum, align 8, !tbaa !9
  store i64 0, ptr @ans, align 8, !tbaa !9
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @N)
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %38, %11
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = load i32, ptr @N, align 4, !tbaa !5
  %16 = icmp sle i32 %14, %15
  br i1 %16, label %17, label %41

17:                                               ; preds = %13
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %4)
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = icmp sgt i32 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %17
  %22 = load i32, ptr %4, align 4, !tbaa !5
  br label %26

23:                                               ; preds = %17
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = sub nsw i32 0, %24
  br label %26

26:                                               ; preds = %23, %21
  %27 = phi i32 [ %22, %21 ], [ %25, %23 ]
  %28 = sext i32 %27 to i64
  %29 = load i64, ptr @sum, align 8, !tbaa !9
  %30 = add nsw i64 %29, %28
  store i64 %30, ptr @sum, align 8, !tbaa !9
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = mul nsw i64 %32, %34
  %36 = load i64, ptr @ans, align 8, !tbaa !9
  %37 = add nsw i64 %36, %35
  store i64 %37, ptr @ans, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %26
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %3, align 4, !tbaa !5
  br label %13, !llvm.loop !11

41:                                               ; preds = %13
  %42 = load i64, ptr @ans, align 8, !tbaa !9
  %43 = load i32, ptr @N, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = mul nsw i64 %42, %44
  %46 = load i64, ptr @sum, align 8, !tbaa !9
  %47 = load i64, ptr @sum, align 8, !tbaa !9
  %48 = mul nsw i64 %46, %47
  %49 = sub nsw i64 %45, %48
  store i64 %49, ptr @ans, align 8, !tbaa !9
  %50 = load i64, ptr @ans, align 8, !tbaa !9
  %51 = load i32, ptr @N, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = call noundef i64 @_Z3gcdxx(i64 noundef %50, i64 noundef %52)
  store i64 %53, ptr %5, align 8, !tbaa !9
  %54 = load i64, ptr @ans, align 8, !tbaa !9
  %55 = load i64, ptr %5, align 8, !tbaa !9
  %56 = sdiv i64 %54, %55
  %57 = load i32, ptr @N, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = load i64, ptr %5, align 8, !tbaa !9
  %60 = sdiv i64 %58, %59
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %56, i64 noundef %60)
  br label %62

62:                                               ; preds = %41
  %63 = load i32, ptr %2, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !13

65:                                               ; preds = %7
  call void @exit(i32 noundef 0) #6
  unreachable
}

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

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

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #4

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 = { 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 = { noreturn 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 #5 = { nounwind }
attributes #6 = { noreturn 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !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"

@N = external dso_local global i32, align 4
@T = external dso_local global i32, align 4
@ans = external dso_local local_unnamed_addr global i64, align 8
@sum = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1

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

; Function Attrs: mustprogress norecurse noreturn uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @T)
  %3 = load i32, ptr @T, align 4, !tbaa !5
  %.not11 = icmp slt i32 %3, 1
  br i1 %.not11, label %._crit_edge15, label %.lr.ph14

.lr.ph14:                                         ; preds = %0, %._crit_edge
  %.012 = phi i32 [ %31, %._crit_edge ], [ 1, %0 ]
  store i64 0, ptr @sum, align 8, !tbaa !9
  store i64 0, ptr @ans, align 8, !tbaa !9
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @N)
  %5 = load i32, ptr @N, align 4, !tbaa !5
  %.not89 = icmp slt i32 %5, 1
  br i1 %.not89, label %.lr.ph14.._crit_edge_crit_edge, label %.lr.ph

.lr.ph14.._crit_edge_crit_edge:                   ; preds = %.lr.ph14
  %.pre = load i64, ptr @ans, align 8, !tbaa !9
  %.pre17 = load i64, ptr @sum, align 8, !tbaa !9
  br label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph14, %.lr.ph
  %.0610 = phi i32 [ %16, %.lr.ph ], [ 1, %.lr.ph14 ]
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %7 = load i32, ptr %1, align 4
  %8 = call i32 @llvm.abs.i32(i32 %7, i1 true)
  %9 = zext nneg i32 %8 to i64
  %10 = load i64, ptr @sum, align 8, !tbaa !9
  %11 = add nsw i64 %10, %9
  store i64 %11, ptr @sum, align 8, !tbaa !9
  %12 = sext i32 %7 to i64
  %13 = mul nsw i64 %12, %12
  %14 = load i64, ptr @ans, align 8, !tbaa !9
  %15 = add nsw i64 %14, %13
  store i64 %15, ptr @ans, align 8, !tbaa !9
  %16 = add nuw nsw i32 %.0610, 1
  %17 = load i32, ptr @N, align 4, !tbaa !5
  %.not8.not = icmp slt i32 %.0610, %17
  br i1 %.not8.not, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph14.._crit_edge_crit_edge
  %18 = phi i64 [ %.pre17, %.lr.ph14.._crit_edge_crit_edge ], [ %11, %.lr.ph ]
  %19 = phi i64 [ %.pre, %.lr.ph14.._crit_edge_crit_edge ], [ %15, %.lr.ph ]
  %.lcssa = phi i32 [ %5, %.lr.ph14.._crit_edge_crit_edge ], [ %17, %.lr.ph ]
  %20 = sext i32 %.lcssa to i64
  %21 = mul nsw i64 %19, %20
  %22 = mul nsw i64 %18, %18
  %23 = sub nsw i64 %21, %22
  store i64 %23, ptr @ans, align 8, !tbaa !9
  %24 = call noundef i64 @_Z3gcdxx(i64 noundef %23, i64 noundef %20)
  %25 = load i64, ptr @ans, align 8, !tbaa !9
  %26 = sdiv i64 %25, %24
  %27 = load i32, ptr @N, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = sdiv i64 %28, %24
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %26, i64 noundef %29)
  %31 = add nuw nsw i32 %.012, 1
  %32 = load i32, ptr @T, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.012, %32
  br i1 %.not.not, label %.lr.ph14, label %._crit_edge15, !llvm.loop !13

._crit_edge15:                                    ; preds = %._crit_edge, %0
  call void @exit(i32 noundef 0) #7
  unreachable
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #5

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 noreturn 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 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 = { noreturn 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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { nounwind }
attributes #7 = { noreturn 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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