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

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

@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@f = external dso_local global [52 x i32], align 16
@idx = external dso_local global [49 x i32], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = 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
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @a, ptr noundef @b, ptr noundef @n)
  store i32 1, ptr getelementptr inbounds ([52 x i32], ptr @f, i64 0, i64 2), align 8, !tbaa !5
  store i32 1, ptr getelementptr inbounds ([52 x i32], ptr @f, i64 0, i64 1), align 4, !tbaa !5
  %7 = load i32, ptr getelementptr inbounds ([52 x i32], ptr @f, i64 0, i64 1), align 4, !tbaa !5
  %8 = mul nsw i32 %7, 7
  %9 = load i32, ptr getelementptr inbounds ([52 x i32], ptr @f, i64 0, i64 2), align 8, !tbaa !5
  %10 = add nsw i32 %8, %9
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [49 x i32], ptr @idx, i64 0, i64 %11
  store i32 2, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 3, ptr %2, align 4, !tbaa !5
  br label %13

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

16:                                               ; preds = %13
  store i32 2, ptr %3, align 4
  br label %121

17:                                               ; preds = %13
  %18 = load i32, ptr @a, align 4, !tbaa !5
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sub nsw i32 %19, 1
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [52 x i32], ptr @f, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = mul nsw i32 %18, %23
  %25 = load i32, ptr @b, align 4, !tbaa !5
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = sub nsw i32 %26, 2
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [52 x i32], ptr @f, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = mul nsw i32 %25, %30
  %32 = add nsw i32 %24, %31
  %33 = srem i32 %32, 7
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [52 x i32], ptr @f, i64 0, i64 %35
  store i32 %33, ptr %36, align 4, !tbaa !5
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [52 x i32], ptr @f, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = icmp slt i32 %40, 0
  br i1 %41, label %42, label %48

42:                                               ; preds = %17
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [52 x i32], ptr @f, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = add nsw i32 %46, 7
  store i32 %47, ptr %45, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %42, %17
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = load i32, ptr @n, align 4, !tbaa !5
  %51 = icmp eq i32 %49, %50
  br i1 %51, label %52, label %58

52:                                               ; preds = %48
  %53 = load i32, ptr %2, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [52 x i32], ptr @f, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %56)
  store i32 2, ptr %3, align 4
  br label %121

58:                                               ; preds = %48
  %59 = load i32, ptr %2, align 4, !tbaa !5
  %60 = sub nsw i32 %59, 1
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [52 x i32], ptr @f, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = mul nsw i32 %63, 7
  %65 = load i32, ptr %2, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [52 x i32], ptr @f, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = add nsw i32 %64, %68
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [49 x i32], ptr @idx, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %74, label %103

74:                                               ; preds = %58
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %75 = load i32, ptr %2, align 4, !tbaa !5
  %76 = sub nsw i32 %75, 1
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [52 x i32], ptr @f, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = mul nsw i32 %79, 7
  %81 = load i32, ptr %2, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [52 x i32], ptr @f, i64 0, i64 %82
  %84 = load i32, ptr %83, align 4, !tbaa !5
  %85 = add nsw i32 %80, %84
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [49 x i32], ptr @idx, i64 0, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !5
  store i32 %88, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %89 = load i32, ptr %2, align 4, !tbaa !5
  %90 = load i32, ptr %4, align 4, !tbaa !5
  %91 = sub nsw i32 %89, %90
  store i32 %91, ptr %5, align 4, !tbaa !5
  %92 = load i32, ptr @n, align 4, !tbaa !5
  %93 = load i32, ptr %4, align 4, !tbaa !5
  %94 = sub nsw i32 %92, %93
  %95 = load i32, ptr %5, align 4, !tbaa !5
  %96 = srem i32 %94, %95
  %97 = load i32, ptr %4, align 4, !tbaa !5
  %98 = add nsw i32 %96, %97
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [52 x i32], ptr @f, i64 0, i64 %99
  %101 = load i32, ptr %100, align 4, !tbaa !5
  %102 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %101)
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %121

103:                                              ; preds = %58
  %104 = load i32, ptr %2, align 4, !tbaa !5
  %105 = load i32, ptr %2, align 4, !tbaa !5
  %106 = sub nsw i32 %105, 1
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds [52 x i32], ptr @f, i64 0, i64 %107
  %109 = load i32, ptr %108, align 4, !tbaa !5
  %110 = mul nsw i32 %109, 7
  %111 = load i32, ptr %2, align 4, !tbaa !5
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds [52 x i32], ptr @f, i64 0, i64 %112
  %114 = load i32, ptr %113, align 4, !tbaa !5
  %115 = add nsw i32 %110, %114
  %116 = sext i32 %115 to i64
  %117 = getelementptr inbounds [49 x i32], ptr @idx, i64 0, i64 %116
  store i32 %104, ptr %117, align 4, !tbaa !5
  br label %118

118:                                              ; preds = %103
  %119 = load i32, ptr %2, align 4, !tbaa !5
  %120 = add nsw i32 %119, 1
  store i32 %120, ptr %2, align 4, !tbaa !5
  br label %13, !llvm.loop !9

121:                                              ; preds = %74, %52, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %122

122:                                              ; preds = %121
  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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { "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 = { 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"}


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

@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@f = external dso_local local_unnamed_addr global [52 x i32], align 16
@idx = external dso_local local_unnamed_addr global [49 x i32], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 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 @a, ptr noundef nonnull @b, ptr noundef nonnull @n)
  store i32 1, ptr getelementptr inbounds (i8, ptr @f, i64 8), align 8, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @f, i64 4), align 4, !tbaa !5
  store i32 2, ptr getelementptr inbounds (i8, ptr @idx, i64 32), align 16, !tbaa !5
  %2 = load i32, ptr @a, align 4, !tbaa !5
  %3 = load i32, ptr @b, align 4, !tbaa !5
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = zext i32 %4 to i64
  br label %6

6:                                                ; preds = %0, %34
  %7 = phi i32 [ 1, %0 ], [ %spec.select, %34 ]
  %indvars.iv = phi i64 [ 3, %0 ], [ %indvars.iv.next, %34 ]
  %8 = mul nsw i32 %7, %2
  %9 = add nsw i64 %indvars.iv, -2
  %10 = getelementptr inbounds [52 x i32], ptr @f, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = mul nsw i32 %11, %3
  %13 = add nsw i32 %12, %8
  %14 = srem i32 %13, 7
  %15 = getelementptr inbounds [52 x i32], ptr @f, i64 0, i64 %indvars.iv
  %16 = icmp slt i32 %14, 0
  %17 = add nsw i32 %14, 7
  %spec.select = select i1 %16, i32 %17, i32 %14
  store i32 %spec.select, ptr %15, align 4, !tbaa !5
  %18 = icmp eq i64 %indvars.iv, %5
  br i1 %18, label %.loopexit.sink.split, label %19

19:                                               ; preds = %6
  %20 = mul nsw i32 %7, 7
  %21 = add nsw i32 %spec.select, %20
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [49 x i32], ptr @idx, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %.not = icmp eq i32 %24, 0
  %25 = trunc nuw nsw i64 %indvars.iv to i32
  br i1 %.not, label %34, label %26

26:                                               ; preds = %19
  %27 = sub nsw i32 %25, %24
  %28 = sub nsw i32 %4, %24
  %29 = srem i32 %28, %27
  %30 = add nsw i32 %29, %24
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [52 x i32], ptr @f, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  br label %.loopexit.sink.split

34:                                               ; preds = %19
  store i32 %25, ptr %23, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 52
  br i1 %exitcond.not, label %.loopexit, label %6, !llvm.loop !9

.loopexit.sink.split:                             ; preds = %6, %26
  %.sink = phi i32 [ %33, %26 ], [ %spec.select, %6 ]
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.sink)
  br label %.loopexit

.loopexit:                                        ; preds = %34, %.loopexit.sink.split
  ret i32 0
}

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

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

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


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