; LLVM IR from tangjz/acm-icpc :: hdu (6745)

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

@dp = external dso_local global [1001 x [1001 x i32]], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = 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
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %8

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

11:                                               ; preds = %8
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %74

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

13:                                               ; preds = %67, %12
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = icmp slt i32 %14, 1001
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %13
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = icmp sgt i32 %18, 1
  br i1 %19, label %20, label %35

20:                                               ; preds = %17
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1001 x [1001 x i32]], ptr @dp, i64 0, i64 %22
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [1001 x i32], ptr %23, i64 0, i64 %25
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = sub nsw i32 %27, 1
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [1001 x [1001 x i32]], ptr @dp, i64 0, i64 %29
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1001 x i32], ptr %30, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  call void @_Z7upd_maxRii(ptr noundef nonnull align 4 dereferenceable(4) %26, i32 noundef %34)
  br label %35

35:                                               ; preds = %20, %17
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = icmp sgt i32 %36, 1
  br i1 %37, label %38, label %53

38:                                               ; preds = %35
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [1001 x [1001 x i32]], ptr @dp, i64 0, i64 %40
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [1001 x i32], ptr %41, i64 0, i64 %43
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [1001 x [1001 x i32]], ptr @dp, i64 0, i64 %46
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = sub nsw i32 %48, 1
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [1001 x i32], ptr %47, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  call void @_Z7upd_maxRii(ptr noundef nonnull align 4 dereferenceable(4) %44, i32 noundef %52)
  br label %53

53:                                               ; preds = %38, %35
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = call noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef %54, i32 noundef %55)
  %57 = icmp eq i32 %56, 1
  %58 = zext i1 %57 to i32
  %59 = load i32, ptr %2, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [1001 x [1001 x i32]], ptr @dp, i64 0, i64 %60
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [1001 x i32], ptr %61, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = add nsw i32 %65, %58
  store i32 %66, ptr %64, align 4, !tbaa !5
  br label %67

67:                                               ; preds = %53
  %68 = load i32, ptr %4, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %4, align 4, !tbaa !5
  br label %13, !llvm.loop !9

70:                                               ; preds = %16
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %2, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !11

74:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %75 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %5)
  br label %76

76:                                               ; preds = %80, %74
  %77 = load i32, ptr %5, align 4, !tbaa !5
  %78 = add nsw i32 %77, -1
  store i32 %78, ptr %5, align 4, !tbaa !5
  %79 = icmp ne i32 %77, 0
  br i1 %79, label %80, label %90

80:                                               ; preds = %76
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %81 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %6, ptr noundef %7)
  %82 = load i32, ptr %6, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [1001 x [1001 x i32]], ptr @dp, i64 0, i64 %83
  %85 = load i32, ptr %7, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [1001 x i32], ptr %84, i64 0, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !5
  %89 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %88)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %76, !llvm.loop !12

90:                                               ; preds = %76
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  %91 = load i32, ptr %1, align 4
  ret i32 %91
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z7upd_maxRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef, i32 noundef) #3

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

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

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

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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #3 = { 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 #4 = { "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 }

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


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

@dp = external dso_local global [1001 x [1001 x i32]], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  br label %.preheader

.preheader:                                       ; preds = %0, %.split.us
  %indvars.iv31 = phi i64 [ 1, %0 ], [ %indvars.iv.next32, %.split.us ]
  %4 = icmp ugt i64 %indvars.iv31, 1
  %5 = add nsw i64 %indvars.iv31, -1
  br i1 %4, label %.preheader.split.us.peel.next, label %.preheader.split.peel.next

.preheader.split.peel.next:                       ; preds = %.preheader
  %6 = trunc nuw nsw i64 %indvars.iv31 to i32
  %7 = tail call noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef %6, i32 noundef 1)
  %8 = icmp eq i32 %7, 1
  %9 = zext i1 %8 to i32
  %10 = getelementptr inbounds [1001 x [1001 x i32]], ptr @dp, i64 0, i64 %indvars.iv31, i64 1
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = add nsw i32 %11, %9
  store i32 %12, ptr %10, align 4, !tbaa !5
  br label %39

.preheader.split.us.peel.next:                    ; preds = %.preheader
  %13 = getelementptr inbounds [1001 x [1001 x i32]], ptr @dp, i64 0, i64 %indvars.iv31, i64 1
  %14 = getelementptr inbounds [1001 x [1001 x i32]], ptr @dp, i64 0, i64 %5, i64 1
  %15 = load i32, ptr %14, align 4, !tbaa !5
  tail call void @_Z7upd_maxRii(ptr noundef nonnull align 4 dereferenceable(4) %13, i32 noundef %15)
  %16 = trunc nuw nsw i64 %indvars.iv31 to i32
  %17 = tail call noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef %16, i32 noundef 1)
  %18 = icmp eq i32 %17, 1
  %19 = zext i1 %18 to i32
  %20 = load i32, ptr %13, align 4, !tbaa !5
  %21 = add nsw i32 %20, %19
  store i32 %21, ptr %13, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %.preheader.split.us.peel.next, %22
  %indvars.iv26 = phi i64 [ 2, %.preheader.split.us.peel.next ], [ %indvars.iv.next27, %22 ]
  %23 = getelementptr inbounds [1001 x [1001 x i32]], ptr @dp, i64 0, i64 %indvars.iv31, i64 %indvars.iv26
  %24 = getelementptr inbounds [1001 x [1001 x i32]], ptr @dp, i64 0, i64 %5, i64 %indvars.iv26
  %25 = load i32, ptr %24, align 4, !tbaa !5
  tail call void @_Z7upd_maxRii(ptr noundef nonnull align 4 dereferenceable(4) %23, i32 noundef %25)
  %26 = add nsw i64 %indvars.iv26, -1
  %27 = getelementptr inbounds [1001 x [1001 x i32]], ptr @dp, i64 0, i64 %indvars.iv31, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  tail call void @_Z7upd_maxRii(ptr noundef nonnull align 4 dereferenceable(4) %23, i32 noundef %28)
  %29 = trunc nuw nsw i64 %indvars.iv26 to i32
  %30 = tail call noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef %16, i32 noundef %29)
  %31 = icmp eq i32 %30, 1
  %32 = zext i1 %31 to i32
  %33 = load i32, ptr %23, align 4, !tbaa !5
  %34 = add nsw i32 %33, %32
  store i32 %34, ptr %23, align 4, !tbaa !5
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %exitcond29.not = icmp eq i64 %indvars.iv.next27, 1001
  br i1 %exitcond29.not, label %.split.us, label %22, !llvm.loop !9

35:                                               ; preds = %.split.us
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  %36 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %37 = load i32, ptr %1, align 4, !tbaa !5
  %38 = add nsw i32 %37, -1
  store i32 %38, ptr %1, align 4, !tbaa !5
  %.not22 = icmp eq i32 %37, 0
  br i1 %.not22, label %._crit_edge, label %.lr.ph

.split.us:                                        ; preds = %39, %22
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %exitcond34.not = icmp eq i64 %indvars.iv.next32, 1001
  br i1 %exitcond34.not, label %35, label %.preheader, !llvm.loop !12

39:                                               ; preds = %.preheader.split.peel.next, %39
  %40 = phi i32 [ %12, %.preheader.split.peel.next ], [ %48, %39 ]
  %indvars.iv = phi i64 [ 2, %.preheader.split.peel.next ], [ %indvars.iv.next, %39 ]
  %41 = getelementptr inbounds [1001 x [1001 x i32]], ptr @dp, i64 0, i64 %indvars.iv31, i64 %indvars.iv
  tail call void @_Z7upd_maxRii(ptr noundef nonnull align 4 dereferenceable(4) %41, i32 noundef %40)
  %42 = trunc nuw nsw i64 %indvars.iv to i32
  %43 = tail call noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef %6, i32 noundef %42)
  %44 = icmp eq i32 %43, 1
  %45 = zext i1 %44 to i32
  %46 = getelementptr inbounds [1001 x [1001 x i32]], ptr @dp, i64 0, i64 %indvars.iv31, i64 %indvars.iv
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = add nsw i32 %47, %45
  store i32 %48, ptr %46, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 1001
  br i1 %exitcond.not, label %.split.us, label %39, !llvm.loop !13

.lr.ph:                                           ; preds = %35, %.lr.ph
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #5
  %49 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [1001 x [1001 x i32]], ptr @dp, i64 0, i64 %51, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %55)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  %57 = load i32, ptr %1, align 4, !tbaa !5
  %58 = add nsw i32 %57, -1
  store i32 %58, ptr %1, align 4, !tbaa !5
  %.not = icmp eq i32 %57, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  ret i32 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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z7upd_maxRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef, i32 noundef) local_unnamed_addr #3

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

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

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #3 = { 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 #4 = { 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 #5 = { 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, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.peeled.count", i32 1}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10, !11}
!14 = distinct !{!14, !10}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass