; LLVM IR from Columbitech/rohc :: src/cprofile.ll (ZNK4ROHC8CProfile9UpdateMSNEtjRt)

; 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.ROHC::CProfile" = type { ptr, ptr, i16, i64, i32, i32, i32, i32, i64, i64, i32, i32, i16, %"class.ROHC::WLSB", i32, i32, i8, i32, i32, i32, %"struct.ROHC::iphdr", i16, i16, %"class.ROHC::WLSB", [11 x i64] }
%"struct.ROHC::iphdr" = type { i8, i8, i16, i16, i16, i8, i8, i16, i32, i32 }
%"class.ROHC::WLSB" = type { %"class.std::vector", i64, i64, i64, i32, i32 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<ROHC::WLSB<int>::LSB, std::allocator<ROHC::WLSB<int>::LSB>>::_Vector_impl" }
%"struct.std::_Vector_base<ROHC::WLSB<int>::LSB, std::allocator<ROHC::WLSB<int>::LSB>>::_Vector_impl" = type { %"struct.std::_Vector_base<ROHC::WLSB<int>::LSB, std::allocator<ROHC::WLSB<int>::LSB>>::_Vector_impl_data" }
%"struct.std::_Vector_base<ROHC::WLSB<int>::LSB, std::allocator<ROHC::WLSB<int>::LSB>>::_Vector_impl_data" = type { ptr, ptr, ptr }

declare noundef i32 @_ZN4ROHC23LSBWindowPForReorderingENS_12Reordering_tEm(i32 noundef, i64 noundef) #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i16 @_ZNK4ROHC8CProfile9UpdateMSNEtjRt(ptr noundef nonnull align 8 dereferenceable(328) %0, i16 noundef zeroext %1, i32 noundef %2, ptr noundef nonnull align 2 dereferenceable(2) %3) #2 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i16, align 2
  %10 = alloca i16, align 2
  %11 = alloca i16, align 2
  %12 = alloca i16, align 2
  %13 = alloca i16, align 2
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i16 %1, ptr %6, align 2, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !11
  store ptr %3, ptr %8, align 8, !tbaa !5
  %14 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #3
  %15 = getelementptr inbounds %"class.ROHC::CProfile", ptr %14, i32 0, i32 14
  %16 = load i32, ptr %15, align 8, !tbaa !13
  %17 = load i32, ptr %7, align 4, !tbaa !11
  %18 = zext i32 %17 to i64
  %19 = call noundef i32 @_ZN4ROHC23LSBWindowPForReorderingENS_12Reordering_tEm(i32 noundef %16, i64 noundef %18)
  %20 = trunc i32 %19 to i16
  store i16 %20, ptr %9, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #3
  %21 = getelementptr inbounds %"class.ROHC::CProfile", ptr %14, i32 0, i32 12
  %22 = load i16, ptr %21, align 8, !tbaa !26
  store i16 %22, ptr %10, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #3
  %23 = getelementptr inbounds %"class.ROHC::CProfile", ptr %14, i32 0, i32 12
  %24 = load i16, ptr %23, align 8, !tbaa !26
  %25 = zext i16 %24 to i32
  %26 = load i16, ptr %9, align 2, !tbaa !9
  %27 = zext i16 %26 to i32
  %28 = sub nsw i32 %25, %27
  %29 = trunc i32 %28 to i16
  store i16 %29, ptr %11, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #3
  %30 = load i32, ptr %7, align 4, !tbaa !11
  %31 = shl i32 1, %30
  %32 = sub nsw i32 %31, 1
  %33 = trunc i32 %32 to i16
  store i16 %33, ptr %12, align 2, !tbaa !9
  %34 = getelementptr inbounds %"class.ROHC::CProfile", ptr %14, i32 0, i32 12
  %35 = load i16, ptr %34, align 8, !tbaa !26
  %36 = zext i16 %35 to i32
  %37 = load i16, ptr %12, align 2, !tbaa !9
  %38 = zext i16 %37 to i32
  %39 = xor i32 %38, -1
  %40 = and i32 %36, %39
  %41 = load i16, ptr %6, align 2, !tbaa !9
  %42 = zext i16 %41 to i32
  %43 = load i16, ptr %12, align 2, !tbaa !9
  %44 = zext i16 %43 to i32
  %45 = and i32 %42, %44
  %46 = or i32 %40, %45
  %47 = trunc i32 %46 to i16
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  store i16 %47, ptr %48, align 2, !tbaa !9
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = load i16, ptr %49, align 2, !tbaa !9
  %51 = zext i16 %50 to i32
  %52 = load i16, ptr %11, align 2, !tbaa !9
  %53 = zext i16 %52 to i32
  %54 = icmp slt i32 %51, %53
  br i1 %54, label %55, label %65

55:                                               ; preds = %4
  %56 = load i32, ptr %7, align 4, !tbaa !11
  %57 = shl i32 1, %56
  %58 = trunc i32 %57 to i16
  %59 = zext i16 %58 to i32
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = load i16, ptr %60, align 2, !tbaa !9
  %62 = zext i16 %61 to i32
  %63 = add nsw i32 %62, %59
  %64 = trunc i32 %63 to i16
  store i16 %64, ptr %60, align 2, !tbaa !9
  br label %65

65:                                               ; preds = %55, %4
  call void @llvm.lifetime.start.p0(i64 2, ptr %13) #3
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = load i16, ptr %66, align 2, !tbaa !9
  %68 = zext i16 %67 to i32
  %69 = load i16, ptr %10, align 2, !tbaa !9
  %70 = zext i16 %69 to i32
  %71 = sub nsw i32 %68, %70
  %72 = trunc i32 %71 to i16
  store i16 %72, ptr %13, align 2, !tbaa !9
  %73 = load i16, ptr %13, align 2, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 2, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #3
  ret i16 %73
}

attributes #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 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !21, i64 136}
!14 = !{!"_ZTSN4ROHC8CProfileE", !6, i64 8, !10, i64 16, !15, i64 24, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !15, i64 48, !15, i64 56, !12, i64 64, !12, i64 68, !10, i64 72, !16, i64 80, !21, i64 136, !22, i64 140, !23, i64 144, !24, i64 148, !12, i64 152, !12, i64 156, !25, i64 160, !10, i64 180, !10, i64 182, !16, i64 184, !7, i64 240}
!15 = !{!"long", !7, i64 0}
!16 = !{!"_ZTSN4ROHC4WLSBIiEE", !17, i64 0, !15, i64 24, !15, i64 32, !15, i64 40, !12, i64 48, !12, i64 52}
!17 = !{!"_ZTSSt6vectorIN4ROHC4WLSBIiE3LSBESaIS3_EE", !18, i64 0}
!18 = !{!"_ZTSSt12_Vector_baseIN4ROHC4WLSBIiE3LSBESaIS3_EE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseIN4ROHC4WLSBIiE3LSBESaIS3_EE12_Vector_implE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseIN4ROHC4WLSBIiE3LSBESaIS3_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!21 = !{!"_ZTSN4ROHC12Reordering_tE", !7, i64 0}
!22 = !{!"_ZTSN4ROHC15IPIDBehaviour_tE", !7, i64 0}
!23 = !{!"bool", !7, i64 0}
!24 = !{!"_ZTSN4ROHC8CProfileUt_E", !7, i64 0}
!25 = !{!"_ZTSN4ROHC5iphdrE", !7, i64 0, !7, i64 0, !7, i64 1, !10, i64 2, !10, i64 4, !10, i64 6, !7, i64 8, !7, i64 9, !10, i64 10, !12, i64 12, !12, i64 16}
!26 = !{!14, !10, i64 72}


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

declare noundef i32 @_ZN4ROHC23LSBWindowPForReorderingENS_12Reordering_tEm(i32 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i16 @_ZNK4ROHC8CProfile9UpdateMSNEtjRt(ptr nocapture noundef nonnull readonly align 8 dereferenceable(328) %0, i16 noundef zeroext %1, i32 noundef %2, ptr nocapture noundef nonnull writeonly align 2 dereferenceable(2) %3) local_unnamed_addr #1 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 136
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = zext i32 %2 to i64
  %8 = tail call noundef i32 @_ZN4ROHC23LSBWindowPForReorderingENS_12Reordering_tEm(i32 noundef %6, i64 noundef %7)
  %9 = getelementptr inbounds i8, ptr %0, i64 72
  %10 = load i16, ptr %9, align 8, !tbaa !23
  %11 = zext i16 %10 to i32
  %12 = trunc i32 %8 to i16
  %13 = sub i16 %10, %12
  %14 = shl nuw i32 1, %2
  %15 = add nuw i32 %14, 65535
  %16 = sub i32 0, %14
  %17 = and i32 %11, %16
  %18 = zext i16 %1 to i32
  %19 = and i32 %15, %18
  %20 = or i32 %17, %19
  %21 = zext i16 %13 to i32
  %22 = icmp ult i32 %20, %21
  %23 = select i1 %22, i32 %14, i32 0
  %spec.select = add nuw i32 %23, %20
  %storemerge = trunc i32 %spec.select to i16
  store i16 %storemerge, ptr %3, align 2, !tbaa !24
  %24 = sub i16 %storemerge, %10
  ret i16 %24
}

attributes #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 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, !18, i64 136}
!6 = !{!"_ZTSN4ROHC8CProfileE", !7, i64 8, !10, i64 16, !11, i64 24, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !11, i64 48, !11, i64 56, !12, i64 64, !12, i64 68, !10, i64 72, !13, i64 80, !18, i64 136, !19, i64 140, !20, i64 144, !21, i64 148, !12, i64 152, !12, i64 156, !22, i64 160, !10, i64 180, !10, i64 182, !13, i64 184, !8, i64 240}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!"_ZTSN4ROHC4WLSBIiEE", !14, i64 0, !11, i64 24, !11, i64 32, !11, i64 40, !12, i64 48, !12, i64 52}
!14 = !{!"_ZTSSt6vectorIN4ROHC4WLSBIiE3LSBESaIS3_EE", !15, i64 0}
!15 = !{!"_ZTSSt12_Vector_baseIN4ROHC4WLSBIiE3LSBESaIS3_EE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIN4ROHC4WLSBIiE3LSBESaIS3_EE12_Vector_implE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIN4ROHC4WLSBIiE3LSBESaIS3_EE17_Vector_impl_dataE", !7, i64 0, !7, i64 8, !7, i64 16}
!18 = !{!"_ZTSN4ROHC12Reordering_tE", !8, i64 0}
!19 = !{!"_ZTSN4ROHC15IPIDBehaviour_tE", !8, i64 0}
!20 = !{!"bool", !8, i64 0}
!21 = !{!"_ZTSN4ROHC8CProfileUt_E", !8, i64 0}
!22 = !{!"_ZTSN4ROHC5iphdrE", !8, i64 0, !8, i64 0, !8, i64 1, !10, i64 2, !10, i64 4, !10, i64 6, !8, i64 8, !8, i64 9, !10, i64 10, !12, i64 12, !12, i64 16}
!23 = !{!6, !10, i64 72}
!24 = !{!10, !10, i64 0}


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