; LLVM IR from upupming/algorithm :: kick-start/2021/RoundC/A.  Smaller Strings.ll (Z3dfsib)

; 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] }

@n = external dso_local global i64, align 8
@f = external dso_local global [100010 x i64], align 16
@_Z1sB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z3dfsib(i32 noundef %0, i1 noundef zeroext %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  %9 = zext i1 %1 to i8
  store i8 %9, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %11)
  %13 = load i8, ptr %12, align 1, !tbaa !11
  %14 = sext i8 %13 to i32
  %15 = load i64, ptr @n, align 8, !tbaa !12
  %16 = sub nsw i64 %15, 1
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = sub nsw i64 %16, %18
  %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 !11
  %22 = sext i8 %21 to i32
  %23 = icmp slt i32 %14, %22
  br i1 %23, label %44, label %24

24:                                               ; preds = %2
  %25 = load i32, ptr %4, 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 !11
  %29 = sext i8 %28 to i32
  %30 = load i64, ptr @n, align 8, !tbaa !12
  %31 = sub nsw i64 %30, 1
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = sub nsw i64 %31, %33
  %35 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %34)
  %36 = load i8, ptr %35, align 1, !tbaa !11
  %37 = sext i8 %36 to i32
  %38 = icmp eq i32 %29, %37
  br i1 %38, label %39, label %42

39:                                               ; preds = %24
  %40 = load i8, ptr %5, align 1, !tbaa !9, !range !14, !noundef !15
  %41 = trunc i8 %40 to i1
  br label %42

42:                                               ; preds = %39, %24
  %43 = phi i1 [ false, %24 ], [ %41, %39 ]
  br label %44

44:                                               ; preds = %42, %2
  %45 = phi i1 [ true, %2 ], [ %43, %42 ]
  %46 = zext i1 %45 to i8
  store i8 %46, ptr %6, align 1, !tbaa !9
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = load i64, ptr @n, align 8, !tbaa !12
  %50 = sub nsw i64 %49, 1
  %51 = sdiv i64 %50, 2
  %52 = icmp eq i64 %48, %51
  br i1 %52, label %53, label %81

53:                                               ; preds = %44
  %54 = load i64, ptr @n, align 8, !tbaa !12
  %55 = srem i64 %54, 2
  %56 = icmp eq i64 %55, 0
  br i1 %56, label %57, label %69

57:                                               ; preds = %53
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %59)
  %61 = load i8, ptr %60, align 1, !tbaa !11
  %62 = sext i8 %61 to i32
  %63 = sub nsw i32 %62, 97
  %64 = load i8, ptr %6, align 1, !tbaa !9, !range !14, !noundef !15
  %65 = trunc i8 %64 to i1
  %66 = zext i1 %65 to i32
  %67 = add nsw i32 %63, %66
  %68 = sext i32 %67 to i64
  store i64 %68, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %118

69:                                               ; preds = %53
  %70 = load i32, ptr %4, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %71)
  %73 = load i8, ptr %72, align 1, !tbaa !11
  %74 = sext i8 %73 to i32
  %75 = sub nsw i32 %74, 97
  %76 = load i8, ptr %5, align 1, !tbaa !9, !range !14, !noundef !15
  %77 = trunc i8 %76 to i1
  %78 = zext i1 %77 to i32
  %79 = add nsw i32 %75, %78
  %80 = sext i32 %79 to i64
  store i64 %80, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %118

81:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !12
  %82 = load i64, ptr @n, align 8, !tbaa !12
  %83 = load i32, ptr %4, align 4, !tbaa !5
  %84 = add nsw i32 %83, 1
  %85 = mul nsw i32 2, %84
  %86 = sext i32 %85 to i64
  %87 = sub nsw i64 %82, %86
  %88 = icmp sge i64 %87, 0
  br i1 %88, label %89, label %108

89:                                               ; preds = %81
  %90 = load i32, ptr %4, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %91)
  %93 = load i8, ptr %92, align 1, !tbaa !11
  %94 = sext i8 %93 to i32
  %95 = sub nsw i32 %94, 97
  %96 = sext i32 %95 to i64
  %97 = load i64, ptr @n, align 8, !tbaa !12
  %98 = load i32, ptr %4, align 4, !tbaa !5
  %99 = add nsw i32 %98, 1
  %100 = mul nsw i32 2, %99
  %101 = sext i32 %100 to i64
  %102 = sub nsw i64 %97, %101
  %103 = getelementptr inbounds [100010 x i64], ptr @f, i64 0, i64 %102
  %104 = load i64, ptr %103, align 8, !tbaa !12
  %105 = mul nsw i64 %96, %104
  %106 = load i64, ptr %8, align 8, !tbaa !12
  %107 = add nsw i64 %106, %105
  store i64 %107, ptr %8, align 8, !tbaa !12
  br label %108

108:                                              ; preds = %89, %81
  %109 = load i32, ptr %4, align 4, !tbaa !5
  %110 = add nsw i32 %109, 1
  %111 = load i8, ptr %6, align 1, !tbaa !9, !range !14, !noundef !15
  %112 = trunc i8 %111 to i1
  %113 = call noundef i64 @_Z3dfsib(i32 noundef %110, i1 noundef zeroext %112)
  %114 = load i64, ptr %8, align 8, !tbaa !12
  %115 = add nsw i64 %114, %113
  store i64 %115, ptr %8, align 8, !tbaa !12
  %116 = load i64, ptr %8, align 8, !tbaa !12
  %117 = srem i64 %116, 1000000007
  store i64 %117, ptr %3, align 8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %118

118:                                              ; preds = %108, %69, %57
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  %119 = load i64, ptr %3, align 8
  ret i64 %119
}

; 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) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}


; 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] }

@n = external dso_local local_unnamed_addr global i64, align 8
@f = external dso_local local_unnamed_addr global [100010 x i64], align 16
@_Z1sB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i64 -1000000006, 1000000007) i64 @_Z3dfsib(i32 noundef %0, i1 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %3)
  %5 = load i8, ptr %4, align 1, !tbaa !5
  %6 = load i64, ptr @n, align 8, !tbaa !8
  %7 = xor i64 %3, -1
  %8 = add i64 %6, %7
  %9 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %8)
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %11 = icmp slt i8 %5, %10
  br i1 %11, label %21, label %12

12:                                               ; preds = %2
  %13 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %3)
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %15 = load i64, ptr @n, align 8, !tbaa !8
  %16 = add i64 %15, %7
  %17 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %16)
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %19 = icmp eq i8 %14, %18
  %20 = and i1 %19, %1
  br label %21

21:                                               ; preds = %12, %2
  %22 = phi i1 [ true, %2 ], [ %20, %12 ]
  %23 = load i64, ptr @n, align 8, !tbaa !8
  %24 = add nsw i64 %23, -1
  %25 = sdiv i64 %24, 2
  %26 = icmp eq i64 %25, %3
  br i1 %26, label %common.ret, label %36

common.ret:                                       ; preds = %21
  %27 = and i64 %23, 1
  %28 = icmp eq i64 %27, 0
  %29 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %3)
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %31 = sext i8 %30 to i64
  %32 = select i1 %22, i64 -96, i64 -97
  %33 = add nsw i64 %32, %31
  %34 = select i1 %1, i64 -96, i64 -97
  %35 = add nsw i64 %34, %31
  %common.ret.op = select i1 %28, i64 %33, i64 %35
  br label %common.ret21

36:                                               ; preds = %21
  %37 = add nsw i32 %0, 1
  %38 = shl nsw i32 %37, 1
  %39 = sext i32 %38 to i64
  %.not = icmp slt i64 %23, %39
  br i1 %.not, label %50, label %40

40:                                               ; preds = %36
  %41 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %3)
  %42 = load i8, ptr %41, align 1, !tbaa !5
  %43 = sext i8 %42 to i64
  %44 = add nsw i64 %43, -97
  %45 = load i64, ptr @n, align 8, !tbaa !8
  %46 = sub nsw i64 %45, %39
  %47 = getelementptr inbounds [100010 x i64], ptr @f, i64 0, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !8
  %49 = mul nsw i64 %44, %48
  br label %50

common.ret21:                                     ; preds = %50, %common.ret
  %common.ret21.op = phi i64 [ %common.ret.op, %common.ret ], [ %53, %50 ]
  ret i64 %common.ret21.op

50:                                               ; preds = %40, %36
  %.0 = phi i64 [ %49, %40 ], [ 0, %36 ]
  %51 = tail call noundef i64 @_Z3dfsib(i32 noundef %37, i1 noundef zeroext %22)
  %52 = add nsw i64 %51, %.0
  %53 = srem i64 %52, 1000000007
  br label %common.ret21
}

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

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

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"long long", !6, i64 0}


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