; LLVM IR from tangjz/acm-icpc :: lydsy (3834)

; 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
@sL = external dso_local global i32, align 4
@sR = external dso_local global i32, align 4
@wL = external dso_local global i32, align 4
@wR = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = 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
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  br label %6

6:                                                ; preds = %80, %0
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = add nsw i32 %7, -1
  store i32 %8, ptr @n, align 4, !tbaa !5
  %9 = icmp ne i32 %7, 0
  br i1 %9, label %10, label %83

10:                                               ; preds = %6
  store i32 1, ptr @ans, align 4, !tbaa !5
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @sL, ptr noundef @sR, ptr noundef @wL, ptr noundef @wR)
  %12 = load i32, ptr @sL, align 4, !tbaa !5
  %13 = add nsw i32 %12, -1
  store i32 %13, ptr @sL, align 4, !tbaa !5
  %14 = load i32, ptr @wL, align 4, !tbaa !5
  %15 = add nsw i32 %14, -1
  store i32 %15, ptr @wL, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %16 = load i32, ptr @sR, align 4, !tbaa !5
  %17 = load i32, ptr @wR, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %21

19:                                               ; preds = %10
  %20 = load i32, ptr @sR, align 4, !tbaa !5
  br label %23

21:                                               ; preds = %10
  %22 = load i32, ptr @wR, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %21, %19
  %24 = phi i32 [ %20, %19 ], [ %22, %21 ]
  store i32 %24, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  br label %25

25:                                               ; preds = %77, %23
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %29, label %28

28:                                               ; preds = %25
  store i32 4, ptr %4, align 4
  br label %79

29:                                               ; preds = %25
  %30 = load i32, ptr @sL, align 4, !tbaa !5
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sdiv i32 %30, %31
  %33 = load i32, ptr @sR, align 4, !tbaa !5
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = sdiv i32 %33, %34
  %36 = icmp slt i32 %32, %35
  br i1 %36, label %37, label %47

37:                                               ; preds = %29
  %38 = load i32, ptr @wL, align 4, !tbaa !5
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = sdiv i32 %38, %39
  %41 = load i32, ptr @wR, align 4, !tbaa !5
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = sdiv i32 %41, %42
  %44 = icmp slt i32 %40, %43
  br i1 %44, label %45, label %47

45:                                               ; preds = %37
  %46 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %46, ptr @ans, align 4, !tbaa !5
  store i32 4, ptr %4, align 4
  br label %79

47:                                               ; preds = %37, %29
  %48 = load i32, ptr @sR, align 4, !tbaa !5
  %49 = load i32, ptr @sR, align 4, !tbaa !5
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = sdiv i32 %49, %50
  %52 = add nsw i32 %51, 1
  %53 = sdiv i32 %48, %52
  %54 = load i32, ptr @wR, align 4, !tbaa !5
  %55 = load i32, ptr @wR, align 4, !tbaa !5
  %56 = load i32, ptr %2, align 4, !tbaa !5
  %57 = sdiv i32 %55, %56
  %58 = add nsw i32 %57, 1
  %59 = sdiv i32 %54, %58
  %60 = icmp sgt i32 %53, %59
  br i1 %60, label %61, label %68

61:                                               ; preds = %47
  %62 = load i32, ptr @sR, align 4, !tbaa !5
  %63 = load i32, ptr @sR, align 4, !tbaa !5
  %64 = load i32, ptr %2, align 4, !tbaa !5
  %65 = sdiv i32 %63, %64
  %66 = add nsw i32 %65, 1
  %67 = sdiv i32 %62, %66
  br label %75

68:                                               ; preds = %47
  %69 = load i32, ptr @wR, align 4, !tbaa !5
  %70 = load i32, ptr @wR, align 4, !tbaa !5
  %71 = load i32, ptr %2, align 4, !tbaa !5
  %72 = sdiv i32 %70, %71
  %73 = add nsw i32 %72, 1
  %74 = sdiv i32 %69, %73
  br label %75

75:                                               ; preds = %68, %61
  %76 = phi i32 [ %67, %61 ], [ %74, %68 ]
  store i32 %76, ptr %3, align 4, !tbaa !5
  br label %77

77:                                               ; preds = %75
  %78 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %78, ptr %2, align 4, !tbaa !5
  br label %25, !llvm.loop !9

79:                                               ; preds = %45, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr @ans, align 4, !tbaa !5
  %82 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %81)
  br label %6, !llvm.loop !11

83:                                               ; preds = %6
  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 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 = { 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}


; 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
@sL = external dso_local global i32, align 4
@sR = external dso_local global i32, align 4
@wL = external dso_local global i32, align 4
@wR = external dso_local global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = 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 @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @n, align 4, !tbaa !5
  %.not17 = icmp eq i32 %2, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph18

.lr.ph18:                                         ; preds = %0, %.loopexit
  store i32 1, ptr @ans, align 4, !tbaa !5
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @sL, ptr noundef nonnull @sR, ptr noundef nonnull @wL, ptr noundef nonnull @wR)
  %5 = load i32, ptr @sL, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr @sL, align 4, !tbaa !5
  %7 = load i32, ptr @wL, align 4, !tbaa !5
  %8 = add nsw i32 %7, -1
  store i32 %8, ptr @wL, align 4, !tbaa !5
  %9 = load i32, ptr @sR, align 4
  %10 = load i32, ptr @wR, align 4
  %11 = tail call i32 @llvm.smin.i32(i32 %9, i32 %10)
  %.not1315 = icmp eq i32 %11, 0
  br i1 %.not1315, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph18, %20
  %.016 = phi i32 [ %., %20 ], [ %11, %.lr.ph18 ]
  %12 = sdiv i32 %6, %.016
  %13 = sdiv i32 %9, %.016
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %15, label %.lr.ph._crit_edge

.lr.ph._crit_edge:                                ; preds = %.lr.ph
  %.pre = sdiv i32 %10, %.016
  br label %20

15:                                               ; preds = %.lr.ph
  %16 = sdiv i32 %8, %.016
  %17 = sdiv i32 %10, %.016
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %15
  store i32 %.016, ptr @ans, align 4, !tbaa !5
  br label %.loopexit

20:                                               ; preds = %.lr.ph._crit_edge, %15
  %.pre-phi = phi i32 [ %.pre, %.lr.ph._crit_edge ], [ %17, %15 ]
  %21 = add nsw i32 %13, 1
  %22 = sdiv i32 %9, %21
  %23 = add nsw i32 %.pre-phi, 1
  %24 = sdiv i32 %10, %23
  %. = tail call i32 @llvm.smax.i32(i32 %22, i32 %24)
  %.not13 = icmp eq i32 %., 0
  br i1 %.not13, label %.loopexit, label %.lr.ph, !llvm.loop !9

.loopexit:                                        ; preds = %20, %.lr.ph18, %19
  %25 = load i32, ptr @ans, align 4, !tbaa !5
  %26 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %25)
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %28 = add nsw i32 %27, -1
  store i32 %28, ptr @n, align 4, !tbaa !5
  %.not = icmp eq i32 %27, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph18, !llvm.loop !11

._crit_edge:                                      ; preds = %.loopexit, %0
  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

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

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

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

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


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