; LLVM IR from DionysiosB/CodeForces :: 0500-0599 (544B-SeaAndIslands)

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

16:                                               ; preds = %0
  %17 = call i32 @puts(ptr noundef @.str.1)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %68

18:                                               ; preds = %0
  %19 = call i32 @puts(ptr noundef @.str.2)
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  store i8 0, ptr %6, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %64, %18
  %21 = load i64, ptr %7, align 8, !tbaa !5
  %22 = load i64, ptr %2, align 8, !tbaa !5
  %23 = load i64, ptr %2, align 8, !tbaa !5
  %24 = mul nsw i64 %22, %23
  %25 = icmp slt i64 %21, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %20
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %67

27:                                               ; preds = %20
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = load i64, ptr %3, align 8, !tbaa !5
  %30 = icmp slt i64 %28, %29
  br i1 %30, label %31, label %42

31:                                               ; preds = %27
  %32 = load i64, ptr %7, align 8, !tbaa !5
  %33 = srem i64 %32, 2
  %34 = load i8, ptr %6, align 1, !tbaa !9, !range !11, !noundef !12
  %35 = trunc i8 %34 to i1
  %36 = zext i1 %35 to i64
  %37 = icmp eq i64 %33, %36
  br i1 %37, label %38, label %42

38:                                               ; preds = %31
  %39 = load i64, ptr %4, align 8, !tbaa !5
  %40 = add nsw i64 %39, 1
  store i64 %40, ptr %4, align 8, !tbaa !5
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %44

42:                                               ; preds = %31, %27
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  br label %44

44:                                               ; preds = %42, %38
  %45 = load i64, ptr %7, align 8, !tbaa !5
  %46 = add nsw i64 %45, 1
  %47 = load i64, ptr %2, align 8, !tbaa !5
  %48 = srem i64 %46, %47
  %49 = icmp eq i64 %48, 0
  br i1 %49, label %50, label %63

50:                                               ; preds = %44
  %51 = load i64, ptr %2, align 8, !tbaa !5
  %52 = srem i64 %51, 2
  %53 = icmp ne i64 %52, 0
  br i1 %53, label %61, label %54

54:                                               ; preds = %50
  %55 = load i8, ptr %6, align 1, !tbaa !9, !range !11, !noundef !12
  %56 = trunc i8 %55 to i1
  %57 = zext i1 %56 to i32
  %58 = sub nsw i32 1, %57
  %59 = icmp ne i32 %58, 0
  %60 = zext i1 %59 to i8
  store i8 %60, ptr %6, align 1, !tbaa !9
  br label %61

61:                                               ; preds = %54, %50
  %62 = call i32 @puts(ptr noundef @.str.5)
  br label %63

63:                                               ; preds = %61, %44
  br label %64

64:                                               ; preds = %63
  %65 = load i64, ptr %7, align 8, !tbaa !5
  %66 = add nsw i64 %65, 1
  store i64 %66, ptr %7, align 8, !tbaa !5
  br label %20, !llvm.loop !13

67:                                               ; preds = %26
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  br label %68

68:                                               ; preds = %67, %16
  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
  %69 = load i32, ptr %1, align 4
  ret i32 %69
}

; 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 @puts(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

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 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"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 [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [1 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)
  %4 = load i64, ptr %2, align 8, !tbaa !5
  %5 = load i64, ptr %1, align 8, !tbaa !5
  %6 = mul nsw i64 %5, %5
  %7 = add nuw nsw i64 %6, 1
  %8 = lshr i64 %7, 1
  %9 = icmp sgt i64 %4, %8
  br i1 %9, label %10, label %12

10:                                               ; preds = %0
  %11 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %.loopexit

12:                                               ; preds = %0
  %13 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  %14 = load i64, ptr %1, align 8, !tbaa !5
  %.not17 = icmp eq i64 %14, 0
  br i1 %.not17, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %12, %34
  %.015 = phi i64 [ %25, %34 ], [ 0, %12 ]
  %.0914 = phi i8 [ %.2, %34 ], [ 0, %12 ]
  %.01013 = phi i64 [ %.111, %34 ], [ 0, %12 ]
  %15 = load i64, ptr %2, align 8, !tbaa !5
  %16 = icmp slt i64 %.01013, %15
  br i1 %16, label %17, label %23

17:                                               ; preds = %.lr.ph
  %18 = and i64 %.015, 1
  %19 = and i8 %.0914, 1
  %20 = zext nneg i8 %19 to i64
  %21 = icmp eq i64 %18, %20
  %spec.select = select i1 %21, ptr @.str.3, ptr @.str.4
  %22 = zext i1 %21 to i64
  %spec.select18 = add nsw i64 %.01013, %22
  br label %23

23:                                               ; preds = %17, %.lr.ph
  %.str.4.sink = phi ptr [ @.str.4, %.lr.ph ], [ %spec.select, %17 ]
  %.111 = phi i64 [ %.01013, %.lr.ph ], [ %spec.select18, %17 ]
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.4.sink)
  %25 = add nuw nsw i64 %.015, 1
  %26 = load i64, ptr %1, align 8, !tbaa !5
  %27 = srem i64 %25, %26
  %28 = icmp eq i64 %27, 0
  br i1 %28, label %29, label %34

29:                                               ; preds = %23
  %30 = trunc i64 %26 to i8
  %31 = and i8 %30, 1
  %32 = xor i8 %31, %.0914
  %.1 = xor i8 %32, 1
  %33 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.5)
  %.pre = load i64, ptr %1, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %23, %29
  %35 = phi i64 [ %.pre, %29 ], [ %26, %23 ]
  %.2 = phi i8 [ %.1, %29 ], [ %.0914, %23 ]
  %36 = mul nsw i64 %35, %35
  %37 = icmp ult i64 %25, %36
  br i1 %37, label %.lr.ph, label %.loopexit, !llvm.loop !9

.loopexit:                                        ; preds = %34, %12, %10
  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: 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

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

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


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass