; LLVM IR from Columbitech/rohc :: src/dprofile.ll (ZN4ROHC8DProfile22UpdateIPIDOffsetFromIDEv)

; 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::DProfile" = type <{ ptr, ptr, i16, [2 x i8], i32, i16, i16, i32, i32, i32, i64, i64, i8, [3 x i8], %"struct.ROHC::iphdr", i64, i32, [4 x i8] }>
%"struct.ROHC::iphdr" = type { i8, i8, i16, i16, i16, i8, i8, i16, i32, i32 }

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i16 @_ZN4ROHC10rohc_htonsEt(i16 noundef zeroext) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4ROHC8DProfile22UpdateIPIDOffsetFromIDEv(ptr noundef nonnull align 8 dereferenceable(92) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  %4 = getelementptr inbounds %"class.ROHC::DProfile", ptr %3, i32 0, i32 7
  %5 = load i32, ptr %4, align 4, !tbaa !9
  %6 = icmp eq i32 0, %5
  br i1 %6, label %7, label %19

7:                                                ; preds = %1
  %8 = getelementptr inbounds %"class.ROHC::DProfile", ptr %3, i32 0, i32 14
  %9 = getelementptr inbounds %"struct.ROHC::iphdr", ptr %8, i32 0, i32 3
  %10 = load i16, ptr %9, align 4, !tbaa !19
  %11 = call noundef zeroext i16 @_ZN4ROHC10rohc_htonsEt(i16 noundef zeroext %10)
  %12 = zext i16 %11 to i32
  %13 = getelementptr inbounds %"class.ROHC::DProfile", ptr %3, i32 0, i32 5
  %14 = load i16, ptr %13, align 8, !tbaa !20
  %15 = zext i16 %14 to i32
  %16 = sub nsw i32 %12, %15
  %17 = trunc i32 %16 to i16
  %18 = getelementptr inbounds %"class.ROHC::DProfile", ptr %3, i32 0, i32 6
  store i16 %17, ptr %18, align 2, !tbaa !21
  br label %35

19:                                               ; preds = %1
  %20 = getelementptr inbounds %"class.ROHC::DProfile", ptr %3, i32 0, i32 7
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = icmp eq i32 1, %21
  br i1 %22, label %23, label %34

23:                                               ; preds = %19
  %24 = getelementptr inbounds %"class.ROHC::DProfile", ptr %3, i32 0, i32 14
  %25 = getelementptr inbounds %"struct.ROHC::iphdr", ptr %24, i32 0, i32 3
  %26 = load i16, ptr %25, align 4, !tbaa !19
  %27 = zext i16 %26 to i32
  %28 = getelementptr inbounds %"class.ROHC::DProfile", ptr %3, i32 0, i32 5
  %29 = load i16, ptr %28, align 8, !tbaa !20
  %30 = zext i16 %29 to i32
  %31 = sub nsw i32 %27, %30
  %32 = trunc i32 %31 to i16
  %33 = getelementptr inbounds %"class.ROHC::DProfile", ptr %3, i32 0, i32 6
  store i16 %32, ptr %33, align 2, !tbaa !21
  br label %34

34:                                               ; preds = %23, %19
  br label %35

35:                                               ; preds = %34, %7
  ret void
}

attributes #0 = { 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 #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !13, i64 28}
!10 = !{!"_ZTSN4ROHC8DProfileE", !6, i64 8, !11, i64 16, !12, i64 20, !11, i64 24, !11, i64 26, !13, i64 28, !14, i64 32, !14, i64 36, !15, i64 40, !15, i64 48, !16, i64 56, !17, i64 60, !15, i64 80, !18, i64 88}
!11 = !{!"short", !7, i64 0}
!12 = !{!"_ZTSN4ROHC8DProfileUt_E", !7, i64 0}
!13 = !{!"_ZTSN4ROHC15IPIDBehaviour_tE", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{!"_ZTSN4ROHC5iphdrE", !7, i64 0, !7, i64 0, !7, i64 1, !11, i64 2, !11, i64 4, !11, i64 6, !7, i64 8, !7, i64 9, !11, i64 10, !14, i64 12, !14, i64 16}
!18 = !{!"_ZTSN4ROHC12Reordering_tE", !7, i64 0}
!19 = !{!10, !11, i64 64}
!20 = !{!10, !11, i64 24}
!21 = !{!10, !11, i64 26}


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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i16 @_ZN4ROHC10rohc_htonsEt(i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4ROHC8DProfile22UpdateIPIDOffsetFromIDEv(ptr nocapture noundef nonnull align 8 dereferenceable(92) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 28
  %3 = load i32, ptr %2, align 4, !tbaa !5
  switch i32 %3, label %15 [
    i32 0, label %4
    i32 1, label %8
  ]

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 64
  %6 = load i16, ptr %5, align 8, !tbaa !18
  %7 = tail call noundef zeroext i16 @_ZN4ROHC10rohc_htonsEt(i16 noundef zeroext %6)
  br label %.sink.split

8:                                                ; preds = %1
  %9 = getelementptr inbounds i8, ptr %0, i64 64
  %10 = load i16, ptr %9, align 8, !tbaa !18
  br label %.sink.split

.sink.split:                                      ; preds = %4, %8
  %.sink2 = phi i16 [ %10, %8 ], [ %7, %4 ]
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  %12 = load i16, ptr %11, align 8, !tbaa !19
  %13 = sub i16 %.sink2, %12
  %14 = getelementptr inbounds i8, ptr %0, i64 26
  store i16 %13, ptr %14, align 2, !tbaa !20
  br label %15

15:                                               ; preds = %.sink.split, %1
  ret void
}

attributes #0 = { 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 #1 = { 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, !12, i64 28}
!6 = !{!"_ZTSN4ROHC8DProfileE", !7, i64 8, !10, i64 16, !11, i64 20, !10, i64 24, !10, i64 26, !12, i64 28, !13, i64 32, !13, i64 36, !14, i64 40, !14, i64 48, !15, i64 56, !16, i64 60, !14, i64 80, !17, i64 88}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"_ZTSN4ROHC8DProfileUt_E", !8, i64 0}
!12 = !{!"_ZTSN4ROHC15IPIDBehaviour_tE", !8, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!"long", !8, i64 0}
!15 = !{!"bool", !8, i64 0}
!16 = !{!"_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, !13, i64 12, !13, i64 16}
!17 = !{!"_ZTSN4ROHC12Reordering_tE", !8, i64 0}
!18 = !{!6, !10, i64 64}
!19 = !{!6, !10, i64 24}
!20 = !{!6, !10, i64 26}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass