; LLVM IR from DionysiosB/CodeForces :: 0900-0999 (946B-WeirdSubtractionProcess)

; 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 [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 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
  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
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %3)
  br label %7

7:                                                ; preds = %89, %0
  br label %8

8:                                                ; preds = %7
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = mul nsw i64 2, %10
  %12 = icmp sge i64 %9, %11
  br i1 %12, label %13, label %36

13:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = load i64, ptr %3, align 8, !tbaa !5
  %16 = sub nsw i64 %14, %15
  %17 = load i64, ptr %3, align 8, !tbaa !5
  %18 = mul nsw i64 2, %17
  %19 = sdiv i64 %16, %18
  store i64 %19, ptr %4, align 8, !tbaa !5
  %20 = load i64, ptr %4, align 8, !tbaa !5
  %21 = mul nsw i64 %20, 2
  %22 = load i64, ptr %3, align 8, !tbaa !5
  %23 = mul nsw i64 %21, %22
  %24 = load i64, ptr %2, align 8, !tbaa !5
  %25 = sub nsw i64 %24, %23
  store i64 %25, ptr %2, align 8, !tbaa !5
  %26 = load i64, ptr %2, align 8, !tbaa !5
  %27 = load i64, ptr %3, align 8, !tbaa !5
  %28 = mul nsw i64 2, %27
  %29 = icmp sge i64 %26, %28
  br i1 %29, label %30, label %35

30:                                               ; preds = %13
  %31 = load i64, ptr %3, align 8, !tbaa !5
  %32 = mul nsw i64 2, %31
  %33 = load i64, ptr %2, align 8, !tbaa !5
  %34 = sub nsw i64 %33, %32
  store i64 %34, ptr %2, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %30, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %36

36:                                               ; preds = %35, %8
  %37 = load i64, ptr %2, align 8, !tbaa !5
  %38 = icmp sle i64 %37, 0
  br i1 %38, label %42, label %39

39:                                               ; preds = %36
  %40 = load i64, ptr %3, align 8, !tbaa !5
  %41 = icmp sle i64 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %39, %36
  br label %90

43:                                               ; preds = %39
  %44 = load i64, ptr %3, align 8, !tbaa !5
  %45 = load i64, ptr %2, align 8, !tbaa !5
  %46 = mul nsw i64 2, %45
  %47 = icmp sge i64 %44, %46
  br i1 %47, label %48, label %71

48:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %49 = load i64, ptr %3, align 8, !tbaa !5
  %50 = load i64, ptr %2, align 8, !tbaa !5
  %51 = sub nsw i64 %49, %50
  %52 = load i64, ptr %2, align 8, !tbaa !5
  %53 = mul nsw i64 2, %52
  %54 = sdiv i64 %51, %53
  store i64 %54, ptr %5, align 8, !tbaa !5
  %55 = load i64, ptr %5, align 8, !tbaa !5
  %56 = mul nsw i64 %55, 2
  %57 = load i64, ptr %2, align 8, !tbaa !5
  %58 = mul nsw i64 %56, %57
  %59 = load i64, ptr %3, align 8, !tbaa !5
  %60 = sub nsw i64 %59, %58
  store i64 %60, ptr %3, align 8, !tbaa !5
  %61 = load i64, ptr %3, align 8, !tbaa !5
  %62 = load i64, ptr %2, align 8, !tbaa !5
  %63 = mul nsw i64 2, %62
  %64 = icmp sge i64 %61, %63
  br i1 %64, label %65, label %70

65:                                               ; preds = %48
  %66 = load i64, ptr %2, align 8, !tbaa !5
  %67 = mul nsw i64 2, %66
  %68 = load i64, ptr %3, align 8, !tbaa !5
  %69 = sub nsw i64 %68, %67
  store i64 %69, ptr %3, align 8, !tbaa !5
  br label %70

70:                                               ; preds = %65, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %71

71:                                               ; preds = %70, %43
  %72 = load i64, ptr %2, align 8, !tbaa !5
  %73 = icmp sle i64 %72, 0
  br i1 %73, label %77, label %74

74:                                               ; preds = %71
  %75 = load i64, ptr %3, align 8, !tbaa !5
  %76 = icmp sle i64 %75, 0
  br i1 %76, label %77, label %78

77:                                               ; preds = %74, %71
  br label %90

78:                                               ; preds = %74
  %79 = load i64, ptr %2, align 8, !tbaa !5
  %80 = load i64, ptr %3, align 8, !tbaa !5
  %81 = mul nsw i64 2, %80
  %82 = icmp slt i64 %79, %81
  br i1 %82, label %83, label %89

83:                                               ; preds = %78
  %84 = load i64, ptr %3, align 8, !tbaa !5
  %85 = load i64, ptr %2, align 8, !tbaa !5
  %86 = mul nsw i64 2, %85
  %87 = icmp slt i64 %84, %86
  br i1 %87, label %88, label %89

88:                                               ; preds = %83
  br label %90

89:                                               ; preds = %83, %78
  br label %7, !llvm.loop !9

90:                                               ; preds = %88, %77, %42
  %91 = load i64, ptr %2, align 8, !tbaa !5
  %92 = load i64, ptr %3, align 8, !tbaa !5
  %93 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %91, i64 noundef %92)
  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 @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 long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; 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 [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 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
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %.promoted = load i64, ptr %1, align 8, !tbaa !5
  %.promoted20 = load i64, ptr %2, align 8
  br label %4

4:                                                ; preds = %thread-pre-split.thread, %0
  %.pr22 = phi i64 [ %.pr2126, %thread-pre-split.thread ], [ %.promoted20, %0 ]
  %5 = phi i64 [ %14, %thread-pre-split.thread ], [ %.promoted, %0 ]
  %6 = shl i64 %.pr22, 1
  %.not = icmp slt i64 %5, %6
  br i1 %.not, label %13, label %7

7:                                                ; preds = %4
  %8 = sub nsw i64 %5, %.pr22
  %.fr = freeze i64 %8
  %9 = srem i64 %.fr, %6
  %.neg = sub i64 %9, %.fr
  %10 = add i64 %.neg, %5
  store i64 %10, ptr %1, align 8, !tbaa !5
  %.not15 = icmp slt i64 %10, %6
  br i1 %.not15, label %13, label %11

11:                                               ; preds = %7
  %12 = sub nsw i64 %10, %6
  store i64 %12, ptr %1, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %7, %11, %4
  %14 = phi i64 [ %10, %7 ], [ %12, %11 ], [ %5, %4 ]
  %15 = icmp slt i64 %14, 1
  %16 = icmp slt i64 %.pr22, 1
  %or.cond = or i1 %16, %15
  br i1 %or.cond, label %27, label %17

17:                                               ; preds = %13
  %18 = shl nuw i64 %14, 1
  %.not16 = icmp slt i64 %.pr22, %18
  br i1 %.not16, label %thread-pre-split.thread, label %thread-pre-split

thread-pre-split:                                 ; preds = %17
  %19 = sub nsw i64 %.pr22, %14
  %.fr23 = freeze i64 %19
  %20 = srem i64 %.fr23, %18
  %.neg24 = sub i64 %20, %.fr23
  %21 = add i64 %.neg24, %.pr22
  %.not17 = icmp slt i64 %21, %18
  %22 = select i1 %.not17, i64 0, i64 %18
  %spec.select = sub nsw i64 %21, %22
  store i64 %spec.select, ptr %2, align 8, !tbaa !5
  %23 = icmp slt i64 %spec.select, 1
  br i1 %23, label %27, label %thread-pre-split.thread

thread-pre-split.thread:                          ; preds = %17, %thread-pre-split
  %.pr2126 = phi i64 [ %spec.select, %thread-pre-split ], [ %.pr22, %17 ]
  %24 = shl nuw nsw i64 %.pr2126, 1
  %25 = icmp slt i64 %14, %24
  %26 = icmp slt i64 %.pr2126, %18
  %or.cond19 = and i1 %26, %25
  br i1 %or.cond19, label %27, label %4, !llvm.loop !9

27:                                               ; preds = %thread-pre-split.thread, %thread-pre-split, %13
  %28 = phi i64 [ %.pr2126, %thread-pre-split.thread ], [ %spec.select, %thread-pre-split ], [ %.pr22, %13 ]
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %14, i64 noundef %28)
  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 @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 long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass