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

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

@t = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@mod = external dso_local global i32, align 4
@seq = external dso_local global [10010 x i32], align 16
@pos = external dso_local global [10010 x i32], align 16
@n = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 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
  store i32 0, ptr %1, align 4
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %103, %0
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr @t, align 4, !tbaa !5
  %11 = icmp sle i32 %9, %10
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @x, ptr noundef @n, ptr noundef @mod, ptr noundef @c)
  %15 = load i32, ptr @mod, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = mul i64 %16, 4
  call void @llvm.memset.p0.i64(ptr align 16 @pos, i8 0, i64 %17, i1 false)
  %18 = load i32, ptr @mod, align 4, !tbaa !5
  %19 = load i32, ptr @x, align 4, !tbaa !5
  %20 = srem i32 %19, %18
  store i32 %20, ptr @x, align 4, !tbaa !5
  store i32 %20, ptr getelementptr inbounds ([10010 x i32], ptr @seq, i64 0, i64 1), align 4, !tbaa !5
  %21 = load i32, ptr getelementptr inbounds ([10010 x i32], ptr @seq, i64 0, i64 1), align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [10010 x i32], ptr @pos, i64 0, i64 %22
  store i32 1, ptr %23, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 2, ptr %6, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %69, %13
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = load i32, ptr @mod, align 4, !tbaa !5
  %27 = icmp sle i32 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  store i32 5, ptr %3, align 4
  br label %72

29:                                               ; preds = %24
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = sub nsw i32 %30, 1
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [10010 x i32], ptr @seq, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = mul nsw i32 %34, 10
  %36 = load i32, ptr @x, align 4, !tbaa !5
  %37 = add nsw i32 %35, %36
  %38 = load i32, ptr @mod, align 4, !tbaa !5
  %39 = srem i32 %37, %38
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [10010 x i32], ptr @seq, i64 0, i64 %41
  store i32 %39, ptr %42, align 4, !tbaa !5
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [10010 x i32], ptr @seq, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [10010 x i32], ptr @pos, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %59, label %51

51:                                               ; preds = %29
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [10010 x i32], ptr @seq, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [10010 x i32], ptr @pos, i64 0, i64 %57
  store i32 %52, ptr %58, align 4, !tbaa !5
  br label %68

59:                                               ; preds = %29
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [10010 x i32], ptr @seq, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [10010 x i32], ptr @pos, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  store i32 %66, ptr %4, align 4, !tbaa !5
  %67 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %67, ptr %5, align 4, !tbaa !5
  store i32 5, ptr %3, align 4
  br label %72

68:                                               ; preds = %51
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %6, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %6, align 4, !tbaa !5
  br label %24, !llvm.loop !9

72:                                               ; preds = %59, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %2, align 4, !tbaa !5
  %75 = load i64, ptr @n, align 8, !tbaa !11
  %76 = load i32, ptr %4, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = icmp slt i64 %75, %77
  br i1 %78, label %79, label %81

79:                                               ; preds = %73
  %80 = load i64, ptr @n, align 8, !tbaa !11
  br label %94

81:                                               ; preds = %73
  %82 = load i64, ptr @n, align 8, !tbaa !11
  %83 = load i32, ptr %4, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = sub nsw i64 %82, %84
  %86 = load i32, ptr %5, align 4, !tbaa !5
  %87 = load i32, ptr %4, align 4, !tbaa !5
  %88 = sub nsw i32 %86, %87
  %89 = sext i32 %88 to i64
  %90 = srem i64 %85, %89
  %91 = load i32, ptr %4, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = add nsw i64 %90, %92
  br label %94

94:                                               ; preds = %81, %79
  %95 = phi i64 [ %80, %79 ], [ %93, %81 ]
  %96 = getelementptr inbounds [10010 x i32], ptr @seq, i64 0, i64 %95
  %97 = load i32, ptr %96, align 4, !tbaa !5
  %98 = load i32, ptr @c, align 4, !tbaa !5
  %99 = icmp eq i32 %97, %98
  %100 = zext i1 %99 to i64
  %101 = select i1 %99, ptr @.str.3, ptr @.str.4
  %102 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %74, ptr noundef %101)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %103

103:                                              ; preds = %94
  %104 = load i32, ptr %2, align 4, !tbaa !5
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !13

106:                                              ; preds = %12
  ret i32 0
}

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

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

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

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

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

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


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

@t = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@mod = external dso_local global i32, align 4
@seq = external dso_local local_unnamed_addr global [10010 x i32], align 16
@pos = external dso_local local_unnamed_addr global [10010 x i32], align 16
@n = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %.not34 = icmp slt i32 %2, 1
  br i1 %.not34, label %._crit_edge40, label %.lr.ph39

._crit_edge40:                                    ; preds = %31, %0
  ret i32 0

.lr.ph39:                                         ; preds = %0, %31
  %.01737 = phi i32 [ %.1, %31 ], [ undef, %0 ]
  %.01836 = phi i32 [ %.119, %31 ], [ undef, %0 ]
  %.02035 = phi i32 [ %39, %31 ], [ 1, %0 ]
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @x, ptr noundef nonnull @n, ptr noundef nonnull @mod, ptr noundef nonnull @c)
  %4 = load i32, ptr @mod, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = shl nsw i64 %5, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 16 @pos, i8 0, i64 %6, i1 false)
  %7 = load i32, ptr @x, align 4, !tbaa !5
  %8 = srem i32 %7, %4
  store i32 %8, ptr @x, align 4, !tbaa !5
  store i32 %8, ptr getelementptr inbounds (i8, ptr @seq, i64 4), align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [10010 x i32], ptr @pos, i64 0, i64 %9
  store i32 1, ptr %10, align 4, !tbaa !5
  %.not2628 = icmp slt i32 %4, 2
  br i1 %.not2628, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.lr.ph39
  %11 = add nuw i32 %4, 1
  %wide.trip.count = zext i32 %11 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %21
  %12 = phi i32 [ %8, %.lr.ph.preheader ], [ %15, %21 ]
  %indvars.iv = phi i64 [ 2, %.lr.ph.preheader ], [ %indvars.iv.next, %21 ]
  %13 = mul nsw i32 %12, 10
  %14 = add nsw i32 %13, %8
  %15 = srem i32 %14, %4
  %16 = getelementptr inbounds [10010 x i32], ptr @seq, i64 0, i64 %indvars.iv
  store i32 %15, ptr %16, align 4, !tbaa !5
  %17 = sext i32 %15 to i64
  %18 = getelementptr inbounds [10010 x i32], ptr @pos, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %.not27 = icmp eq i32 %19, 0
  %20 = trunc nuw nsw i64 %indvars.iv to i32
  br i1 %.not27, label %21, label %._crit_edge

21:                                               ; preds = %.lr.ph
  store i32 %20, ptr %18, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %21, %.lr.ph, %.lr.ph39
  %.119 = phi i32 [ %.01836, %.lr.ph39 ], [ %19, %.lr.ph ], [ %.01836, %21 ]
  %.1 = phi i32 [ %.01737, %.lr.ph39 ], [ %20, %.lr.ph ], [ %.01737, %21 ]
  %22 = load i64, ptr @n, align 8, !tbaa !11
  %23 = sext i32 %.119 to i64
  %24 = icmp slt i64 %22, %23
  br i1 %24, label %31, label %25

25:                                               ; preds = %._crit_edge
  %26 = sub nsw i64 %22, %23
  %27 = sub nsw i32 %.1, %.119
  %28 = sext i32 %27 to i64
  %29 = srem i64 %26, %28
  %30 = add nsw i64 %29, %23
  br label %31

31:                                               ; preds = %._crit_edge, %25
  %32 = phi i64 [ %30, %25 ], [ %22, %._crit_edge ]
  %33 = getelementptr inbounds [10010 x i32], ptr @seq, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = load i32, ptr @c, align 4, !tbaa !5
  %36 = icmp eq i32 %34, %35
  %37 = select i1 %36, ptr @.str.3, ptr @.str.4
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.02035, ptr noundef nonnull %37)
  %39 = add nuw nsw i32 %.02035, 1
  %40 = load i32, ptr @t, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.02035, %40
  br i1 %.not.not, label %.lr.ph39, label %._crit_edge40, !llvm.loop !13
}

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

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

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

attributes #0 = { mustprogress nofree 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 nounwind willreturn memory(argmem: write) }

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


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