; LLVM IR from DionysiosB/CodeForces :: 0400-0499 (459A-PashmakAndGarden)

; 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 [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 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
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca double, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5)
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = icmp eq i32 %12, %13
  br i1 %14, label %15, label %38

15:                                               ; preds = %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = icmp sgt i32 %16, %17
  br i1 %18, label %19, label %23

19:                                               ; preds = %15
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sub nsw i32 %20, %21
  br label %27

23:                                               ; preds = %15
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sub nsw i32 %24, %25
  br label %27

27:                                               ; preds = %23, %19
  %28 = phi i32 [ %22, %19 ], [ %26, %23 ]
  store i32 %28, ptr %6, align 4, !tbaa !5
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = add nsw i32 %29, %30
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = add nsw i32 %33, %34
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %31, i32 noundef %32, i32 noundef %35, i32 noundef %36)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %117

38:                                               ; preds = %0
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = icmp eq i32 %39, %40
  br i1 %41, label %42, label %65

42:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = icmp sgt i32 %43, %44
  br i1 %45, label %46, label %50

46:                                               ; preds = %42
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = sub nsw i32 %47, %48
  br label %54

50:                                               ; preds = %42
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = load i32, ptr %2, align 4, !tbaa !5
  %53 = sub nsw i32 %51, %52
  br label %54

54:                                               ; preds = %50, %46
  %55 = phi i32 [ %49, %46 ], [ %53, %50 ]
  store i32 %55, ptr %7, align 4, !tbaa !5
  %56 = load i32, ptr %2, align 4, !tbaa !5
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = load i32, ptr %7, align 4, !tbaa !5
  %59 = add nsw i32 %57, %58
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = add nsw i32 %61, %62
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %56, i32 noundef %59, i32 noundef %60, i32 noundef %63)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %116

65:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = load i32, ptr %2, align 4, !tbaa !5
  %68 = sub nsw i32 %66, %67
  %69 = load i32, ptr %4, align 4, !tbaa !5
  %70 = load i32, ptr %2, align 4, !tbaa !5
  %71 = sub nsw i32 %69, %70
  %72 = mul nsw i32 %68, %71
  %73 = load i32, ptr %5, align 4, !tbaa !5
  %74 = load i32, ptr %3, align 4, !tbaa !5
  %75 = sub nsw i32 %73, %74
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = load i32, ptr %3, align 4, !tbaa !5
  %78 = sub nsw i32 %76, %77
  %79 = mul nsw i32 %75, %78
  %80 = add nsw i32 %72, %79
  %81 = sext i32 %80 to i64
  store i64 %81, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %82 = load i64, ptr %8, align 8, !tbaa !9
  %83 = sdiv i64 %82, 2
  %84 = sitofp i64 %83 to double
  %85 = call double @sqrt(double noundef %84) #4
  %86 = fptosi double %85 to i64
  store i64 %86, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %87 = load i32, ptr %5, align 4, !tbaa !5
  %88 = load i32, ptr %3, align 4, !tbaa !5
  %89 = sub nsw i32 %87, %88
  %90 = load i32, ptr %4, align 4, !tbaa !5
  %91 = load i32, ptr %2, align 4, !tbaa !5
  %92 = sub nsw i32 %90, %91
  %93 = sdiv i32 %89, %92
  %94 = sitofp i32 %93 to double
  store double %94, ptr %10, align 8, !tbaa !11
  %95 = load double, ptr %10, align 8, !tbaa !11
  %96 = fcmp une double %95, 1.000000e+00
  br i1 %96, label %97, label %100

97:                                               ; preds = %65
  %98 = load double, ptr %10, align 8, !tbaa !11
  %99 = fcmp une double %98, -1.000000e+00
  br i1 %99, label %107, label %100

100:                                              ; preds = %97, %65
  %101 = load i64, ptr %9, align 8, !tbaa !9
  %102 = mul nsw i64 2, %101
  %103 = load i64, ptr %9, align 8, !tbaa !9
  %104 = mul nsw i64 %102, %103
  %105 = load i64, ptr %8, align 8, !tbaa !9
  %106 = icmp ne i64 %104, %105
  br i1 %106, label %107, label %109

107:                                              ; preds = %100, %97
  %108 = call i32 @puts(ptr noundef @.str.1)
  br label %115

109:                                              ; preds = %100
  %110 = load i32, ptr %2, align 4, !tbaa !5
  %111 = load i32, ptr %5, align 4, !tbaa !5
  %112 = load i32, ptr %4, align 4, !tbaa !5
  %113 = load i32, ptr %3, align 4, !tbaa !5
  %114 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %110, i32 noundef %111, i32 noundef %112, i32 noundef %113)
  br label %115

115:                                              ; preds = %109, %107
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %116

116:                                              ; preds = %115, %54
  br label %117

117:                                              ; preds = %116, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  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

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

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

; Function Attrs: nounwind
declare double @sqrt(double noundef) #3

declare i32 @puts(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 "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 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !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 [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  %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 i32, ptr %1, align 4, !tbaa !5
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = icmp eq i32 %6, %7
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  br i1 %8, label %11, label %16

11:                                               ; preds = %0
  %12 = sub nsw i32 %9, %10
  %13 = call i32 @llvm.abs.i32(i32 %12, i1 true)
  %14 = add nsw i32 %13, %6
  %15 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %14, i32 noundef %9, i32 noundef %14, i32 noundef %10)
  br label %41

16:                                               ; preds = %0
  %17 = icmp eq i32 %9, %10
  br i1 %17, label %18, label %23

18:                                               ; preds = %16
  %19 = sub nsw i32 %6, %7
  %20 = call i32 @llvm.abs.i32(i32 %19, i1 true)
  %21 = add nsw i32 %9, %20
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %6, i32 noundef %21, i32 noundef %7, i32 noundef %21)
  br label %41

23:                                               ; preds = %16
  %24 = sub nsw i32 %10, %9
  %25 = sub nsw i32 %7, %6
  %26 = sdiv i32 %24, %25
  switch i32 %26, label %37 [
    i32 -1, label %27
    i32 1, label %27
  ]

27:                                               ; preds = %23, %23
  %28 = mul nsw i32 %24, %24
  %29 = mul nsw i32 %25, %25
  %30 = add nuw nsw i32 %28, %29
  %31 = zext nneg i32 %30 to i64
  %32 = lshr i64 %31, 1
  %33 = uitofp nneg i64 %32 to double
  %sqrt = call double @llvm.sqrt.f64(double %33)
  %34 = fptosi double %sqrt to i64
  %35 = shl nsw i64 %34, 1
  %36 = mul nsw i64 %35, %34
  %.not = icmp eq i64 %36, %31
  br i1 %.not, label %39, label %37

37:                                               ; preds = %23, %27
  %38 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %41

39:                                               ; preds = %27
  %40 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %6, i32 noundef %10, i32 noundef %7, i32 noundef %9)
  br label %41

41:                                               ; preds = %37, %39, %18, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  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: nofree nounwind
declare noundef i32 @printf(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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.sqrt.f64(double) #3

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


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass