; LLVM IR from tangjz/acm-icpc :: codeforces/gym (100685I)

; 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
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@flag = external dso_local global i8, align 1
@.str = external hidden unnamed_addr constant [9 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
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m, ptr noundef @a, ptr noundef @b)
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = load i32, ptr @a, align 4, !tbaa !5
  %11 = sdiv i32 %9, %10
  %12 = load i32, ptr @m, align 4, !tbaa !5
  %13 = load i32, ptr @b, align 4, !tbaa !5
  %14 = sdiv i32 %12, %13
  %15 = mul nsw i32 %11, %14
  store i32 %15, ptr @ans, align 4, !tbaa !5
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = load i32, ptr @a, align 4, !tbaa !5
  %18 = srem i32 %16, %17
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %44

20:                                               ; preds = %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %21 = load i32, ptr @m, align 4, !tbaa !5
  %22 = load i32, ptr @b, align 4, !tbaa !5
  %23 = sdiv i32 %21, %22
  store i32 %23, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %24 = load i32, ptr @a, align 4, !tbaa !5
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = load i32, ptr @a, align 4, !tbaa !5
  %27 = srem i32 %25, %26
  %28 = sdiv i32 %24, %27
  store i32 %28, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sub nsw i32 %29, 1
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = sdiv i32 %30, %31
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %4, align 4, !tbaa !5
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = mul nsw i32 %35, %36
  %38 = icmp slt i32 %34, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %20
  store i8 1, ptr @flag, align 1, !tbaa !9
  br label %40

40:                                               ; preds = %39, %20
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = load i32, ptr @ans, align 4, !tbaa !5
  %43 = add nsw i32 %42, %41
  store i32 %43, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %44

44:                                               ; preds = %40, %0
  %45 = load i32, ptr @m, align 4, !tbaa !5
  %46 = load i32, ptr @b, align 4, !tbaa !5
  %47 = srem i32 %45, %46
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %73

49:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %50 = load i32, ptr @n, align 4, !tbaa !5
  %51 = load i32, ptr @a, align 4, !tbaa !5
  %52 = sdiv i32 %50, %51
  store i32 %52, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %53 = load i32, ptr @b, align 4, !tbaa !5
  %54 = load i32, ptr @m, align 4, !tbaa !5
  %55 = load i32, ptr @b, align 4, !tbaa !5
  %56 = srem i32 %54, %55
  %57 = sdiv i32 %53, %56
  store i32 %57, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = sub nsw i32 %58, 1
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = sdiv i32 %59, %60
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %7, align 4, !tbaa !5
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = load i32, ptr %7, align 4, !tbaa !5
  %65 = load i32, ptr %6, align 4, !tbaa !5
  %66 = mul nsw i32 %64, %65
  %67 = icmp slt i32 %63, %66
  br i1 %67, label %68, label %69

68:                                               ; preds = %49
  store i8 1, ptr @flag, align 1, !tbaa !9
  br label %69

69:                                               ; preds = %68, %49
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = load i32, ptr @ans, align 4, !tbaa !5
  %72 = add nsw i32 %71, %70
  store i32 %72, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %73

73:                                               ; preds = %69, %44
  %74 = load i32, ptr @n, align 4, !tbaa !5
  %75 = load i32, ptr @a, align 4, !tbaa !5
  %76 = srem i32 %74, %75
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %78, label %89

78:                                               ; preds = %73
  %79 = load i32, ptr @m, align 4, !tbaa !5
  %80 = load i32, ptr @b, align 4, !tbaa !5
  %81 = srem i32 %79, %80
  %82 = icmp ne i32 %81, 0
  br i1 %82, label %83, label %89

83:                                               ; preds = %78
  %84 = load i8, ptr @flag, align 1, !tbaa !9, !range !11, !noundef !12
  %85 = trunc i8 %84 to i1
  br i1 %85, label %89, label %86

86:                                               ; preds = %83
  %87 = load i32, ptr @ans, align 4, !tbaa !5
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr @ans, align 4, !tbaa !5
  br label %89

89:                                               ; preds = %86, %83, %78, %73
  %90 = load i32, ptr @ans, align 4, !tbaa !5
  %91 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %90)
  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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!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
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@flag = external dso_local local_unnamed_addr global i8, align 1
@.str = external hidden unnamed_addr constant [9 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 @n, ptr noundef nonnull @m, ptr noundef nonnull @a, ptr noundef nonnull @b)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = load i32, ptr @a, align 4, !tbaa !5
  %4 = sdiv i32 %2, %3
  %5 = load i32, ptr @m, align 4, !tbaa !5
  %6 = load i32, ptr @b, align 4, !tbaa !5
  %7 = sdiv i32 %5, %6
  %8 = srem i32 %5, %6
  %9 = mul nsw i32 %7, %4
  store i32 %9, ptr @ans, align 4, !tbaa !5
  %10 = srem i32 %2, %3
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %19, label %11

11:                                               ; preds = %0
  %12 = sdiv i32 %3, %10
  %13 = add nsw i32 %7, -1
  %14 = sdiv i32 %13, %12
  %15 = add nsw i32 %14, 1
  %16 = mul nsw i32 %15, %12
  %17 = icmp slt i32 %7, %16
  br i1 %17, label %18, label %.thread17

18:                                               ; preds = %11
  store i8 1, ptr @flag, align 1, !tbaa !9
  br label %.thread17

19:                                               ; preds = %0
  %20 = srem i32 %5, %6
  %.not13 = icmp eq i32 %20, 0
  br i1 %.not13, label %.thread19, label %22

.thread17:                                        ; preds = %11, %18
  %21 = add nsw i32 %15, %9
  store i32 %21, ptr @ans, align 4, !tbaa !5
  %.not1318 = icmp eq i32 %8, 0
  br i1 %.not1318, label %.thread19, label %22

22:                                               ; preds = %.thread17, %19
  %23 = phi i32 [ %21, %.thread17 ], [ %9, %19 ]
  %24 = phi i32 [ %8, %.thread17 ], [ %20, %19 ]
  %25 = sdiv i32 %6, %24
  %26 = add nsw i32 %4, -1
  %27 = sdiv i32 %26, %25
  %28 = add nsw i32 %27, 1
  %29 = mul nsw i32 %28, %25
  %30 = icmp slt i32 %4, %29
  br i1 %30, label %31, label %.thread

31:                                               ; preds = %22
  store i8 1, ptr @flag, align 1, !tbaa !9
  br label %.thread

.thread:                                          ; preds = %22, %31
  %32 = add nsw i32 %23, %28
  store i32 %32, ptr @ans, align 4, !tbaa !5
  br i1 %.not, label %.thread19, label %33

33:                                               ; preds = %.thread
  %34 = load i8, ptr @flag, align 1, !tbaa !9, !range !11, !noundef !12
  %35 = trunc nuw i8 %34 to i1
  br i1 %35, label %.thread19, label %36

36:                                               ; preds = %33
  %37 = add nsw i32 %32, 1
  store i32 %37, ptr @ans, align 4, !tbaa !5
  br label %.thread19

.thread19:                                        ; preds = %.thread17, %19, %.thread, %36, %33
  %38 = phi i32 [ %21, %.thread17 ], [ %9, %19 ], [ %32, %.thread ], [ %37, %36 ], [ %32, %33 ]
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %38)
  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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}


; Effective O3 passes: DivRemPairsPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass