; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=thumbv8-eabi -float-abi=hard -arm-restrict-it | FileCheck --check-prefixes=P01 %s
; RUN: llc < %s -mtriple=thumbv7-eabi -float-abi=hard -arm-restrict-it | FileCheck --check-prefixes=P01 %s
; RUN: llc < %s -mtriple=thumbv8-eabi -float-abi=hard -regalloc=basic -arm-restrict-it | FileCheck --check-prefixes=P23 %s
; RUN: llc < %s -mtriple=thumbv7-eabi -float-abi=hard -regalloc=basic -arm-restrict-it | FileCheck --check-prefixes=P23 %s

%"struct.__gnu_cxx::__normal_iterator<char*,std::basic_string<char, std::char_traits<char>, std::allocator<char> > >" = type { ptr }
%"struct.__gnu_cxx::new_allocator<char>" = type <{ i8 }>
%"struct.std::basic_string<char,std::char_traits<char>,std::allocator<char> >" = type { %"struct.__gnu_cxx::__normal_iterator<char*,std::basic_string<char, std::char_traits<char>, std::allocator<char> > >" }
%"struct.std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Rep" = type { %"struct.std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Rep_base" }
%"struct.std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Rep_base" = type { i32, i32, i32 }


define weak arm_aapcs_vfpcc i32 @_ZNKSs7compareERKSs(ptr %this, ptr %__str) {
; P01-LABEL: _ZNKSs7compareERKSs:
; P01:       @ %bb.0: @ %entry
; P01-NEXT:    .save {r4, r5, r6, r7, r8, lr}
; P01-NEXT:    push.w {r4, r5, r6, r7, r8, lr}
; P01-NEXT:    mov r8, r1
; P01-NEXT:    mov r5, r0
; P01-NEXT:    bl _ZNKSs4sizeEv
; P01-NEXT:    mov r4, r0
; P01-NEXT:    mov r0, r8
; P01-NEXT:    bl _ZNKSs4sizeEv
; P01-NEXT:    mov r6, r4
; P01-NEXT:    cmp r4, r0
; P01-NEXT:    mov r7, r0
; P01-NEXT:    it hi
; P01-NEXT:    movhi r6, r0
; P01-NEXT:    mov r0, r5
; P01-NEXT:    bl _ZNKSs7_M_dataEv
; P01-NEXT:    mov r5, r0
; P01-NEXT:    mov r0, r8
; P01-NEXT:    bl _ZNKSs4dataEv
; P01-NEXT:    mov r1, r0
; P01-NEXT:    mov r0, r5
; P01-NEXT:    mov r2, r6
; P01-NEXT:    bl memcmp
; P01-NEXT:    subs r1, r4, r7
; P01-NEXT:    cmp r0, #0
; P01-NEXT:    it eq
; P01-NEXT:    moveq r0, r1
; P01-NEXT:    pop.w {r4, r5, r6, r7, r8, pc}
;
; P23-LABEL: _ZNKSs7compareERKSs:
; P23:       @ %bb.0: @ %entry
; P23-NEXT:    .save {r4, r5, r6, r7, r8, lr}
; P23-NEXT:    push.w {r4, r5, r6, r7, r8, lr}
; P23-NEXT:    mov r8, r1
; P23-NEXT:    mov r7, r0
; P23-NEXT:    bl _ZNKSs4sizeEv
; P23-NEXT:    mov r6, r0
; P23-NEXT:    mov r0, r8
; P23-NEXT:    bl _ZNKSs4sizeEv
; P23-NEXT:    mov r4, r6
; P23-NEXT:    cmp r6, r0
; P23-NEXT:    mov r5, r0
; P23-NEXT:    it hi
; P23-NEXT:    movhi r4, r0
; P23-NEXT:    mov r0, r7
; P23-NEXT:    bl _ZNKSs7_M_dataEv
; P23-NEXT:    mov r7, r0
; P23-NEXT:    mov r0, r8
; P23-NEXT:    bl _ZNKSs4dataEv
; P23-NEXT:    mov r1, r0
; P23-NEXT:    mov r0, r7
; P23-NEXT:    mov r2, r4
; P23-NEXT:    bl memcmp
; P23-NEXT:    subs r1, r6, r5
; P23-NEXT:    cmp r0, #0
; P23-NEXT:    it eq
; P23-NEXT:    moveq r0, r1
; P23-NEXT:    pop.w {r4, r5, r6, r7, r8, pc}
entry:
  %0 = tail call arm_aapcs_vfpcc  i32 @_ZNKSs4sizeEv(ptr %this) ; <i32> [#uses=3]
  %1 = tail call arm_aapcs_vfpcc  i32 @_ZNKSs4sizeEv(ptr %__str) ; <i32> [#uses=3]
  %2 = icmp ult i32 %1, %0                        ; <i1> [#uses=1]
  %3 = select i1 %2, i32 %1, i32 %0               ; <i32> [#uses=1]
  %4 = tail call arm_aapcs_vfpcc  ptr @_ZNKSs7_M_dataEv(ptr %this) ; <ptr> [#uses=1]
  %5 = tail call arm_aapcs_vfpcc  ptr @_ZNKSs4dataEv(ptr %__str) ; <ptr> [#uses=1]
  %6 = tail call arm_aapcs_vfpcc  i32 @memcmp(ptr %4, ptr %5, i32 %3) nounwind readonly ; <i32> [#uses=2]
  %7 = icmp eq i32 %6, 0                          ; <i1> [#uses=1]
  br i1 %7, label %bb, label %bb1

bb:                                               ; preds = %entry
  %8 = sub i32 %0, %1                             ; <i32> [#uses=1]
  ret i32 %8

bb1:                                              ; preds = %entry
  ret i32 %6
}

declare arm_aapcs_vfpcc i32 @memcmp(ptr nocapture, ptr nocapture, i32) nounwind readonly

declare arm_aapcs_vfpcc i32 @_ZNKSs4sizeEv(ptr %this)

declare arm_aapcs_vfpcc ptr @_ZNKSs7_M_dataEv(ptr %this)

declare arm_aapcs_vfpcc ptr @_ZNKSs4dataEv(ptr %this)
