; LLVM IR from abeaumont/competitive-programming :: codejam/2018-practice/d.ll (Z1sii)

; 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.std::tuple" = type { %"struct.std::_Tuple_impl" }
%"struct.std::_Tuple_impl" = type { %"struct.std::_Tuple_impl.0", %"struct.std::_Head_base.1" }
%"struct.std::_Tuple_impl.0" = type { %"struct.std::_Head_base" }
%"struct.std::_Head_base" = type { i32 }
%"struct.std::_Head_base.1" = type { i32 }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z1sii(ptr dead_on_unwind noalias writable sret(%"class.std::tuple") align 4 %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %9 = load i32, ptr %6, align 4, !tbaa !5
  %10 = icmp eq i32 %9, 1
  br i1 %10, label %11, label %17

11:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = sdiv i32 %12, 2
  store i32 %13, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = sub nsw i32 %14, 1
  %16 = sdiv i32 %15, 2
  store i32 %16, ptr %8, align 4, !tbaa !5
  call void @_ZSt10make_tupleIJiiEESt5tupleIJDpNSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeEEEDpOS3_(ptr dead_on_unwind writable sret(%"class.std::tuple") align 4 %0, ptr noundef nonnull align 4 dereferenceable(4) %7, ptr noundef nonnull align 4 dereferenceable(4) %8)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %36

17:                                               ; preds = %3
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = srem i32 %18, 2
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %25, label %21

21:                                               ; preds = %17
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = srem i32 %22, 2
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %30

25:                                               ; preds = %21, %17
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = sdiv i32 %26, 2
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = sdiv i32 %28, 2
  call void @_Z1sii(ptr dead_on_unwind writable sret(%"class.std::tuple") align 4 %0, i32 noundef %27, i32 noundef %29)
  br label %36

30:                                               ; preds = %21
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = sub nsw i32 %31, 1
  %33 = sdiv i32 %32, 2
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = sdiv i32 %34, 2
  call void @_Z1sii(ptr dead_on_unwind writable sret(%"class.std::tuple") align 4 %0, i32 noundef %33, i32 noundef %35)
  br label %36

36:                                               ; preds = %30, %25, %11
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZSt10make_tupleIJiiEESt5tupleIJDpNSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeEEEDpOS3_(ptr dead_on_unwind noalias writable sret(%"class.std::tuple") align 4, ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #1

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

; 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 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; 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.std::tuple" = type { %"struct.std::_Tuple_impl" }
%"struct.std::_Tuple_impl" = type { %"struct.std::_Tuple_impl.0", %"struct.std::_Head_base.1" }
%"struct.std::_Tuple_impl.0" = type { %"struct.std::_Head_base" }
%"struct.std::_Head_base" = type { i32 }
%"struct.std::_Head_base.1" = type { i32 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z1sii(ptr dead_on_unwind noalias writable sret(%"class.std::tuple") align 4 %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = icmp eq i32 %2, 1
  br i1 %6, label %tailrecurse._crit_edge, label %.lr.ph

tailrecurse._crit_edge:                           ; preds = %.lr.ph, %3
  %.tr10.lcssa = phi i32 [ %1, %3 ], [ %.tr10.be, %.lr.ph ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #2
  %7 = sdiv i32 %.tr10.lcssa, 2
  store i32 %7, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #2
  %8 = add nsw i32 %.tr10.lcssa, -1
  %9 = sdiv i32 %8, 2
  store i32 %9, ptr %5, align 4, !tbaa !5
  call void @_ZSt10make_tupleIJiiEESt5tupleIJDpNSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeEEEDpOS3_(ptr dead_on_unwind writable sret(%"class.std::tuple") align 4 %0, ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %5)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #2
  ret void

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.tr1113 = phi i32 [ %.tr11.be, %.lr.ph ], [ %2, %3 ]
  %.tr1012 = phi i32 [ %.tr10.be, %.lr.ph ], [ %1, %3 ]
  %10 = and i32 %.tr1012, 1
  %.not = icmp eq i32 %10, 0
  %11 = and i32 %.tr1113, 1
  %12 = icmp ne i32 %11, 0
  %or.cond.not = and i1 %.not, %12
  %13 = sext i1 %or.cond.not to i32
  %spec.select = add nsw i32 %.tr1012, %13
  %.tr11.be = sdiv i32 %.tr1113, 2
  %.tr10.be = sdiv i32 %spec.select, 2
  %14 = and i32 %.tr1113, -2
  %15 = icmp eq i32 %14, 2
  br i1 %15, label %tailrecurse._crit_edge, label %.lr.ph
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZSt10make_tupleIJiiEESt5tupleIJDpNSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeEEEDpOS3_(ptr dead_on_unwind noalias writable sret(%"class.std::tuple") align 4, ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { mustprogress 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 = { 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"}


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