; LLVM IR from tangjz/acm-icpc :: codeforces/complete/1552H.ll (Z5solvev)

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

%class.anon = type { i8 }

@_ZZ5solvevE1f = external hidden global [201 x i32], align 16
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@stdout = external global ptr, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca %class.anon, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #6
  store i32 200, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 7, ptr %2, align 4, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 16 @_ZZ5solvevE1f, i8 -1, i64 804, i1 false)
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #6
  %8 = call noundef i32 @"_ZZ5solvevENK3$_0clEi"(ptr noundef nonnull align 1 dereferenceable(1) %3, i32 noundef 1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 7, ptr %5, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %31, %0
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %13, label %32

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = add nsw i32 %14, %15
  %17 = add nsw i32 %16, 1
  %18 = ashr i32 %17, 1
  store i32 %18, ptr %6, align 4, !tbaa !5
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = shl i32 1, %19
  %21 = call noundef i32 @"_ZZ5solvevENK3$_0clEi"(ptr noundef nonnull align 1 dereferenceable(1) %3, i32 noundef %20)
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = shl i32 %21, %22
  %24 = call noundef i32 @"_ZZ5solvevENK3$_0clEi"(ptr noundef nonnull align 1 dereferenceable(1) %3, i32 noundef 1)
  %25 = icmp eq i32 %23, %24
  br i1 %25, label %26, label %28

26:                                               ; preds = %13
  %27 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %27, ptr %4, align 4, !tbaa !5
  br label %31

28:                                               ; preds = %13
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = sub nsw i32 %29, 1
  store i32 %30, ptr %5, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %28, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %9, !llvm.loop !9

32:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = shl i32 2, %33
  %35 = call noundef i32 @"_ZZ5solvevENK3$_0clEi"(ptr noundef nonnull align 1 dereferenceable(1) %3, i32 noundef %34)
  %36 = shl i32 %35, 1
  %37 = call noundef i32 @"_ZZ5solvevENK3$_0clEi"(ptr noundef nonnull align 1 dereferenceable(1) %3, i32 noundef 1)
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = ashr i32 %37, %38
  %40 = sub nsw i32 %36, %39
  %41 = call i32 @llvm.abs.i32(i32 %40, i1 true)
  store i32 %41, ptr %7, align 4, !tbaa !5
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = call noundef i32 @"_ZZ5solvevENK3$_0clEi"(ptr noundef nonnull align 1 dereferenceable(1) %3, i32 noundef 1)
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = sdiv i32 %43, %44
  %46 = add nsw i32 %42, %45
  %47 = sub nsw i32 %46, 2
  %48 = shl i32 %47, 1
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %48)
  %50 = load ptr, ptr @stdout, align 8, !tbaa !11
  %51 = call i32 @fflush(ptr noundef %50)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #6
  ret void
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef i32 @"_ZZ5solvevENK3$_0clEi"(ptr noundef nonnull align 1 dereferenceable(1), i32 noundef) #3 align 2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #4

declare i32 @printf(ptr noundef, ...) #5

declare i32 @fflush(ptr noundef) #5

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { inlinehint 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { "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 #6 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}


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

%class.anon = type { i8 }

@_ZZ5solvevE1f = external hidden local_unnamed_addr global [201 x i32], align 16
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() local_unnamed_addr #0 {
  %1 = alloca %class.anon, align 1
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(804) @_ZZ5solvevE1f, i8 -1, i64 804, i1 false)
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %1) #6
  %2 = call noundef i32 @"_ZZ5solvevENK3$_0clEi"(ptr noundef nonnull align 1 dereferenceable(1) %1, i32 noundef 1)
  br label %3

3:                                                ; preds = %0, %3
  %.015 = phi i32 [ 0, %0 ], [ %.1, %3 ]
  %.01214 = phi i32 [ 7, %0 ], [ %.113, %3 ]
  %4 = add i32 %.01214, 1
  %5 = add i32 %4, %.015
  %6 = ashr i32 %5, 1
  %7 = shl nuw i32 1, %6
  %8 = call noundef i32 @"_ZZ5solvevENK3$_0clEi"(ptr noundef nonnull align 1 dereferenceable(1) %1, i32 noundef %7)
  %9 = shl i32 %8, %6
  %10 = call noundef i32 @"_ZZ5solvevENK3$_0clEi"(ptr noundef nonnull align 1 dereferenceable(1) %1, i32 noundef 1)
  %11 = icmp eq i32 %9, %10
  %12 = add nsw i32 %6, -1
  %.113 = select i1 %11, i32 %.01214, i32 %12
  %.1 = select i1 %11, i32 %6, i32 %.015
  %13 = icmp slt i32 %.1, %.113
  br i1 %13, label %3, label %14, !llvm.loop !5

14:                                               ; preds = %3
  %15 = shl i32 2, %.1
  %16 = call noundef i32 @"_ZZ5solvevENK3$_0clEi"(ptr noundef nonnull align 1 dereferenceable(1) %1, i32 noundef %15)
  %17 = shl i32 %16, 1
  %18 = call noundef i32 @"_ZZ5solvevENK3$_0clEi"(ptr noundef nonnull align 1 dereferenceable(1) %1, i32 noundef 1)
  %19 = ashr i32 %18, %.1
  %20 = sub nsw i32 %17, %19
  %21 = call i32 @llvm.abs.i32(i32 %20, i1 true)
  %22 = call noundef i32 @"_ZZ5solvevENK3$_0clEi"(ptr noundef nonnull align 1 dereferenceable(1) %1, i32 noundef 1)
  %23 = sdiv i32 %22, %21
  %24 = add nsw i32 %21, %23
  %25 = shl i32 %24, 1
  %26 = add i32 %25, -4
  %27 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %26)
  %28 = load ptr, ptr @stdout, align 8, !tbaa !7
  %29 = call i32 @fflush(ptr noundef %28)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %1) #6
  ret void
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef i32 @"_ZZ5solvevENK3$_0clEi"(ptr noundef nonnull align 1 dereferenceable(1), i32 noundef) local_unnamed_addr #3 align 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: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #4

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

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #5

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { inlinehint 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 #4 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 #6 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass