; LLVM IR from Izaron/ACM-ICPC :: Russian Olympiad in Informatics/Final Stage 2016/typing.ll (Z3dfsi)

; 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] }
%class.bor = type { ptr, ptr, i64 }

@mbor = external dso_local global ptr, align 8
@ans = external dso_local global [300005 x i64], align 16
@m = external dso_local global i32, align 4
@_Z4masaB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8

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

13:                                               ; preds = %1
  store i64 0, ptr %2, align 8
  br label %97

14:                                               ; preds = %1
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [300005 x i64], ptr @ans, i64 0, i64 %16
  %18 = load i64, ptr %17, align 8, !tbaa !9
  %19 = icmp ne i64 %18, -1
  br i1 %19, label %20, label %25

20:                                               ; preds = %14
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [300005 x i64], ptr @ans, i64 0, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !9
  store i64 %24, ptr %2, align 8
  br label %97

25:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %26 = load ptr, ptr @mbor, align 8, !tbaa !11
  store ptr %26, ptr %4, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store i64 1000000000000000000, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %27 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %27, ptr %6, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %87, %25
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = load i32, ptr @m, align 4, !tbaa !5
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  store i32 2, ptr %7, align 4
  br label %90

33:                                               ; preds = %28
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z4masaB5cxx11, i64 noundef %35)
  %37 = load i8, ptr %36, align 1, !tbaa !13
  %38 = sext i8 %37 to i32
  %39 = icmp eq i32 %38, 48
  br i1 %39, label %40, label %66

40:                                               ; preds = %33
  %41 = load ptr, ptr %4, align 8, !tbaa !11
  %42 = getelementptr inbounds %class.bor, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !14
  %44 = icmp eq ptr %43, null
  br i1 %44, label %45, label %46

45:                                               ; preds = %40
  store i32 2, ptr %7, align 4
  br label %90

46:                                               ; preds = %40
  %47 = load ptr, ptr %4, align 8, !tbaa !11
  %48 = getelementptr inbounds %class.bor, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !14
  store ptr %49, ptr %4, align 8, !tbaa !11
  %50 = load ptr, ptr %4, align 8, !tbaa !11
  %51 = getelementptr inbounds %class.bor, ptr %50, i32 0, i32 2
  %52 = load i64, ptr %51, align 8, !tbaa !16
  %53 = icmp sge i64 %52, 1000000000000000000
  br i1 %53, label %54, label %55

54:                                               ; preds = %46
  br label %87

55:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %56 = load ptr, ptr %4, align 8, !tbaa !11
  %57 = getelementptr inbounds %class.bor, ptr %56, i32 0, i32 2
  %58 = load i64, ptr %57, align 8, !tbaa !16
  %59 = load i32, ptr %6, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  %61 = call noundef i64 @_Z3dfsi(i32 noundef %60)
  %62 = add nsw i64 %58, %61
  store i64 %62, ptr %8, align 8, !tbaa !9
  %63 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %8)
  %64 = load i64, ptr %63, align 8, !tbaa !9
  store i64 %64, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %65

65:                                               ; preds = %55
  br label %86

66:                                               ; preds = %33
  %67 = load ptr, ptr %4, align 8, !tbaa !11
  %68 = getelementptr inbounds %class.bor, ptr %67, i32 0, i32 1
  %69 = load ptr, ptr %68, align 8, !tbaa !17
  %70 = icmp eq ptr %69, null
  br i1 %70, label %71, label %72

71:                                               ; preds = %66
  store i32 2, ptr %7, align 4
  br label %90

72:                                               ; preds = %66
  %73 = load ptr, ptr %4, align 8, !tbaa !11
  %74 = getelementptr inbounds %class.bor, ptr %73, i32 0, i32 1
  %75 = load ptr, ptr %74, align 8, !tbaa !17
  store ptr %75, ptr %4, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %76 = load ptr, ptr %4, align 8, !tbaa !11
  %77 = getelementptr inbounds %class.bor, ptr %76, i32 0, i32 2
  %78 = load i64, ptr %77, align 8, !tbaa !16
  %79 = load i32, ptr %6, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  %81 = call noundef i64 @_Z3dfsi(i32 noundef %80)
  %82 = add nsw i64 %78, %81
  store i64 %82, ptr %9, align 8, !tbaa !9
  %83 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %9)
  %84 = load i64, ptr %83, align 8, !tbaa !9
  store i64 %84, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %85

85:                                               ; preds = %72
  br label %86

86:                                               ; preds = %85, %65
  br label %87

87:                                               ; preds = %86, %54
  %88 = load i32, ptr %6, align 4, !tbaa !5
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %6, align 4, !tbaa !5
  br label %28, !llvm.loop !18

90:                                               ; preds = %71, %45, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %91

91:                                               ; preds = %90
  %92 = load i64, ptr %5, align 8, !tbaa !9
  %93 = load i32, ptr %3, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [300005 x i64], ptr @ans, i64 0, i64 %94
  store i64 %92, ptr %95, align 8, !tbaa !9
  %96 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %96, ptr %2, align 8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %97

97:                                               ; preds = %91, %20, %13
  %98 = load i64, ptr %2, align 8
  ret i64 %98
}

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

; 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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #4 = { 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 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !12, i64 0}
!15 = !{!"_ZTS3bor", !12, i64 0, !12, i64 8, !10, i64 16}
!16 = !{!15, !10, i64 16}
!17 = !{!15, !12, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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

@mbor = external dso_local local_unnamed_addr global ptr, align 8
@ans = external dso_local local_unnamed_addr global [300005 x i64], align 16
@m = external dso_local local_unnamed_addr global i32, align 4
@_Z4masaB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z3dfsi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = load i32, ptr @m, align 4, !tbaa !5
  %6 = icmp eq i32 %5, %0
  br i1 %6, label %49, label %7

7:                                                ; preds = %1
  %8 = sext i32 %0 to i64
  %9 = getelementptr inbounds [300005 x i64], ptr @ans, i64 0, i64 %8
  %10 = load i64, ptr %9, align 8, !tbaa !9
  %.not = icmp eq i64 %10, -1
  br i1 %.not, label %11, label %49

11:                                               ; preds = %7
  %12 = load ptr, ptr @mbor, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  store i64 1000000000000000000, ptr %2, align 8, !tbaa !9
  %13 = icmp sgt i32 %5, %0
  br i1 %13, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %11, %44
  %indvars.iv = phi i64 [ %indvars.iv.next.pre-phi, %44 ], [ %8, %11 ]
  %.01723 = phi ptr [ %.1, %44 ], [ %12, %11 ]
  %14 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z4masaB5cxx11, i64 noundef %indvars.iv)
  %15 = load i8, ptr %14, align 1, !tbaa !13
  %16 = icmp eq i8 %15, 48
  br i1 %16, label %17, label %31

17:                                               ; preds = %.lr.ph
  %18 = load ptr, ptr %.01723, align 8, !tbaa !14
  %19 = icmp eq ptr %18, null
  br i1 %19, label %._crit_edge.loopexit, label %20

20:                                               ; preds = %17
  %21 = getelementptr inbounds i8, ptr %18, i64 16
  %22 = load i64, ptr %21, align 8, !tbaa !16
  %23 = icmp sgt i64 %22, 999999999999999999
  br i1 %23, label %._crit_edge28, label %24

._crit_edge28:                                    ; preds = %20
  %.pre29 = add nsw i64 %indvars.iv, 1
  br label %44

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %25 = add nsw i64 %indvars.iv, 1
  %26 = trunc nsw i64 %25 to i32
  %27 = call noundef i64 @_Z3dfsi(i32 noundef %26)
  %28 = add nsw i64 %27, %22
  store i64 %28, ptr %3, align 8, !tbaa !9
  %29 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %30 = load i64, ptr %29, align 8, !tbaa !9
  store i64 %30, ptr %2, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br label %44

31:                                               ; preds = %.lr.ph
  %32 = getelementptr inbounds i8, ptr %.01723, i64 8
  %33 = load ptr, ptr %32, align 8, !tbaa !17
  %34 = icmp eq ptr %33, null
  br i1 %34, label %._crit_edge.loopexit, label %35

35:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %36 = getelementptr inbounds i8, ptr %33, i64 16
  %37 = load i64, ptr %36, align 8, !tbaa !16
  %38 = add nsw i64 %indvars.iv, 1
  %39 = trunc nsw i64 %38 to i32
  %40 = call noundef i64 @_Z3dfsi(i32 noundef %39)
  %41 = add nsw i64 %40, %37
  store i64 %41, ptr %4, align 8, !tbaa !9
  %42 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %43 = load i64, ptr %42, align 8, !tbaa !9
  store i64 %43, ptr %2, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  br label %44

44:                                               ; preds = %._crit_edge28, %24, %35
  %indvars.iv.next.pre-phi = phi i64 [ %.pre29, %._crit_edge28 ], [ %25, %24 ], [ %38, %35 ]
  %.1 = phi ptr [ %18, %._crit_edge28 ], [ %18, %24 ], [ %33, %35 ]
  %45 = load i32, ptr @m, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = icmp slt i64 %indvars.iv.next.pre-phi, %46
  br i1 %47, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !18

._crit_edge.loopexit:                             ; preds = %31, %17, %44
  %.pre = load i64, ptr %2, align 8, !tbaa !9
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %11
  %48 = phi i64 [ %.pre, %._crit_edge.loopexit ], [ 1000000000000000000, %11 ]
  store i64 %48, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  br label %49

49:                                               ; preds = %7, %1, %._crit_edge
  %.018 = phi i64 [ %48, %._crit_edge ], [ 0, %1 ], [ %10, %7 ]
  ret i64 %.018
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

; 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 = { 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 #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 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !12, i64 0}
!15 = !{!"_ZTS3bor", !12, i64 0, !12, i64 8, !10, i64 16}
!16 = !{!15, !10, i64 16}
!17 = !{!15, !12, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass