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

; 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
@cnt = external dso_local global i32, align 4
@s = external dso_local global [10 x i32], align 16
@c = external dso_local global [10 x i32], align 16
@ans = 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 [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsiii(i32 noundef, i32 noundef, 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
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  %5 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %5, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 2, ptr %3, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %44, %0
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = sdiv i32 %8, %9
  %11 = icmp sle i32 %7, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %47

13:                                               ; preds = %6
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = srem i32 %14, %15
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %43

18:                                               ; preds = %13
  %19 = load i32, ptr @cnt, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [10 x i32], ptr @c, i64 0, i64 %20
  store i32 0, ptr %21, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %28, %18
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = srem i32 %23, %24
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %37

27:                                               ; preds = %22
  br label %28

28:                                               ; preds = %27
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sdiv i32 %30, %29
  store i32 %31, ptr %2, align 4, !tbaa !5
  %32 = load i32, ptr @cnt, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [10 x i32], ptr @c, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %34, align 4, !tbaa !5
  br label %22, !llvm.loop !9

37:                                               ; preds = %22
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = load i32, ptr @cnt, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr @cnt, align 4, !tbaa !5
  %41 = sext i32 %39 to i64
  %42 = getelementptr inbounds [10 x i32], ptr @s, i64 0, i64 %41
  store i32 %38, ptr %42, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %37, %13
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %3, align 4, !tbaa !5
  br label %6, !llvm.loop !11

47:                                               ; preds = %12
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = icmp sgt i32 %48, 1
  br i1 %49, label %50, label %59

50:                                               ; preds = %47
  %51 = load i32, ptr @cnt, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [10 x i32], ptr @c, i64 0, i64 %52
  store i32 1, ptr %53, align 4, !tbaa !5
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = load i32, ptr @cnt, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr @cnt, align 4, !tbaa !5
  %57 = sext i32 %55 to i64
  %58 = getelementptr inbounds [10 x i32], ptr @s, i64 0, i64 %57
  store i32 %54, ptr %58, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %50, %47
  store i64 0, ptr @ans, align 8, !tbaa !12
  call void @_Z3dfsiii(i32 noundef 0, i32 noundef 1, i32 noundef 1)
  %60 = load i64, ptr @ans, align 8, !tbaa !12
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %60)
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

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

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 = { 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}


; 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
@cnt = external dso_local local_unnamed_addr global i32, align 4
@s = external dso_local local_unnamed_addr global [10 x i32], align 16
@c = external dso_local local_unnamed_addr global [10 x i32], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %cnt.promoted = load i32, ptr @cnt, align 4, !tbaa !5
  %.not17 = icmp slt i32 %2, 4
  br i1 %.not17, label %._crit_edge22, label %.lr.ph21

._crit_edge22:                                    ; preds = %16, %0
  %3 = phi i32 [ %cnt.promoted, %0 ], [ %17, %16 ]
  %.013.lcssa = phi i32 [ %2, %0 ], [ %.2, %16 ]
  %4 = icmp sgt i32 %.013.lcssa, 1
  br i1 %4, label %20, label %25

.lr.ph21:                                         ; preds = %0, %16
  %.019 = phi i32 [ %18, %16 ], [ 2, %0 ]
  %.01318 = phi i32 [ %.2, %16 ], [ %2, %0 ]
  %5 = phi i32 [ %17, %16 ], [ %cnt.promoted, %0 ]
  %6 = srem i32 %.01318, %.019
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %.lr.ph.preheader, label %16

.lr.ph.preheader:                                 ; preds = %.lr.ph21
  %8 = sext i32 %5 to i64
  %9 = getelementptr inbounds [10 x i32], ptr @c, i64 0, i64 %8
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.115 = phi i32 [ %10, %.lr.ph ], [ %.01318, %.lr.ph.preheader ]
  %storemerge14 = phi i32 [ %11, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %10 = sdiv i32 %.115, %.019
  %11 = add nuw nsw i32 %storemerge14, 1
  %12 = srem i32 %10, %.019
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph
  store i32 %11, ptr %9, align 4, !tbaa !5
  %14 = add nsw i32 %5, 1
  store i32 %14, ptr @cnt, align 4, !tbaa !5
  %15 = getelementptr inbounds [10 x i32], ptr @s, i64 0, i64 %8
  store i32 %.019, ptr %15, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %.lr.ph21, %._crit_edge
  %17 = phi i32 [ %14, %._crit_edge ], [ %5, %.lr.ph21 ]
  %.2 = phi i32 [ %10, %._crit_edge ], [ %.01318, %.lr.ph21 ]
  %18 = add nuw nsw i32 %.019, 1
  %19 = sdiv i32 %.2, %18
  %.not.not = icmp slt i32 %.019, %19
  br i1 %.not.not, label %.lr.ph21, label %._crit_edge22, !llvm.loop !11

20:                                               ; preds = %._crit_edge22
  %21 = sext i32 %3 to i64
  %22 = getelementptr inbounds [10 x i32], ptr @c, i64 0, i64 %21
  store i32 1, ptr %22, align 4, !tbaa !5
  %23 = add nsw i32 %3, 1
  store i32 %23, ptr @cnt, align 4, !tbaa !5
  %24 = getelementptr inbounds [10 x i32], ptr @s, i64 0, i64 %21
  store i32 %.013.lcssa, ptr %24, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %20, %._crit_edge22
  store i64 0, ptr @ans, align 8, !tbaa !12
  tail call void @_Z3dfsiii(i32 noundef 0, i32 noundef 1, i32 noundef 1)
  %26 = load i64, ptr @ans, align 8, !tbaa !12
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %26)
  ret i32 0
}

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

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

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 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 #2 = { 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"}
!11 = distinct !{!11, !10}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}


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