; LLVM IR from tangjz/acm-icpc :: codeforces/gym (101412A)

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

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

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

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

10:                                               ; preds = %6
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [20001 x i8], ptr @vis, i64 0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !9, !range !11, !noundef !12
  %15 = trunc i8 %14 to i1
  br i1 %15, label %22, label %16

16:                                               ; preds = %10
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = load i32, ptr @tot, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr @tot, align 4, !tbaa !5
  %20 = sext i32 %18 to i64
  %21 = getelementptr inbounds [20001 x i32], ptr @prime, i64 0, i64 %20
  store i32 %17, ptr %21, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %16, %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  br label %23

23:                                               ; preds = %51, %22
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = load i32, ptr @tot, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %27, label %35

27:                                               ; preds = %23
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [20001 x i32], ptr @prime, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = mul nsw i32 %28, %32
  store i32 %33, ptr %5, align 4, !tbaa !5
  %34 = icmp slt i32 %33, 20001
  br label %35

35:                                               ; preds = %27, %23
  %36 = phi i1 [ false, %23 ], [ %34, %27 ]
  br i1 %36, label %38, label %37

37:                                               ; preds = %35
  store i32 5, ptr %3, align 4
  br label %54

38:                                               ; preds = %35
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [20001 x i8], ptr @vis, i64 0, i64 %40
  store i8 1, ptr %41, align 1, !tbaa !9
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [20001 x i32], ptr @prime, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = srem i32 %42, %46
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %50

49:                                               ; preds = %38
  store i32 5, ptr %3, align 4
  br label %54

50:                                               ; preds = %38
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %4, align 4, !tbaa !5
  br label %23, !llvm.loop !13

54:                                               ; preds = %49, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %55

55:                                               ; preds = %54
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %2, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !15

59:                                               ; preds = %9
  %60 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %61

61:                                               ; preds = %100, %59
  %62 = load i32, ptr @t, align 4, !tbaa !5
  %63 = add nsw i32 %62, -1
  store i32 %63, ptr @t, align 4, !tbaa !5
  %64 = icmp ne i32 %62, 0
  br i1 %64, label %65, label %104

65:                                               ; preds = %61
  %66 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @m)
  %67 = load i32, ptr @n, align 4, !tbaa !5
  %68 = call i32 @llvm.abs.i32(i32 %67, i1 true)
  store i32 %68, ptr @n, align 4, !tbaa !5
  %69 = load i32, ptr @m, align 4, !tbaa !5
  %70 = call i32 @llvm.abs.i32(i32 %69, i1 true)
  store i32 %70, ptr @m, align 4, !tbaa !5
  %71 = icmp slt i32 %68, %70
  br i1 %71, label %72, label %73

72:                                               ; preds = %65
  call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) @n, ptr noundef nonnull align 4 dereferenceable(4) @m) #5
  br label %73

73:                                               ; preds = %72, %65
  %74 = load i32, ptr @m, align 4, !tbaa !5
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %76, label %88

76:                                               ; preds = %73
  %77 = load i32, ptr @n, align 4, !tbaa !5
  %78 = load i32, ptr @n, align 4, !tbaa !5
  %79 = mul nsw i32 %77, %78
  %80 = load i32, ptr @m, align 4, !tbaa !5
  %81 = load i32, ptr @m, align 4, !tbaa !5
  %82 = mul nsw i32 %80, %81
  %83 = add nsw i32 %79, %82
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [20001 x i8], ptr @vis, i64 0, i64 %84
  %86 = load i8, ptr %85, align 1, !tbaa !9, !range !11, !noundef !12
  %87 = trunc i8 %86 to i1
  br i1 %87, label %99, label %98

88:                                               ; preds = %73
  %89 = load i32, ptr @n, align 4, !tbaa !5
  %90 = and i32 %89, 3
  %91 = icmp eq i32 %90, 3
  br i1 %91, label %92, label %99

92:                                               ; preds = %88
  %93 = load i32, ptr @n, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [20001 x i8], ptr @vis, i64 0, i64 %94
  %96 = load i8, ptr %95, align 1, !tbaa !9, !range !11, !noundef !12
  %97 = trunc i8 %96 to i1
  br i1 %97, label %99, label %98

98:                                               ; preds = %92, %76
  br label %100

99:                                               ; preds = %92, %88, %76
  br label %100

100:                                              ; preds = %99, %98
  %101 = phi ptr [ @.str.2, %98 ], [ @.str.3, %99 ]
  %102 = getelementptr inbounds [2 x i8], ptr %101, i64 0, i64 0
  %103 = call i32 @puts(ptr noundef %102)
  br label %61, !llvm.loop !16

104:                                              ; preds = %61
  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: 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, ...) #2

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

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

declare i32 @puts(ptr noundef) #2

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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 #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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

@tot = external dso_local local_unnamed_addr global i32, align 4
@prime = external dso_local local_unnamed_addr global [20001 x i32], align 16
@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@vis = external dso_local local_unnamed_addr global [20001 x i8], 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 [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %tot.promoted = load i32, ptr @tot, align 4, !tbaa !5
  br label %5

1:                                                ; preds = %.critedge
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %3 = load i32, ptr @t, align 4, !tbaa !5
  %4 = add nsw i32 %3, -1
  store i32 %4, ptr @t, align 4, !tbaa !5
  %.not19 = icmp eq i32 %3, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph20

5:                                                ; preds = %0, %.critedge
  %indvars.iv22 = phi i64 [ 2, %0 ], [ %indvars.iv.next23, %.critedge ]
  %6 = phi i32 [ %tot.promoted, %0 ], [ %16, %.critedge ]
  %7 = getelementptr inbounds [20001 x i8], ptr @vis, i64 0, i64 %indvars.iv22
  %8 = load i8, ptr %7, align 1, !tbaa !9, !range !11, !noundef !12
  %9 = trunc nuw i8 %8 to i1
  br i1 %9, label %15, label %10

10:                                               ; preds = %5
  %11 = add nsw i32 %6, 1
  store i32 %11, ptr @tot, align 4, !tbaa !5
  %12 = sext i32 %6 to i64
  %13 = getelementptr inbounds [20001 x i32], ptr @prime, i64 0, i64 %12
  %14 = trunc nuw nsw i64 %indvars.iv22 to i32
  store i32 %14, ptr %13, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %10, %5
  %16 = phi i32 [ %11, %10 ], [ %6, %5 ]
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %15
  %18 = zext nneg i32 %16 to i64
  %19 = trunc nuw nsw i64 %indvars.iv22 to i32
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %24
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %24 ]
  %20 = getelementptr inbounds [20001 x i32], ptr @prime, i64 0, i64 %indvars.iv
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = mul nsw i32 %21, %19
  %23 = icmp slt i32 %22, 20001
  br i1 %23, label %24, label %.critedge

24:                                               ; preds = %.lr.ph
  %25 = sext i32 %22 to i64
  %26 = getelementptr inbounds [20001 x i8], ptr @vis, i64 0, i64 %25
  store i8 1, ptr %26, align 1, !tbaa !9
  %27 = srem i32 %19, %21
  %28 = icmp ne i32 %27, 0
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %29 = icmp ult i64 %indvars.iv.next, %18
  %or.cond = select i1 %28, i1 %29, i1 false
  br i1 %or.cond, label %.lr.ph, label %.critedge, !llvm.loop !13

.critedge:                                        ; preds = %.lr.ph, %24, %15
  %indvars.iv.next23 = add nuw nsw i64 %indvars.iv22, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next23, 20001
  br i1 %exitcond.not, label %1, label %5, !llvm.loop !15

.lr.ph20:                                         ; preds = %1, %57
  %30 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %31 = load i32, ptr @n, align 4, !tbaa !5
  %32 = tail call i32 @llvm.abs.i32(i32 %31, i1 true)
  store i32 %32, ptr @n, align 4, !tbaa !5
  %33 = load i32, ptr @m, align 4, !tbaa !5
  %34 = tail call i32 @llvm.abs.i32(i32 %33, i1 true)
  store i32 %34, ptr @m, align 4, !tbaa !5
  %35 = icmp ult i32 %32, %34
  br i1 %35, label %36, label %37

36:                                               ; preds = %.lr.ph20
  tail call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) @n, ptr noundef nonnull align 4 dereferenceable(4) @m) #4
  %.pr = load i32, ptr @m, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %36, %.lr.ph20
  %38 = phi i32 [ %.pr, %36 ], [ %34, %.lr.ph20 ]
  %.not14 = icmp eq i32 %38, 0
  %39 = load i32, ptr @n, align 4, !tbaa !5
  br i1 %.not14, label %48, label %40

40:                                               ; preds = %37
  %41 = mul nsw i32 %39, %39
  %42 = mul nsw i32 %38, %38
  %43 = add nuw nsw i32 %41, %42
  %44 = zext nneg i32 %43 to i64
  %45 = getelementptr inbounds [20001 x i8], ptr @vis, i64 0, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !9, !range !11, !noundef !12
  %47 = trunc nuw i8 %46 to i1
  br i1 %47, label %56, label %57

48:                                               ; preds = %37
  %49 = and i32 %39, 3
  %50 = icmp eq i32 %49, 3
  br i1 %50, label %51, label %56

51:                                               ; preds = %48
  %52 = sext i32 %39 to i64
  %53 = getelementptr inbounds [20001 x i8], ptr @vis, i64 0, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !9, !range !11, !noundef !12
  %55 = trunc nuw i8 %54 to i1
  br i1 %55, label %56, label %57

56:                                               ; preds = %51, %48, %40
  br label %57

57:                                               ; preds = %40, %51, %56
  %58 = phi ptr [ @.str.3, %56 ], [ @.str.2, %51 ], [ @.str.2, %40 ]
  %59 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %58)
  %60 = load i32, ptr @t, align 4, !tbaa !5
  %61 = add nsw i32 %60, -1
  store i32 %61, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %60, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph20, !llvm.loop !16

._crit_edge:                                      ; preds = %57, %1
  ret i32 0
}

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #1

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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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