; LLVM IR from DionysiosB/CodeForces :: 1600-1699 (1637C-AndrewAndStones)

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

12:                                               ; preds = %74, %0
  %13 = load i64, ptr %2, align 8, !tbaa !5
  %14 = add nsw i64 %13, -1
  store i64 %14, ptr %2, align 8, !tbaa !5
  %15 = icmp ne i64 %13, 0
  br i1 %15, label %16, label %77

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  store i8 1, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  store i8 0, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %57, %16
  %19 = load i64, ptr %7, align 8, !tbaa !5
  %20 = load i64, ptr %3, align 8, !tbaa !5
  %21 = icmp slt i64 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  store i32 4, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %60

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %24 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %9)
  %25 = load i64, ptr %7, align 8, !tbaa !5
  %26 = icmp eq i64 %25, 0
  br i1 %26, label %32, label %27

27:                                               ; preds = %23
  %28 = load i64, ptr %7, align 8, !tbaa !5
  %29 = load i64, ptr %3, align 8, !tbaa !5
  %30 = sub nsw i64 %29, 1
  %31 = icmp eq i64 %28, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %27, %23
  store i32 6, ptr %8, align 4
  br label %54

33:                                               ; preds = %27
  %34 = load i64, ptr %3, align 8, !tbaa !5
  %35 = icmp eq i64 %34, 3
  br i1 %35, label %36, label %44

36:                                               ; preds = %33
  %37 = load i64, ptr %7, align 8, !tbaa !5
  %38 = icmp eq i64 %37, 1
  br i1 %38, label %39, label %44

39:                                               ; preds = %36
  %40 = load i64, ptr %9, align 8, !tbaa !11
  %41 = srem i64 %40, 2
  %42 = icmp ne i64 %41, 0
  %43 = zext i1 %42 to i8
  store i8 %43, ptr %5, align 1, !tbaa !9
  br label %44

44:                                               ; preds = %39, %36, %33
  %45 = load i64, ptr %9, align 8, !tbaa !11
  %46 = icmp sgt i64 %45, 1
  br i1 %46, label %47, label %48

47:                                               ; preds = %44
  store i8 0, ptr %4, align 1, !tbaa !9
  br label %48

48:                                               ; preds = %47, %44
  %49 = load i64, ptr %9, align 8, !tbaa !11
  %50 = add nsw i64 %49, 1
  %51 = sdiv i64 %50, 2
  %52 = load i64, ptr %6, align 8, !tbaa !11
  %53 = add nsw i64 %52, %51
  store i64 %53, ptr %6, align 8, !tbaa !11
  store i32 0, ptr %8, align 4
  br label %54

54:                                               ; preds = %48, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %55 = load i32, ptr %8, align 4
  switch i32 %55, label %79 [
    i32 0, label %56
    i32 6, label %57
  ]

56:                                               ; preds = %54
  br label %57

57:                                               ; preds = %56, %54
  %58 = load i64, ptr %7, align 8, !tbaa !5
  %59 = add nsw i64 %58, 1
  store i64 %59, ptr %7, align 8, !tbaa !5
  br label %18, !llvm.loop !13

60:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #3
  %61 = load i8, ptr %4, align 1, !tbaa !9, !range !15, !noundef !16
  %62 = trunc i8 %61 to i1
  br i1 %62, label %66, label %63

63:                                               ; preds = %60
  %64 = load i8, ptr %5, align 1, !tbaa !9, !range !15, !noundef !16
  %65 = trunc i8 %64 to i1
  br label %66

66:                                               ; preds = %63, %60
  %67 = phi i1 [ true, %60 ], [ %65, %63 ]
  %68 = zext i1 %67 to i8
  store i8 %68, ptr %10, align 1, !tbaa !9
  %69 = load i8, ptr %10, align 1, !tbaa !9, !range !15, !noundef !16
  %70 = trunc i8 %69 to i1
  br i1 %70, label %71, label %72

71:                                               ; preds = %66
  br label %74

72:                                               ; preds = %66
  %73 = load i64, ptr %6, align 8, !tbaa !11
  br label %74

74:                                               ; preds = %72, %71
  %75 = phi i64 [ -1, %71 ], [ %73, %72 ]
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %75)
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %12, !llvm.loop !17

77:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %78 = load i32, ptr %1, align 4
  ret i32 %78

79:                                               ; preds = %54
  unreachable
}

; 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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !14}


; 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 [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 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
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  %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
  %.not24 = icmp eq i64 %5, 0
  br i1 %.not24, label %._crit_edge27, label %.lr.ph26

.lr.ph26:                                         ; preds = %0, %._crit_edge
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %9 = icmp sgt i64 %8, 0
  br i1 %9, label %10, label %._crit_edge

10:                                               ; preds = %.lr.ph26
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %3)
  %.pre = load i64, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  %12 = icmp sgt i64 %.pre, 1
  br i1 %12, label %13, label %._crit_edge

13:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %3)
  %15 = load i64, ptr %2, align 8, !tbaa !5
  %16 = icmp eq i64 %15, 2
  br i1 %16, label %.thread, label %17

.thread:                                          ; preds = %13
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br label %._crit_edge

17:                                               ; preds = %13
  %18 = icmp eq i64 %15, 3
  %19 = load i64, ptr %3, align 8
  %20 = trunc i64 %19 to i1
  %.116.peel31 = select i1 %18, i1 %20, i1 false
  %21 = icmp slt i64 %19, 2
  %22 = add nsw i64 %19, 1
  %23 = sdiv i64 %22, 2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  %24 = icmp sgt i64 %15, 2
  br i1 %24, label %.lr.ph.peel.next28, label %._crit_edge

._crit_edge:                                      ; preds = %40, %10, %17, %.thread, %.lr.ph26
  %.015.lcssa = phi i1 [ false, %.lr.ph26 ], [ false, %10 ], [ %.116.peel31, %17 ], [ false, %.thread ], [ %.116.peel31, %40 ]
  %.013.lcssa = phi i64 [ 0, %.lr.ph26 ], [ 0, %10 ], [ %23, %17 ], [ 0, %.thread ], [ %.114, %40 ]
  %.0.lcssa = phi i1 [ true, %.lr.ph26 ], [ true, %10 ], [ %21, %17 ], [ true, %.thread ], [ %.2, %40 ]
  %25 = select i1 %.0.lcssa, i1 true, i1 %.015.lcssa
  %26 = select i1 %25, i64 -1, i64 %.013.lcssa
  %27 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %26)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  %28 = load i64, ptr %1, align 8, !tbaa !5
  %29 = add nsw i64 %28, -1
  store i64 %29, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %28, 0
  br i1 %.not, label %._crit_edge27, label %.lr.ph26, !llvm.loop !9

.lr.ph.peel.next28:                               ; preds = %17, %40
  %.021 = phi i1 [ %.2, %40 ], [ %21, %17 ]
  %.01220 = phi i64 [ %41, %40 ], [ 2, %17 ]
  %.01319 = phi i64 [ %.114, %40 ], [ %23, %17 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %30 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %3)
  %31 = load i64, ptr %2, align 8, !tbaa !5
  %32 = add nsw i64 %31, -1
  %33 = icmp eq i64 %.01220, %32
  br i1 %33, label %40, label %34

34:                                               ; preds = %.lr.ph.peel.next28
  %35 = load i64, ptr %3, align 8
  %36 = icmp slt i64 %35, 2
  %.1 = select i1 %36, i1 %.021, i1 false
  %37 = add nsw i64 %35, 1
  %38 = sdiv i64 %37, 2
  %39 = add nsw i64 %38, %.01319
  br label %40

40:                                               ; preds = %.lr.ph.peel.next28, %34
  %.114 = phi i64 [ %39, %34 ], [ %.01319, %.lr.ph.peel.next28 ]
  %.2 = phi i1 [ %.1, %34 ], [ %.021, %.lr.ph.peel.next28 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  %41 = add nuw nsw i64 %.01220, 1
  %42 = icmp slt i64 %41, %31
  br i1 %42, label %.lr.ph.peel.next28, label %._crit_edge, !llvm.loop !11

._crit_edge27:                                    ; preds = %._crit_edge, %0
  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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10, !12}
!12 = !{!"llvm.loop.peeled.count", i32 2}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopFullUnrollPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass