; LLVM IR from VastoLorde95/Competitive-Programming :: Hackerrank/Codesprints 2016/Codesprint May/Problem E/M.ll (Z7comparev)

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

@_Z1lB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@_Z1rB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@n = external dso_local global i32, align 4
@comp = external dso_local global [2097152 x i32], align 16

; 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 void @_Z7comparev() #1 {
  %1 = alloca i32, align 4
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = sub nsw i32 %2, 1
  %4 = sext i32 %3 to i64
  %5 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1lB5cxx11, i64 noundef %4)
  %6 = load i8, ptr %5, align 1, !tbaa !9
  %7 = sext i8 %6 to i32
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = sub nsw i32 %8, 1
  %10 = sext i32 %9 to i64
  %11 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1rB5cxx11, i64 noundef %10)
  %12 = load i8, ptr %11, align 1, !tbaa !9
  %13 = sext i8 %12 to i32
  %14 = icmp eq i32 %7, %13
  br i1 %14, label %15, label %20

15:                                               ; preds = %0
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = sub nsw i32 %16, 1
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [2097152 x i32], ptr @comp, i64 0, i64 %18
  store i32 0, ptr %19, align 4, !tbaa !5
  br label %45

20:                                               ; preds = %0
  %21 = load i32, ptr @n, align 4, !tbaa !5
  %22 = sub nsw i32 %21, 1
  %23 = sext i32 %22 to i64
  %24 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1lB5cxx11, i64 noundef %23)
  %25 = load i8, ptr %24, align 1, !tbaa !9
  %26 = sext i8 %25 to i32
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %28 = sub nsw i32 %27, 1
  %29 = sext i32 %28 to i64
  %30 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1rB5cxx11, i64 noundef %29)
  %31 = load i8, ptr %30, align 1, !tbaa !9
  %32 = sext i8 %31 to i32
  %33 = icmp sgt i32 %26, %32
  br i1 %33, label %34, label %39

34:                                               ; preds = %20
  %35 = load i32, ptr @n, align 4, !tbaa !5
  %36 = sub nsw i32 %35, 1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [2097152 x i32], ptr @comp, i64 0, i64 %37
  store i32 1, ptr %38, align 4, !tbaa !5
  br label %44

39:                                               ; preds = %20
  %40 = load i32, ptr @n, align 4, !tbaa !5
  %41 = sub nsw i32 %40, 1
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [2097152 x i32], ptr @comp, i64 0, i64 %42
  store i32 -1, ptr %43, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %39, %34
  br label %45

45:                                               ; preds = %44, %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  %46 = load i32, ptr @n, align 4, !tbaa !5
  %47 = sub nsw i32 %46, 2
  store i32 %47, ptr %1, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %95, %45
  %49 = load i32, ptr %1, align 4, !tbaa !5
  %50 = icmp sge i32 %49, 0
  br i1 %50, label %52, label %51

51:                                               ; preds = %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  br label %98

52:                                               ; preds = %48
  %53 = load i32, ptr %1, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1lB5cxx11, i64 noundef %54)
  %56 = load i8, ptr %55, align 1, !tbaa !9
  %57 = sext i8 %56 to i32
  %58 = load i32, ptr %1, 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) @_Z1rB5cxx11, i64 noundef %59)
  %61 = load i8, ptr %60, align 1, !tbaa !9
  %62 = sext i8 %61 to i32
  %63 = icmp slt i32 %57, %62
  br i1 %63, label %64, label %68

64:                                               ; preds = %52
  %65 = load i32, ptr %1, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [2097152 x i32], ptr @comp, i64 0, i64 %66
  store i32 -1, ptr %67, align 4, !tbaa !5
  br label %94

68:                                               ; preds = %52
  %69 = load i32, ptr %1, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1lB5cxx11, i64 noundef %70)
  %72 = load i8, ptr %71, align 1, !tbaa !9
  %73 = sext i8 %72 to i32
  %74 = load i32, ptr %1, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1rB5cxx11, i64 noundef %75)
  %77 = load i8, ptr %76, align 1, !tbaa !9
  %78 = sext i8 %77 to i32
  %79 = icmp sgt i32 %73, %78
  br i1 %79, label %80, label %84

80:                                               ; preds = %68
  %81 = load i32, ptr %1, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [2097152 x i32], ptr @comp, i64 0, i64 %82
  store i32 1, ptr %83, align 4, !tbaa !5
  br label %93

84:                                               ; preds = %68
  %85 = load i32, ptr %1, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [2097152 x i32], ptr @comp, i64 0, i64 %87
  %89 = load i32, ptr %88, align 4, !tbaa !5
  %90 = load i32, ptr %1, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [2097152 x i32], ptr @comp, i64 0, i64 %91
  store i32 %89, ptr %92, align 4, !tbaa !5
  br label %93

93:                                               ; preds = %84, %80
  br label %94

94:                                               ; preds = %93, %64
  br label %95

95:                                               ; preds = %94
  %96 = load i32, ptr %1, align 4, !tbaa !5
  %97 = add nsw i32 %96, -1
  store i32 %97, ptr %1, align 4, !tbaa !5
  br label %48, !llvm.loop !10

98:                                               ; preds = %51
  ret void
}

; 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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] }

@_Z1lB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@_Z1rB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@n = external dso_local local_unnamed_addr global i32, align 4
@comp = external dso_local local_unnamed_addr global [2097152 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z7comparev() local_unnamed_addr #0 {
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %2 = add nsw i32 %1, -1
  %3 = sext i32 %2 to i64
  %4 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1lB5cxx11, i64 noundef %3)
  %5 = load i8, ptr %4, align 1, !tbaa !9
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = add nsw i32 %6, -1
  %8 = sext i32 %7 to i64
  %9 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1rB5cxx11, i64 noundef %8)
  %10 = load i8, ptr %9, align 1, !tbaa !9
  %11 = icmp eq i8 %5, %10
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = add nsw i32 %12, -1
  %14 = sext i32 %13 to i64
  br i1 %11, label %15, label %17

15:                                               ; preds = %0
  %16 = getelementptr inbounds [2097152 x i32], ptr @comp, i64 0, i64 %14
  store i32 0, ptr %16, align 4, !tbaa !5
  br label %32

17:                                               ; preds = %0
  %18 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1lB5cxx11, i64 noundef %14)
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = load i32, ptr @n, align 4, !tbaa !5
  %21 = add nsw i32 %20, -1
  %22 = sext i32 %21 to i64
  %23 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1rB5cxx11, i64 noundef %22)
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %25 = icmp sgt i8 %19, %24
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = add nsw i32 %26, -1
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [2097152 x i32], ptr @comp, i64 0, i64 %28
  br i1 %25, label %30, label %31

30:                                               ; preds = %17
  store i32 1, ptr %29, align 4, !tbaa !5
  br label %32

31:                                               ; preds = %17
  store i32 -1, ptr %29, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %30, %31, %15
  %33 = phi i32 [ %26, %30 ], [ %26, %31 ], [ %12, %15 ]
  %34 = icmp sgt i32 %33, 1
  br i1 %34, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %32
  %35 = add nsw i32 %33, -2
  %36 = zext nneg i32 %35 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %52, %32
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %52
  %indvars.iv = phi i64 [ %36, %.lr.ph.preheader ], [ %indvars.iv.next, %52 ]
  %37 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1lB5cxx11, i64 noundef %indvars.iv)
  %38 = load i8, ptr %37, align 1, !tbaa !9
  %39 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1rB5cxx11, i64 noundef %indvars.iv)
  %40 = load i8, ptr %39, align 1, !tbaa !9
  %41 = icmp slt i8 %38, %40
  br i1 %41, label %52, label %42

42:                                               ; preds = %.lr.ph
  %43 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1lB5cxx11, i64 noundef %indvars.iv)
  %44 = load i8, ptr %43, align 1, !tbaa !9
  %45 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1rB5cxx11, i64 noundef %indvars.iv)
  %46 = load i8, ptr %45, align 1, !tbaa !9
  %47 = icmp sgt i8 %44, %46
  br i1 %47, label %52, label %48

48:                                               ; preds = %42
  %49 = add nuw nsw i64 %indvars.iv, 1
  %50 = getelementptr inbounds [2097152 x i32], ptr @comp, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %42, %.lr.ph, %48
  %.sink = phi i32 [ %51, %48 ], [ -1, %.lr.ph ], [ 1, %42 ]
  %53 = getelementptr inbounds [2097152 x i32], ptr @comp, i64 0, i64 %indvars.iv
  store i32 %.sink, ptr %53, align 4, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %54 = icmp sgt i64 %indvars.iv, 0
  br i1 %54, label %.lr.ph, label %._crit_edge, !llvm.loop !10
}

; 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass