; LLVM IR from DionysiosB/CodeForces :: 1829D-GoldRush (main)

; 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 [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z3gcdxx(i64 noundef, i64 noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %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 i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  br label %9

9:                                                ; preds = %53, %0
  %10 = load i64, ptr %2, align 8, !tbaa !5
  %11 = add nsw i64 %10, -1
  store i64 %11, ptr %2, align 8, !tbaa !5
  %12 = icmp ne i64 %10, 0
  br i1 %12, label %13, label %58

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3, ptr noundef %4)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %15 = load i64, ptr %4, align 8, !tbaa !9
  %16 = load i64, ptr %3, align 8, !tbaa !9
  %17 = call noundef i64 @_Z3gcdxx(i64 noundef %15, i64 noundef %16)
  store i64 %17, ptr %5, align 8, !tbaa !9
  %18 = load i64, ptr %5, align 8, !tbaa !9
  %19 = load i64, ptr %3, align 8, !tbaa !9
  %20 = sdiv i64 %19, %18
  store i64 %20, ptr %3, align 8, !tbaa !9
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = load i64, ptr %4, align 8, !tbaa !9
  %23 = sdiv i64 %22, %21
  store i64 %23, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 0, ptr %6, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %28, %13
  %25 = load i64, ptr %3, align 8, !tbaa !9
  %26 = srem i64 %25, 3
  %27 = icmp eq i64 %26, 0
  br i1 %27, label %28, label %33

28:                                               ; preds = %24
  %29 = load i64, ptr %6, align 8, !tbaa !5
  %30 = add nsw i64 %29, 1
  store i64 %30, ptr %6, align 8, !tbaa !5
  %31 = load i64, ptr %3, align 8, !tbaa !9
  %32 = sdiv i64 %31, 3
  store i64 %32, ptr %3, align 8, !tbaa !9
  br label %24, !llvm.loop !11

33:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 0, ptr %7, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %38, %33
  %35 = load i64, ptr %4, align 8, !tbaa !9
  %36 = srem i64 %35, 2
  %37 = icmp eq i64 %36, 0
  br i1 %37, label %38, label %43

38:                                               ; preds = %34
  %39 = load i64, ptr %7, align 8, !tbaa !5
  %40 = add nsw i64 %39, 1
  store i64 %40, ptr %7, align 8, !tbaa !5
  %41 = load i64, ptr %4, align 8, !tbaa !9
  %42 = sdiv i64 %41, 2
  store i64 %42, ptr %4, align 8, !tbaa !9
  br label %34, !llvm.loop !13

43:                                               ; preds = %34
  %44 = load i64, ptr %3, align 8, !tbaa !9
  %45 = icmp eq i64 %44, 1
  br i1 %45, label %46, label %53

46:                                               ; preds = %43
  %47 = load i64, ptr %4, align 8, !tbaa !9
  %48 = icmp eq i64 %47, 1
  br i1 %48, label %49, label %53

49:                                               ; preds = %46
  %50 = load i64, ptr %7, align 8, !tbaa !5
  %51 = load i64, ptr %6, align 8, !tbaa !5
  %52 = icmp sle i64 %50, %51
  br label %53

53:                                               ; preds = %49, %46, %43
  %54 = phi i1 [ false, %46 ], [ false, %43 ], [ %52, %49 ]
  %55 = zext i1 %54 to i64
  %56 = select i1 %54, ptr @.str.2, ptr @.str.3
  %57 = call i32 @puts(ptr noundef %56)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %9, !llvm.loop !14

58:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %59 = load i32, ptr %1, align 4
  ret i32 %59
}

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

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

declare i32 @puts(ptr noundef) #3

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

attributes #0 = { mustprogress 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 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !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"

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z3gcdxx(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %5 = load i64, ptr %1, align 8, !tbaa !5
  %6 = add nsw i64 %5, -1
  store i64 %6, ptr %1, align 8, !tbaa !5
  %.not19 = icmp eq i64 %5, 0
  br i1 %.not19, label %._crit_edge22, label %.lr.ph21

.lr.ph21:                                         ; preds = %0, %29
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %8 = load i64, ptr %3, align 8, !tbaa !9
  %9 = load i64, ptr %2, align 8, !tbaa !9
  %10 = call noundef i64 @_Z3gcdxx(i64 noundef %8, i64 noundef %9)
  %11 = load i64, ptr %2, align 8, !tbaa !9
  %12 = sdiv i64 %11, %10
  store i64 %12, ptr %2, align 8, !tbaa !9
  %13 = load i64, ptr %3, align 8, !tbaa !9
  %14 = sdiv i64 %13, %10
  store i64 %14, ptr %3, align 8, !tbaa !9
  %15 = srem i64 %12, 3
  %16 = icmp eq i64 %15, 0
  br i1 %16, label %.lr.ph, label %.preheader

..preheader_crit_edge:                            ; preds = %.lr.ph
  store i64 %21, ptr %2, align 8, !tbaa !9
  br label %.preheader

.preheader:                                       ; preds = %..preheader_crit_edge, %.lr.ph21
  %.08.lcssa = phi i64 [ %20, %..preheader_crit_edge ], [ 0, %.lr.ph21 ]
  %.lcssa = phi i64 [ %21, %..preheader_crit_edge ], [ %12, %.lr.ph21 ]
  %17 = and i64 %14, 1
  %18 = icmp eq i64 %17, 0
  br i1 %18, label %.lr.ph15, label %29

.lr.ph:                                           ; preds = %.lr.ph21, %.lr.ph
  %.0810 = phi i64 [ %20, %.lr.ph ], [ 0, %.lr.ph21 ]
  %19 = phi i64 [ %21, %.lr.ph ], [ %12, %.lr.ph21 ]
  %20 = add nuw nsw i64 %.0810, 1
  %21 = sdiv i64 %19, 3
  %22 = srem i64 %21, 3
  %23 = icmp eq i64 %22, 0
  br i1 %23, label %.lr.ph, label %..preheader_crit_edge, !llvm.loop !11

.lr.ph15:                                         ; preds = %.preheader, %.lr.ph15
  %.014 = phi i64 [ %25, %.lr.ph15 ], [ 0, %.preheader ]
  %24 = phi i64 [ %26, %.lr.ph15 ], [ %14, %.preheader ]
  %25 = add nuw nsw i64 %.014, 1
  %26 = ashr exact i64 %24, 1
  %27 = and i64 %24, 2
  %28 = icmp eq i64 %27, 0
  br i1 %28, label %.lr.ph15, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph15
  store i64 %26, ptr %3, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %._crit_edge, %.preheader
  %.0.lcssa = phi i64 [ %25, %._crit_edge ], [ 0, %.preheader ]
  %.lcssa9 = phi i64 [ %26, %._crit_edge ], [ %14, %.preheader ]
  %30 = icmp eq i64 %.lcssa, 1
  %31 = icmp eq i64 %.lcssa9, 1
  %or.cond = and i1 %30, %31
  %32 = icmp ule i64 %.0.lcssa, %.08.lcssa
  %spec.select = select i1 %or.cond, i1 %32, i1 false
  %33 = select i1 %spec.select, ptr @.str.2, ptr @.str.3
  %34 = call i32 @puts(ptr noundef nonnull dereferenceable(1) %33)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  %35 = load i64, ptr %1, align 8, !tbaa !5
  %36 = add nsw i64 %35, -1
  store i64 %36, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %35, 0
  br i1 %.not, label %._crit_edge22, label %.lr.ph21, !llvm.loop !14

._crit_edge22:                                    ; preds = %29, %0
  call void @llvm.lifetime.end.p0(i64 8, 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) #2

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #3

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

attributes #0 = { mustprogress 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 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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