; LLVM IR from Izaron/ACM-ICPC :: Timus Online Judge/Volume 8/1724. Origin of Man Clarified.ll (Z8ansBuildiiii)

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

@ansTree = external dso_local global [400020 x [4 x i32]], align 16
@ans = external dso_local global [100005 x [4 x i32]], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8ansBuildiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !5
  %9 = load i32, ptr %6, align 4, !tbaa !5
  %10 = load i32, ptr %7, align 4, !tbaa !5
  %11 = icmp eq i32 %9, %10
  br i1 %11, label %12, label %26

12:                                               ; preds = %4
  %13 = load i32, ptr %6, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [100005 x [4 x i32]], ptr @ans, i64 0, i64 %14
  %16 = load i32, ptr %8, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [4 x i32], ptr %15, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [400020 x [4 x i32]], ptr @ansTree, i64 0, i64 %21
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [4 x i32], ptr %22, i64 0, i64 %24
  store i32 %19, ptr %25, align 4, !tbaa !5
  br label %68

26:                                               ; preds = %4
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = mul nsw i32 %27, 2
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = add nsw i32 %30, %31
  %33 = sdiv i32 %32, 2
  %34 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z8ansBuildiiii(i32 noundef %28, i32 noundef %29, i32 noundef %33, i32 noundef %34)
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = mul nsw i32 %35, 2
  %37 = add nsw i32 %36, 1
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = add nsw i32 %38, %39
  %41 = sdiv i32 %40, 2
  %42 = add nsw i32 %41, 1
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z8ansBuildiiii(i32 noundef %37, i32 noundef %42, i32 noundef %43, i32 noundef %44)
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = mul nsw i32 %45, 2
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [400020 x [4 x i32]], ptr @ansTree, i64 0, i64 %47
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [4 x i32], ptr %48, i64 0, i64 %50
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = mul nsw i32 %52, 2
  %54 = add nsw i32 %53, 1
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [400020 x [4 x i32]], ptr @ansTree, i64 0, i64 %55
  %57 = load i32, ptr %8, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [4 x i32], ptr %56, i64 0, i64 %58
  %60 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %51, ptr noundef nonnull align 4 dereferenceable(4) %59)
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [400020 x [4 x i32]], ptr @ansTree, i64 0, i64 %63
  %65 = load i32, ptr %8, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [4 x i32], ptr %64, i64 0, i64 %66
  store i32 %61, ptr %67, align 4, !tbaa !5
  br label %68

68:                                               ; preds = %26, %12
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #1

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 = { inlinehint 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" }

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

@ansTree = external dso_local global [400020 x [4 x i32]], align 16
@ans = external dso_local local_unnamed_addr global [100005 x [4 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z8ansBuildiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq i32 %1, %2
  br i1 %5, label %6, label %13

6:                                                ; preds = %4
  %7 = sext i32 %1 to i64
  %8 = sext i32 %3 to i64
  %9 = getelementptr inbounds [100005 x [4 x i32]], ptr @ans, i64 0, i64 %7, i64 %8
  br label %common.ret

common.ret:                                       ; preds = %6, %13
  %.sink26 = phi ptr [ %9, %6 ], [ %24, %13 ]
  %.sink25 = phi i64 [ %8, %6 ], [ %20, %13 ]
  %10 = load i32, ptr %.sink26, align 4, !tbaa !5
  %11 = sext i32 %0 to i64
  %12 = getelementptr inbounds [400020 x [4 x i32]], ptr @ansTree, i64 0, i64 %11, i64 %.sink25
  store i32 %10, ptr %12, align 4, !tbaa !5
  ret void

13:                                               ; preds = %4
  %14 = shl nsw i32 %0, 1
  %15 = add nsw i32 %2, %1
  %16 = sdiv i32 %15, 2
  tail call void @_Z8ansBuildiiii(i32 noundef %14, i32 noundef %1, i32 noundef %16, i32 noundef %3)
  %17 = or disjoint i32 %14, 1
  %18 = add nsw i32 %16, 1
  tail call void @_Z8ansBuildiiii(i32 noundef %17, i32 noundef %18, i32 noundef %2, i32 noundef %3)
  %19 = sext i32 %14 to i64
  %20 = sext i32 %3 to i64
  %21 = getelementptr inbounds [400020 x [4 x i32]], ptr @ansTree, i64 0, i64 %19, i64 %20
  %22 = sext i32 %17 to i64
  %23 = getelementptr inbounds [400020 x [4 x i32]], ptr @ansTree, i64 0, i64 %22, i64 %20
  %24 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %21, ptr noundef nonnull align 4 dereferenceable(4) %23)
  br label %common.ret
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #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 = { inlinehint 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" }

!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: EarlyCSEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass