; LLVM IR from DionysiosB/CodeForces :: 1600-1699 (1661B-GettingZero)

; 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 [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 i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  store i64 15, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 32768, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %4)
  br label %13

13:                                               ; preds = %58, %0
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = add nsw i64 %14, -1
  store i64 %15, ptr %4, align 8, !tbaa !5
  %16 = icmp ne i64 %14, 0
  br i1 %16, label %17, label %61

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 100, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %6)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %55, %17
  %20 = load i64, ptr %7, align 8, !tbaa !5
  %21 = icmp sle i64 %20, 15
  br i1 %21, label %23, label %22

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

23:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %24 = load i64, ptr %6, align 8, !tbaa !5
  %25 = load i64, ptr %7, align 8, !tbaa !5
  %26 = add nsw i64 %24, %25
  store i64 %26, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %51, %23
  %28 = load i64, ptr %10, align 8, !tbaa !5
  %29 = icmp sle i64 %28, 15
  br i1 %29, label %31, label %30

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

31:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %32 = load i64, ptr %7, align 8, !tbaa !5
  %33 = load i64, ptr %10, align 8, !tbaa !5
  %34 = add nsw i64 %32, %33
  store i64 %34, ptr %11, align 8, !tbaa !5
  %35 = load i64, ptr %9, align 8, !tbaa !5
  %36 = srem i64 %35, 32768
  %37 = icmp eq i64 %36, 0
  br i1 %37, label %38, label %48

38:                                               ; preds = %31
  %39 = load i64, ptr %5, align 8, !tbaa !5
  %40 = load i64, ptr %11, align 8, !tbaa !5
  %41 = icmp slt i64 %39, %40
  br i1 %41, label %42, label %44

42:                                               ; preds = %38
  %43 = load i64, ptr %5, align 8, !tbaa !5
  br label %46

44:                                               ; preds = %38
  %45 = load i64, ptr %11, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %44, %42
  %47 = phi i64 [ %43, %42 ], [ %45, %44 ]
  store i64 %47, ptr %5, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %46, %31
  %49 = load i64, ptr %9, align 8, !tbaa !5
  %50 = mul nsw i64 %49, 2
  store i64 %50, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %51

51:                                               ; preds = %48
  %52 = load i64, ptr %10, align 8, !tbaa !5
  %53 = add nsw i64 %52, 1
  store i64 %53, ptr %10, align 8, !tbaa !5
  br label %27, !llvm.loop !9

54:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %55

55:                                               ; preds = %54
  %56 = load i64, ptr %7, align 8, !tbaa !5
  %57 = add nsw i64 %56, 1
  store i64 %57, ptr %7, align 8, !tbaa !5
  br label %19, !llvm.loop !11

58:                                               ; preds = %22
  %59 = load i64, ptr %5, align 8, !tbaa !5
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %59)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %13, !llvm.loop !12

61:                                               ; preds = %13
  %62 = call i32 @puts(ptr noundef @.str.2)
  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
  %63 = load i32, ptr %1, align 4
  ret i32 %63
}

; 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

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 }

!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 = distinct !{!12, !10}


; 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 [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) #4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %4 = load i64, ptr %1, align 8, !tbaa !5
  %5 = add nsw i64 %4, -1
  store i64 %5, ptr %1, align 8, !tbaa !5
  %.not23 = icmp eq i64 %4, 0
  br i1 %.not23, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %7 = load i64, ptr %2, align 8, !tbaa !5
  br label %12

8:                                                ; preds = %12
  %9 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %74)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  %10 = load i64, ptr %1, align 8, !tbaa !5
  %11 = add nsw i64 %10, -1
  store i64 %11, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %10, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

12:                                               ; preds = %.lr.ph, %12
  %.022 = phi i64 [ 100, %.lr.ph ], [ %74, %12 ]
  %.01721 = phi i64 [ 0, %.lr.ph ], [ %19, %12 ]
  %13 = add nsw i64 %7, %.01721
  %14 = and i64 %13, 32767
  %15 = icmp eq i64 %14, 0
  %16 = call i64 @llvm.smin.i64(i64 %.022, i64 %.01721)
  %.2 = select i1 %15, i64 %16, i64 %.022
  %17 = and i64 %13, 16383
  %18 = icmp eq i64 %17, 0
  %19 = add nuw nsw i64 %.01721, 1
  %20 = call i64 @llvm.smin.i64(i64 %.2, i64 %19)
  %.2.1 = select i1 %18, i64 %20, i64 %.2
  %21 = and i64 %13, 8191
  %22 = icmp eq i64 %21, 0
  %23 = add nuw nsw i64 %.01721, 2
  %24 = call i64 @llvm.smin.i64(i64 %.2.1, i64 %23)
  %.2.2 = select i1 %22, i64 %24, i64 %.2.1
  %25 = and i64 %13, 4095
  %26 = icmp eq i64 %25, 0
  %27 = add nuw nsw i64 %.01721, 3
  %28 = call i64 @llvm.smin.i64(i64 %.2.2, i64 %27)
  %.2.3 = select i1 %26, i64 %28, i64 %.2.2
  %29 = and i64 %13, 2047
  %30 = icmp eq i64 %29, 0
  %31 = add nuw nsw i64 %.01721, 4
  %32 = call i64 @llvm.smin.i64(i64 %.2.3, i64 %31)
  %.2.4 = select i1 %30, i64 %32, i64 %.2.3
  %33 = and i64 %13, 1023
  %34 = icmp eq i64 %33, 0
  %35 = add nuw nsw i64 %.01721, 5
  %36 = call i64 @llvm.smin.i64(i64 %.2.4, i64 %35)
  %.2.5 = select i1 %34, i64 %36, i64 %.2.4
  %37 = and i64 %13, 511
  %38 = icmp eq i64 %37, 0
  %39 = add nuw nsw i64 %.01721, 6
  %40 = call i64 @llvm.smin.i64(i64 %.2.5, i64 %39)
  %.2.6 = select i1 %38, i64 %40, i64 %.2.5
  %41 = and i64 %13, 255
  %42 = icmp eq i64 %41, 0
  %43 = add nuw nsw i64 %.01721, 7
  %44 = call i64 @llvm.smin.i64(i64 %.2.6, i64 %43)
  %.2.7 = select i1 %42, i64 %44, i64 %.2.6
  %45 = and i64 %13, 127
  %46 = icmp eq i64 %45, 0
  %47 = add nuw nsw i64 %.01721, 8
  %48 = call i64 @llvm.smin.i64(i64 %.2.7, i64 %47)
  %.2.8 = select i1 %46, i64 %48, i64 %.2.7
  %49 = and i64 %13, 63
  %50 = icmp eq i64 %49, 0
  %51 = add nuw nsw i64 %.01721, 9
  %52 = call i64 @llvm.smin.i64(i64 %.2.8, i64 %51)
  %.2.9 = select i1 %50, i64 %52, i64 %.2.8
  %53 = and i64 %13, 31
  %54 = icmp eq i64 %53, 0
  %55 = add nuw nsw i64 %.01721, 10
  %56 = call i64 @llvm.smin.i64(i64 %.2.9, i64 %55)
  %.2.10 = select i1 %54, i64 %56, i64 %.2.9
  %57 = and i64 %13, 15
  %58 = icmp eq i64 %57, 0
  %59 = add nuw nsw i64 %.01721, 11
  %60 = call i64 @llvm.smin.i64(i64 %.2.10, i64 %59)
  %.2.11 = select i1 %58, i64 %60, i64 %.2.10
  %61 = and i64 %13, 7
  %62 = icmp eq i64 %61, 0
  %63 = add nuw nsw i64 %.01721, 12
  %64 = call i64 @llvm.smin.i64(i64 %.2.11, i64 %63)
  %.2.12 = select i1 %62, i64 %64, i64 %.2.11
  %65 = and i64 %13, 3
  %66 = icmp eq i64 %65, 0
  %67 = add nuw nsw i64 %.01721, 13
  %68 = call i64 @llvm.smin.i64(i64 %.2.12, i64 %67)
  %.2.13 = select i1 %66, i64 %68, i64 %.2.12
  %69 = and i64 %13, 1
  %70 = icmp eq i64 %69, 0
  %71 = add nuw nsw i64 %.01721, 14
  %72 = call i64 @llvm.smin.i64(i64 %.2.13, i64 %71)
  %.2.14 = select i1 %70, i64 %72, i64 %.2.13
  %73 = add nuw nsw i64 %.01721, 15
  %74 = call i64 @llvm.smin.i64(i64 %.2.14, i64 %73)
  %exitcond.not = icmp eq i64 %19, 16
  br i1 %exitcond.not, label %8, label %12, !llvm.loop !11

._crit_edge:                                      ; preds = %8, %0
  %75 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  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) #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

; 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 i64 @llvm.smin.i64(i64, i64) #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 = !{!"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}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopDeletionPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass