; LLVM IR from tangjz/acm-icpc :: 51nod (1334)

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

@Gcd = external dso_local global [3001 x [3001 x i32]], align 16
@t = external dso_local global i32, align 4
@w = external dso_local global i32, align 4
@called = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 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 i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = 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 %9

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

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

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

14:                                               ; preds = %29, %13
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

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

19:                                               ; preds = %14
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = call noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef %20, i32 noundef %21)
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [3001 x [3001 x i32]], ptr @Gcd, i64 0, i64 %24
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [3001 x i32], ptr %25, i64 0, i64 %27
  store i32 %22, ptr %28, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %19
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %4, align 4, !tbaa !5
  br label %14, !llvm.loop !9

32:                                               ; preds = %18
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %2, align 4, !tbaa !5
  br label %9, !llvm.loop !11

36:                                               ; preds = %12
  %37 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %38

38:                                               ; preds = %90, %36
  %39 = load i32, ptr @t, align 4, !tbaa !5
  %40 = add nsw i32 %39, -1
  store i32 %40, ptr @t, align 4, !tbaa !5
  %41 = icmp ne i32 %39, 0
  br i1 %41, label %42, label %93

42:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store i64 0, ptr %7, align 8, !tbaa !12
  %43 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %5, ptr noundef %6, ptr noundef @w)
  store i32 0, ptr @called, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 1, ptr %8, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %87, %42
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = load i32, ptr @w, align 4, !tbaa !5
  %47 = icmp slt i32 %45, %46
  br i1 %47, label %48, label %53

48:                                               ; preds = %44
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = load i64, ptr %6, align 8, !tbaa !12
  %52 = icmp sle i64 %50, %51
  br label %53

53:                                               ; preds = %48, %44
  %54 = phi i1 [ false, %44 ], [ %52, %48 ]
  br i1 %54, label %56, label %55

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

56:                                               ; preds = %53
  %57 = load i32, ptr %8, align 4, !tbaa !5
  %58 = load i64, ptr %6, align 8, !tbaa !12
  %59 = load i32, ptr %8, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = sub nsw i64 %58, %60
  %62 = load i32, ptr @w, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = sdiv i64 %61, %63
  %65 = call noundef i64 @_Z1fix(i32 noundef %57, i64 noundef %64)
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = load i64, ptr %5, align 8, !tbaa !12
  %69 = icmp slt i64 %67, %68
  br i1 %69, label %70, label %81

70:                                               ; preds = %56
  %71 = load i32, ptr %8, align 4, !tbaa !5
  %72 = load i64, ptr %5, align 8, !tbaa !12
  %73 = sub nsw i64 %72, 1
  %74 = load i32, ptr %8, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = sub nsw i64 %73, %75
  %77 = load i32, ptr @w, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = sdiv i64 %76, %78
  %80 = call noundef i64 @_Z1fix(i32 noundef %71, i64 noundef %79)
  br label %82

81:                                               ; preds = %56
  br label %82

82:                                               ; preds = %81, %70
  %83 = phi i64 [ %80, %70 ], [ 0, %81 ]
  %84 = sub nsw i64 %65, %83
  %85 = load i64, ptr %7, align 8, !tbaa !12
  %86 = add nsw i64 %85, %84
  store i64 %86, ptr %7, align 8, !tbaa !12
  br label %87

87:                                               ; preds = %82
  %88 = load i32, ptr %8, align 4, !tbaa !5
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %8, align 4, !tbaa !5
  br label %44, !llvm.loop !14

90:                                               ; preds = %55
  %91 = load i64, ptr %7, align 8, !tbaa !12
  %92 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %91)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %38, !llvm.loop !15

93:                                               ; preds = %38
  ret i32 0
}

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

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

; 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, ...) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i64 @_Z1fix(i32 noundef, i64 noundef) #4

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

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

@Gcd = external dso_local local_unnamed_addr global [3001 x [3001 x i32]], align 16
@t = external dso_local global i32, align 4
@w = external dso_local global i32, align 4
@called = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

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

.preheader:                                       ; preds = %0, %._crit_edge
  %indvars.iv38 = phi i64 [ 1, %0 ], [ %indvars.iv.next39, %._crit_edge ]
  %3 = icmp ugt i64 %indvars.iv38, 1
  br i1 %3, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %4 = trunc nuw nsw i64 %indvars.iv38 to i32
  br label %9

5:                                                ; preds = %._crit_edge
  %6 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %7 = load i32, ptr @t, align 4, !tbaa !5
  %8 = add nsw i32 %7, -1
  store i32 %8, ptr @t, align 4, !tbaa !5
  %.not33 = icmp eq i32 %7, 0
  br i1 %.not33, label %._crit_edge36, label %.lr.ph35

._crit_edge:                                      ; preds = %9, %.preheader
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %exitcond41.not = icmp eq i64 %indvars.iv.next39, 3001
  br i1 %exitcond41.not, label %5, label %.preheader, !llvm.loop !9

9:                                                ; preds = %.lr.ph, %9
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %9 ]
  %10 = trunc nuw nsw i64 %indvars.iv to i32
  %11 = tail call noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef %4, i32 noundef %10)
  %12 = getelementptr inbounds [3001 x [3001 x i32]], ptr @Gcd, i64 0, i64 %indvars.iv38, i64 %indvars.iv
  store i32 %11, ptr %12, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %indvars.iv38
  br i1 %exitcond.not, label %._crit_edge, label %9, !llvm.loop !11

.lr.ph35:                                         ; preds = %5, %._crit_edge32
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull @w)
  store i32 0, ptr @called, align 4, !tbaa !5
  %14 = load i32, ptr @w, align 4, !tbaa !5
  %15 = icmp sgt i32 %14, 1
  %16 = load i64, ptr %2, align 8
  %17 = icmp sgt i64 %16, 0
  %18 = select i1 %15, i1 %17, i1 false
  br i1 %18, label %.lr.ph31, label %._crit_edge32

._crit_edge32:                                    ; preds = %38, %.lr.ph35
  %.019.lcssa = phi i64 [ 0, %.lr.ph35 ], [ %41, %38 ]
  %19 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %.019.lcssa)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  %20 = load i32, ptr @t, align 4, !tbaa !5
  %21 = add nsw i32 %20, -1
  store i32 %21, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %._crit_edge36, label %.lr.ph35, !llvm.loop !12

.lr.ph31:                                         ; preds = %.lr.ph35, %38
  %indvars.iv42 = phi i64 [ %indvars.iv.next43, %38 ], [ 1, %.lr.ph35 ]
  %22 = phi i64 [ %45, %38 ], [ %16, %.lr.ph35 ]
  %23 = phi i32 [ %42, %38 ], [ %14, %.lr.ph35 ]
  %.01928 = phi i64 [ %41, %38 ], [ 0, %.lr.ph35 ]
  %24 = sub nsw i64 %22, %indvars.iv42
  %25 = sext i32 %23 to i64
  %26 = sdiv i64 %24, %25
  %27 = trunc nuw nsw i64 %indvars.iv42 to i32
  %28 = call noundef i64 @_Z1fix(i32 noundef %27, i64 noundef %26)
  %29 = load i64, ptr %1, align 8, !tbaa !13
  %30 = icmp sgt i64 %29, %indvars.iv42
  br i1 %30, label %31, label %38

31:                                               ; preds = %.lr.ph31
  %32 = xor i64 %indvars.iv42, -1
  %33 = add nsw i64 %29, %32
  %34 = load i32, ptr @w, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = sdiv i64 %33, %35
  %37 = call noundef i64 @_Z1fix(i32 noundef %27, i64 noundef %36)
  br label %38

38:                                               ; preds = %.lr.ph31, %31
  %39 = phi i64 [ %37, %31 ], [ 0, %.lr.ph31 ]
  %40 = add i64 %28, %.01928
  %41 = sub i64 %40, %39
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %42 = load i32, ptr @w, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = icmp slt i64 %indvars.iv.next43, %43
  %45 = load i64, ptr %2, align 8
  %46 = icmp sgt i64 %45, %indvars.iv42
  %47 = select i1 %44, i1 %46, i1 false
  br i1 %47, label %.lr.ph31, label %._crit_edge32, !llvm.loop !15

._crit_edge36:                                    ; preds = %._crit_edge32, %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: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef, i32 noundef) local_unnamed_addr #2

; 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 #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i64 @_Z1fix(i32 noundef, i64 noundef) local_unnamed_addr #4

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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 = { inlinehint 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 #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}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = distinct !{!15, !10}


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