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

; 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::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@_Z1sB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@lst = external dso_local global [100005 x i32], align 16
@lstTree = external dso_local global [400020 x i32], align 16

; 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)) #0

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #1 align 2

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

10:                                               ; preds = %3
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [100005 x i32], ptr @lst, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [400020 x i32], ptr @lstTree, i64 0, i64 %16
  store i32 %14, ptr %17, align 4, !tbaa !5
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %19)
  %21 = load i8, ptr %20, align 1, !tbaa !9
  %22 = sext i8 %21 to i32
  %23 = icmp sge i32 %22, 65
  br i1 %23, label %24, label %36

24:                                               ; preds = %10
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %26)
  %28 = load i8, ptr %27, align 1, !tbaa !9
  %29 = sext i8 %28 to i32
  %30 = icmp sle i32 %29, 90
  br i1 %30, label %31, label %36

31:                                               ; preds = %24
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [400020 x i32], ptr @lstTree, i64 0, i64 %34
  store i32 %32, ptr %35, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %31, %24, %10
  br label %68

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

68:                                               ; preds = %37, %36
  ret void
}

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

!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 = !{!7, !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.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@_Z1sB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@lst = external dso_local local_unnamed_addr global [100005 x i32], align 16
@lstTree = external dso_local global [400020 x i32], align 16

; 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 #0

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) local_unnamed_addr #1 align 2

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

5:                                                ; preds = %3
  %6 = sext i32 %1 to i64
  %7 = getelementptr inbounds [100005 x i32], ptr @lst, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = sext i32 %0 to i64
  %10 = getelementptr inbounds [400020 x i32], ptr @lstTree, i64 0, i64 %9
  store i32 %8, ptr %10, align 4, !tbaa !5
  %11 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %6)
  %12 = load i8, ptr %11, align 1, !tbaa !9
  %13 = icmp sgt i8 %12, 64
  br i1 %13, label %14, label %common.ret20

14:                                               ; preds = %5
  %15 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %6)
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = icmp slt i8 %16, 91
  br i1 %17, label %18, label %common.ret20

18:                                               ; preds = %14
  store i32 %1, ptr %10, align 4, !tbaa !5
  br label %common.ret20

common.ret20:                                     ; preds = %5, %14, %18, %19
  ret void

19:                                               ; preds = %3
  %20 = shl nsw i32 %0, 1
  %21 = add nsw i32 %2, %1
  %22 = sdiv i32 %21, 2
  tail call void @_Z8lstBuildiii(i32 noundef %20, i32 noundef %1, i32 noundef %22)
  %23 = or disjoint i32 %20, 1
  %24 = add nsw i32 %22, 1
  tail call void @_Z8lstBuildiii(i32 noundef %23, i32 noundef %24, i32 noundef %2)
  %25 = sext i32 %20 to i64
  %26 = getelementptr inbounds [400020 x i32], ptr @lstTree, i64 0, i64 %25
  %27 = sext i32 %23 to i64
  %28 = getelementptr inbounds [400020 x i32], ptr @lstTree, i64 0, i64 %27
  %29 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %26, ptr noundef nonnull align 4 dereferenceable(4) %28)
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sext i32 %0 to i64
  %32 = getelementptr inbounds [400020 x i32], ptr @lstTree, i64 0, i64 %31
  store i32 %30, ptr %32, align 4, !tbaa !5
  br label %common.ret20
}

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

!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 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass