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

; 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: mustprogress uwtable
define dso_local void @_ZN4ROHC8DProfile20UpdateIPIDFromOffsetEv(ptr noundef nonnull align 8 dereferenceable(92) %0) #0 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 5
  %9 = load i16, ptr %8, align 8, !tbaa !19
  %10 = zext i16 %9 to i32
  %11 = getelementptr inbounds %"class.ROHC::DProfile", ptr %3, i32 0, i32 6
  %12 = load i16, ptr %11, align 2, !tbaa !20
  %13 = zext i16 %12 to i32
  %14 = add nsw i32 %10, %13
  %15 = trunc i32 %14 to i16
  %16 = call noundef zeroext i16 @_ZN4ROHC10rohc_htonsEt(i16 noundef zeroext %15)
  %17 = getelementptr inbounds %"class.ROHC::DProfile", ptr %3, i32 0, i32 14
  %18 = getelementptr inbounds %"struct.ROHC::iphdr", ptr %17, i32 0, i32 3
  store i16 %16, ptr %18, align 4, !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 5
  %25 = load i16, ptr %24, align 8, !tbaa !19
  %26 = zext i16 %25 to i32
  %27 = getelementptr inbounds %"class.ROHC::DProfile", ptr %3, i32 0, i32 6
  %28 = load i16, ptr %27, align 2, !tbaa !20
  %29 = zext i16 %28 to i32
  %30 = add nsw i32 %26, %29
  %31 = trunc i32 %30 to i16
  %32 = getelementptr inbounds %"class.ROHC::DProfile", ptr %3, i32 0, i32 14
  %33 = getelementptr inbounds %"struct.ROHC::iphdr", ptr %32, i32 0, i32 3
  store i16 %31, ptr %33, align 4, !tbaa !21
  br label %34

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i16 @_ZN4ROHC10rohc_htonsEt(i16 noundef zeroext) #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 = { 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" }

!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 24}
!20 = !{!10, !11, i64 26}
!21 = !{!10, !11, i64 64}


; 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: mustprogress nounwind uwtable
define dso_local void @_ZN4ROHC8DProfile20UpdateIPIDFromOffsetEv(ptr nocapture noundef nonnull align 8 dereferenceable(92) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 28
  %3 = load i32, ptr %2, align 4, !tbaa !5
  switch i32 %3, label %18 [
    i32 0, label %4
    i32 1, label %11
  ]

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

11:                                               ; preds = %1
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  %13 = load i16, ptr %12, align 8, !tbaa !18
  %14 = getelementptr inbounds i8, ptr %0, i64 26
  %15 = load i16, ptr %14, align 2, !tbaa !19
  %16 = add i16 %15, %13
  br label %.sink.split

.sink.split:                                      ; preds = %4, %11
  %.sink = phi i16 [ %16, %11 ], [ %10, %4 ]
  %17 = getelementptr inbounds i8, ptr %0, i64 64
  store i16 %.sink, ptr %17, align 8, !tbaa !20
  br label %18

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i16 @_ZN4ROHC10rohc_htonsEt(i16 noundef zeroext) local_unnamed_addr #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 = { 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" }

!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 24}
!19 = !{!6, !10, i64 26}
!20 = !{!6, !10, i64 64}


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