; LLVM IR from tangjz/acm-icpc :: poj (1274)

; 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
@m = external dso_local global i32, align 4
@count = external dso_local global i32, align 4
@link = external dso_local global [401 x i32], align 16
@g = external dso_local global [201 x [201 x i8]], align 16
@y = external dso_local global [201 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z4findi(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
  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 4, ptr %5) #5
  br label %6

6:                                                ; preds = %64, %0
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %8 = icmp ne i32 %7, -1
  br i1 %8, label %9, label %67

9:                                                ; preds = %6
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %40, %9
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = icmp sle i32 %11, %12
  br i1 %13, label %14, label %43

14:                                               ; preds = %10
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %4)
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [201 x [201 x i8]], ptr @g, i64 0, i64 %17
  %19 = getelementptr inbounds [201 x i8], ptr %18, i64 0, i64 0
  %20 = getelementptr inbounds i8, ptr %19, i64 1
  %21 = load i32, ptr @m, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = mul i64 %22, 1
  call void @llvm.memset.p0.i64(ptr align 1 %20, i8 0, i64 %23, i1 false)
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %36, %14
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = icmp sle i32 %25, %26
  br i1 %27, label %28, label %39

28:                                               ; preds = %24
  %29 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %5)
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [201 x [201 x i8]], ptr @g, i64 0, i64 %31
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [201 x i8], ptr %32, i64 0, i64 %34
  store i8 1, ptr %35, align 1, !tbaa !9
  br label %36

36:                                               ; preds = %28
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %3, align 4, !tbaa !5
  br label %24, !llvm.loop !11

39:                                               ; preds = %24
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %2, align 4, !tbaa !5
  br label %10, !llvm.loop !13

43:                                               ; preds = %10
  store i32 0, ptr @count, align 4, !tbaa !5
  %44 = load i32, ptr @m, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = mul i64 %45, 4
  call void @llvm.memset.p0.i64(ptr align 4 getelementptr inbounds (i32, ptr @link, i64 201), i8 0, i64 %46, i1 false)
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %61, %43
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = load i32, ptr @n, align 4, !tbaa !5
  %50 = icmp sle i32 %48, %49
  br i1 %50, label %51, label %64

51:                                               ; preds = %47
  %52 = load i32, ptr @m, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = mul i64 %53, 1
  call void @llvm.memset.p0.i64(ptr align 1 getelementptr inbounds (i8, ptr @y, i64 1), i8 0, i64 %54, i1 false)
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = call noundef zeroext i1 @_Z4findi(i32 noundef %55)
  br i1 %56, label %57, label %60

57:                                               ; preds = %51
  %58 = load i32, ptr @count, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr @count, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %57, %51
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %2, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %2, align 4, !tbaa !5
  br label %47, !llvm.loop !14

64:                                               ; preds = %47
  %65 = load i32, ptr @count, align 4, !tbaa !5
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %65)
  br label %6, !llvm.loop !15

67:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  ret i32 0
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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

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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !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
@m = external dso_local global i32, align 4
@count = external dso_local local_unnamed_addr global i32, align 4
@link = external dso_local local_unnamed_addr global [401 x i32], align 16
@g = external dso_local local_unnamed_addr global [201 x [201 x i8]], align 16
@y = external dso_local local_unnamed_addr global [201 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z4findi(i32 noundef) local_unnamed_addr #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 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() local_unnamed_addr #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %.not24 = icmp eq i32 %3, -1
  br i1 %.not24, label %._crit_edge25, label %.preheader

.preheader:                                       ; preds = %0, %._crit_edge23
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %.not1015 = icmp slt i32 %4, 1
  br i1 %.not1015, label %._crit_edge18.thread, label %.lr.ph17

._crit_edge18.thread:                             ; preds = %.preheader
  store i32 0, ptr @count, align 4, !tbaa !5
  %5 = load i32, ptr @m, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = shl nsw i64 %6, 2
  call void @llvm.memset.p0.i64(ptr nonnull align 4 getelementptr inbounds (i8, ptr @link, i64 804), i8 0, i64 %7, i1 false)
  br label %._crit_edge23

.lr.ph17:                                         ; preds = %.preheader, %._crit_edge
  %indvars.iv = phi i64 [ %indvars.iv.next, %._crit_edge ], [ 1, %.preheader ]
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %9 = getelementptr inbounds [201 x [201 x i8]], ptr @g, i64 0, i64 %indvars.iv, i64 1
  %10 = load i32, ptr @m, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  call void @llvm.memset.p0.i64(ptr nonnull align 1 %9, i8 0, i64 %11, i1 false)
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %.not1213 = icmp slt i32 %12, 1
  br i1 %.not1213, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph17, %.lr.ph
  %.014 = phi i32 [ %17, %.lr.ph ], [ 1, %.lr.ph17 ]
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2)
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [201 x [201 x i8]], ptr @g, i64 0, i64 %indvars.iv, i64 %15
  store i8 1, ptr %16, align 1, !tbaa !9
  %17 = add nuw nsw i32 %.014, 1
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %.not12.not = icmp slt i32 %.014, %18
  br i1 %.not12.not, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %.not10.not = icmp slt i64 %indvars.iv, %20
  br i1 %.not10.not, label %.lr.ph17, label %._crit_edge18, !llvm.loop !13

._crit_edge18:                                    ; preds = %._crit_edge
  store i32 0, ptr @count, align 4, !tbaa !5
  %21 = load i32, ptr @m, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = shl nsw i64 %22, 2
  call void @llvm.memset.p0.i64(ptr nonnull align 4 getelementptr inbounds (i8, ptr @link, i64 804), i8 0, i64 %23, i1 false)
  %.not1119 = icmp slt i32 %19, 1
  br i1 %.not1119, label %._crit_edge23, label %.lr.ph22

.lr.ph22:                                         ; preds = %._crit_edge18, %30
  %.120 = phi i32 [ %31, %30 ], [ 1, %._crit_edge18 ]
  %24 = load i32, ptr @m, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  call void @llvm.memset.p0.i64(ptr nonnull align 1 getelementptr inbounds (i8, ptr @y, i64 1), i8 0, i64 %25, i1 false)
  %26 = call noundef zeroext i1 @_Z4findi(i32 noundef %.120)
  br i1 %26, label %27, label %30

27:                                               ; preds = %.lr.ph22
  %28 = load i32, ptr @count, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr @count, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %.lr.ph22, %27
  %31 = add nuw nsw i32 %.120, 1
  %32 = load i32, ptr @n, align 4, !tbaa !5
  %.not11.not = icmp slt i32 %.120, %32
  br i1 %.not11.not, label %.lr.ph22, label %._crit_edge23.loopexit, !llvm.loop !14

._crit_edge23.loopexit:                           ; preds = %30
  %.pre = load i32, ptr @count, align 4, !tbaa !5
  br label %._crit_edge23

._crit_edge23:                                    ; preds = %._crit_edge18.thread, %._crit_edge23.loopexit, %._crit_edge18
  %33 = phi i32 [ %.pre, %._crit_edge23.loopexit ], [ 0, %._crit_edge18 ], [ 0, %._crit_edge18.thread ]
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %33)
  %35 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %.not = icmp eq i32 %35, -1
  br i1 %.not, label %._crit_edge25, label %.preheader, !llvm.loop !15

._crit_edge25:                                    ; preds = %._crit_edge23, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  ret i32 0
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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

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 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 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}


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