; LLVM IR from DionysiosB/CodeForces :: 0100-0199 (154D-FlatlandFencing)

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

@.str = external hidden unnamed_addr constant [17 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = load i64, ptr %2, align 8, !tbaa !5
  %12 = sub nsw i64 %10, %11
  store i64 %12, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 1, ptr %7, align 4, !tbaa !9
  %13 = load i64, ptr %4, align 8, !tbaa !5
  %14 = icmp sle i64 %13, 0
  br i1 %14, label %15, label %26

15:                                               ; preds = %0
  %16 = load i64, ptr %5, align 8, !tbaa !5
  %17 = icmp sle i64 %16, 0
  br i1 %17, label %18, label %26

18:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %19 = load i64, ptr %4, align 8, !tbaa !5
  store i64 %19, ptr %8, align 8, !tbaa !5
  %20 = load i64, ptr %5, align 8, !tbaa !5
  %21 = sub nsw i64 0, %20
  store i64 %21, ptr %4, align 8, !tbaa !5
  %22 = load i64, ptr %8, align 8, !tbaa !5
  %23 = sub nsw i64 0, %22
  store i64 %23, ptr %5, align 8, !tbaa !5
  %24 = load i64, ptr %6, align 8, !tbaa !5
  %25 = sub nsw i64 0, %24
  store i64 %25, ptr %6, align 8, !tbaa !5
  store i32 -1, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %26

26:                                               ; preds = %18, %15, %0
  %27 = load i64, ptr %4, align 8, !tbaa !5
  %28 = icmp sle i64 %27, 0
  br i1 %28, label %29, label %43

29:                                               ; preds = %26
  %30 = load i64, ptr %6, align 8, !tbaa !5
  %31 = load i64, ptr %4, align 8, !tbaa !5
  %32 = icmp slt i64 %30, %31
  br i1 %32, label %37, label %33

33:                                               ; preds = %29
  %34 = load i64, ptr %6, align 8, !tbaa !5
  %35 = load i64, ptr %5, align 8, !tbaa !5
  %36 = icmp sgt i64 %34, %35
  br i1 %36, label %37, label %39

37:                                               ; preds = %33, %29
  %38 = call i32 @puts(ptr noundef @.str.1)
  br label %42

39:                                               ; preds = %33
  %40 = load i64, ptr %3, align 8, !tbaa !5
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %40)
  br label %42

42:                                               ; preds = %39, %37
  br label %94

43:                                               ; preds = %26
  %44 = load i64, ptr %6, align 8, !tbaa !5
  %45 = icmp slt i64 %44, 0
  br i1 %45, label %46, label %48

46:                                               ; preds = %43
  %47 = call i32 @puts(ptr noundef @.str.1)
  br label %93

48:                                               ; preds = %43
  %49 = load i64, ptr %6, align 8, !tbaa !5
  %50 = load i64, ptr %4, align 8, !tbaa !5
  %51 = load i64, ptr %5, align 8, !tbaa !5
  %52 = add nsw i64 %50, %51
  %53 = srem i64 %49, %52
  %54 = icmp eq i64 %53, 0
  br i1 %54, label %55, label %57

55:                                               ; preds = %48
  %56 = call i32 @puts(ptr noundef @.str.3)
  br label %92

57:                                               ; preds = %48
  %58 = load i64, ptr %6, align 8, !tbaa !5
  %59 = load i64, ptr %4, align 8, !tbaa !5
  %60 = load i64, ptr %5, align 8, !tbaa !5
  %61 = add nsw i64 %59, %60
  %62 = srem i64 %58, %61
  %63 = load i64, ptr %4, align 8, !tbaa !5
  %64 = icmp slt i64 %62, %63
  br i1 %64, label %73, label %65

65:                                               ; preds = %57
  %66 = load i64, ptr %6, align 8, !tbaa !5
  %67 = load i64, ptr %4, align 8, !tbaa !5
  %68 = load i64, ptr %5, align 8, !tbaa !5
  %69 = add nsw i64 %67, %68
  %70 = srem i64 %66, %69
  %71 = load i64, ptr %5, align 8, !tbaa !5
  %72 = icmp sgt i64 %70, %71
  br i1 %72, label %73, label %75

73:                                               ; preds = %65, %57
  %74 = call i32 @puts(ptr noundef @.str.1)
  br label %91

75:                                               ; preds = %65
  %76 = load i64, ptr %3, align 8, !tbaa !5
  %77 = load i32, ptr %7, align 4, !tbaa !9
  %78 = sext i32 %77 to i64
  %79 = load i64, ptr %6, align 8, !tbaa !5
  %80 = load i64, ptr %4, align 8, !tbaa !5
  %81 = load i64, ptr %5, align 8, !tbaa !5
  %82 = add nsw i64 %80, %81
  %83 = sdiv i64 %79, %82
  %84 = mul nsw i64 %78, %83
  %85 = load i64, ptr %4, align 8, !tbaa !5
  %86 = load i64, ptr %5, align 8, !tbaa !5
  %87 = add nsw i64 %85, %86
  %88 = mul nsw i64 %84, %87
  %89 = sub nsw i64 %76, %88
  %90 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %89)
  br label %91

91:                                               ; preds = %75, %73
  br label %92

92:                                               ; preds = %91, %55
  br label %93

93:                                               ; preds = %92, %46
  br label %94

94:                                               ; preds = %93, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  ret i32 0
}

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

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

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

declare i32 @puts(ptr noundef) #2

declare i32 @printf(ptr noundef, ...) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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"

@.str = external hidden unnamed_addr constant [17 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %6 = load i64, ptr %2, align 8, !tbaa !5
  %7 = load i64, ptr %1, align 8, !tbaa !5
  %8 = sub nsw i64 %6, %7
  %9 = load i64, ptr %3, align 8, !tbaa !5
  %10 = icmp slt i64 %9, 1
  %11 = load i64, ptr %4, align 8
  %12 = icmp slt i64 %11, 1
  %or.cond = select i1 %10, i1 %12, i1 false
  br i1 %or.cond, label %13, label %17

13:                                               ; preds = %0
  %14 = sub nsw i64 0, %11
  store i64 %14, ptr %3, align 8, !tbaa !5
  %15 = sub nsw i64 0, %9
  store i64 %15, ptr %4, align 8, !tbaa !5
  %16 = sub nsw i64 0, %8
  br label %17

17:                                               ; preds = %13, %0
  %18 = phi i64 [ %15, %13 ], [ %11, %0 ]
  %19 = phi i64 [ %14, %13 ], [ %9, %0 ]
  %.011.neg = phi i64 [ 1, %13 ], [ -1, %0 ]
  %.0 = phi i64 [ %16, %13 ], [ %8, %0 ]
  %20 = icmp slt i64 %19, 1
  br i1 %20, label %21, label %28

21:                                               ; preds = %17
  %22 = icmp slt i64 %.0, %19
  %23 = icmp sgt i64 %.0, %18
  %or.cond18 = select i1 %22, i1 true, i1 %23
  br i1 %or.cond18, label %24, label %26

24:                                               ; preds = %21
  %25 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %47

26:                                               ; preds = %21
  %27 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %6)
  br label %47

28:                                               ; preds = %17
  %29 = icmp slt i64 %.0, 0
  br i1 %29, label %30, label %32

30:                                               ; preds = %28
  %31 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %47

32:                                               ; preds = %28
  %33 = add nsw i64 %18, %19
  %34 = srem i64 %.0, %33
  %35 = sdiv i64 %.0, %33
  %36 = icmp eq i64 %34, 0
  br i1 %36, label %37, label %39

37:                                               ; preds = %32
  %38 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %47

39:                                               ; preds = %32
  %40 = icmp ult i64 %34, %19
  %41 = icmp sgt i64 %34, %18
  %or.cond19 = or i1 %40, %41
  br i1 %or.cond19, label %42, label %44

42:                                               ; preds = %39
  %43 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %47

44:                                               ; preds = %39
  %.neg = mul nsw i64 %33, %.011.neg
  %.neg16 = mul i64 %.neg, %35
  %45 = add i64 %.neg16, %6
  %46 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %45)
  br label %47

47:                                               ; preds = %30, %42, %44, %37, %24, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  ret i32 0
}

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

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(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 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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