; LLVM IR from tangjz/acm-icpc :: self_training/2015-04-17 (H)

; 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
@x = external dso_local global i32, align 4
@inv = external dso_local global [2001 x i32], align 16
@d = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z1Cxi(i64 noundef, i32 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 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
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  store i32 1, ptr getelementptr inbounds ([2001 x i32], ptr @inv, i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %7

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

10:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %31

11:                                               ; preds = %7
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = sdiv i32 1000000007, %12
  %14 = sub nsw i32 1000000007, %13
  %15 = sext i32 %14 to i64
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = srem i32 1000000007, %16
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [2001 x i32], ptr @inv, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = mul nsw i64 %15, %21
  %23 = srem i64 %22, 1000000007
  %24 = trunc i64 %23 to i32
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [2001 x i32], ptr @inv, i64 0, i64 %26
  store i32 %24, ptr %27, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %11
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !9

31:                                               ; preds = %10
  br label %32

32:                                               ; preds = %98, %31
  %33 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @d, ptr noundef @x)
  %34 = icmp eq i32 %33, 3
  br i1 %34, label %35, label %44

35:                                               ; preds = %32
  %36 = load i32, ptr @n, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = load i64, ptr @d, align 8, !tbaa !11
  %39 = add nsw i64 %37, %38
  %40 = load i32, ptr @x, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = add nsw i64 %39, %41
  %43 = icmp ne i64 %42, 0
  br label %44

44:                                               ; preds = %35, %32
  %45 = phi i1 [ false, %32 ], [ %43, %35 ]
  br i1 %45, label %46, label %101

46:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %95, %46
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = load i32, ptr @x, align 4, !tbaa !5
  %50 = mul nsw i32 %48, %49
  %51 = load i32, ptr @n, align 4, !tbaa !5
  %52 = icmp sle i32 %50, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %98

54:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %55 = load i32, ptr @n, align 4, !tbaa !5
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = load i32, ptr @x, align 4, !tbaa !5
  %58 = mul nsw i32 %56, %57
  %59 = sub nsw i32 %55, %58
  store i32 %59, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %60 = load i64, ptr @d, align 8, !tbaa !11
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = call noundef i32 @_Z1Cxi(i64 noundef %60, i32 noundef %61)
  store i32 %62, ptr %6, align 4, !tbaa !5
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = load i32, ptr %5, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = load i64, ptr @d, align 8, !tbaa !11
  %68 = add nsw i64 %66, %67
  %69 = sub nsw i64 %68, 1
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = call noundef i32 @_Z1Cxi(i64 noundef %69, i32 noundef %70)
  %72 = sext i32 %71 to i64
  %73 = mul nsw i64 %64, %72
  %74 = srem i64 %73, 1000000007
  %75 = trunc i64 %74 to i32
  store i32 %75, ptr %6, align 4, !tbaa !5
  %76 = load i32, ptr %4, align 4, !tbaa !5
  %77 = and i32 %76, 1
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %85

79:                                               ; preds = %54
  %80 = load i32, ptr %6, align 4, !tbaa !5
  %81 = icmp ne i32 %80, 0
  br i1 %81, label %82, label %85

82:                                               ; preds = %79
  %83 = load i32, ptr %6, align 4, !tbaa !5
  %84 = sub nsw i32 1000000007, %83
  store i32 %84, ptr %6, align 4, !tbaa !5
  br label %85

85:                                               ; preds = %82, %79, %54
  %86 = load i32, ptr %6, align 4, !tbaa !5
  %87 = load i32, ptr %3, align 4, !tbaa !5
  %88 = add nsw i32 %87, %86
  store i32 %88, ptr %3, align 4, !tbaa !5
  %89 = load i32, ptr %3, align 4, !tbaa !5
  %90 = icmp sge i32 %89, 1000000007
  br i1 %90, label %91, label %94

91:                                               ; preds = %85
  %92 = load i32, ptr %3, align 4, !tbaa !5
  %93 = sub nsw i32 %92, 1000000007
  store i32 %93, ptr %3, align 4, !tbaa !5
  br label %94

94:                                               ; preds = %91, %85
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %95

95:                                               ; preds = %94
  %96 = load i32, ptr %4, align 4, !tbaa !5
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %4, align 4, !tbaa !5
  br label %47, !llvm.loop !13

98:                                               ; preds = %53
  %99 = load i32, ptr %3, align 4, !tbaa !5
  %100 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %99)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %32, !llvm.loop !14

101:                                              ; preds = %44
  ret i32 0
}

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

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

attributes #0 = { mustprogress 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !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"

@n = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@inv = external dso_local local_unnamed_addr global [2001 x i32], align 16
@d = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

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

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  store i32 1, ptr getelementptr inbounds (i8, ptr @inv, i64 4), align 4, !tbaa !5
  br label %3

.preheader30:                                     ; preds = %3
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @d, ptr noundef nonnull @x)
  %2 = icmp eq i32 %1, 3
  br i1 %2, label %.lr.ph35, label %.critedge

3:                                                ; preds = %0, %3
  %indvars.iv = phi i64 [ 2, %0 ], [ %indvars.iv.next, %3 ]
  %4 = trunc nuw nsw i64 %indvars.iv to i32
  %5 = udiv i32 1000000007, %4
  %6 = sub nuw nsw i32 1000000007, %5
  %7 = zext nneg i32 %6 to i64
  %8 = urem i32 1000000007, %4
  %9 = zext nneg i32 %8 to i64
  %10 = getelementptr inbounds [2001 x i32], ptr @inv, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = mul nsw i64 %12, %7
  %14 = srem i64 %13, 1000000007
  %15 = trunc nsw i64 %14 to i32
  %16 = getelementptr inbounds [2001 x i32], ptr @inv, i64 0, i64 %indvars.iv
  store i32 %15, ptr %16, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 2001
  br i1 %exitcond.not, label %.preheader30, label %3, !llvm.loop !9

.lr.ph35:                                         ; preds = %.preheader30, %._crit_edge
  %17 = load i32, ptr @n, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = load i64, ptr @d, align 8, !tbaa !11
  %20 = add nsw i64 %19, %18
  %21 = load i32, ptr @x, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = sub nsw i64 0, %22
  %.not = icmp eq i64 %20, %23
  br i1 %.not, label %.critedge, label %.preheader

.preheader:                                       ; preds = %.lr.ph35
  %.not2932 = icmp slt i32 %17, 0
  br i1 %.not2932, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.023.lcssa = phi i32 [ 0, %.preheader ], [ %.1, %.lr.ph ]
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.023.lcssa)
  %25 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @d, ptr noundef nonnull @x)
  %26 = icmp eq i32 %25, 3
  br i1 %26, label %.lr.ph35, label %.critedge, !llvm.loop !13

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %27 = phi i32 [ %52, %.lr.ph ], [ %17, %.preheader ]
  %28 = phi i32 [ %51, %.lr.ph ], [ 0, %.preheader ]
  %.02234 = phi i32 [ %49, %.lr.ph ], [ 0, %.preheader ]
  %.02333 = phi i32 [ %.1, %.lr.ph ], [ 0, %.preheader ]
  %29 = sub nsw i32 %27, %28
  %30 = load i64, ptr @d, align 8, !tbaa !11
  %31 = tail call noundef i32 @_Z1Cxi(i64 noundef %30, i32 noundef %.02234)
  %32 = sext i32 %31 to i64
  %33 = sext i32 %29 to i64
  %34 = load i64, ptr @d, align 8, !tbaa !11
  %35 = add nsw i64 %33, -1
  %36 = add i64 %35, %34
  %37 = tail call noundef i32 @_Z1Cxi(i64 noundef %36, i32 noundef %29)
  %38 = sext i32 %37 to i64
  %39 = mul nsw i64 %38, %32
  %40 = srem i64 %39, 1000000007
  %41 = trunc nsw i64 %40 to i32
  %42 = and i32 %.02234, 1
  %43 = icmp ne i32 %42, 0
  %44 = icmp ne i64 %40, 0
  %or.cond = select i1 %43, i1 %44, i1 false
  %45 = sub nsw i32 1000000007, %41
  %spec.select = select i1 %or.cond, i32 %45, i32 %41
  %46 = add nsw i32 %spec.select, %.02333
  %47 = icmp sgt i32 %46, 1000000006
  %48 = add nsw i32 %46, -1000000007
  %.1 = select i1 %47, i32 %48, i32 %46
  %49 = add nuw nsw i32 %.02234, 1
  %50 = load i32, ptr @x, align 4, !tbaa !5
  %51 = mul nsw i32 %50, %49
  %52 = load i32, ptr @n, align 4, !tbaa !5
  %.not29 = icmp sgt i32 %51, %52
  br i1 %.not29, label %._crit_edge, label %.lr.ph, !llvm.loop !14

.critedge:                                        ; preds = %.lr.ph35, %._crit_edge, %.preheader30
  ret i32 0
}

; 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 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 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 #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 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


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