; LLVM IR from yinqiwen/ardb :: src/common/buffer/buffer_helper.ll (ZN4ardb12BufferHelper13WriteFixInt16ERNS_6BufferEsb)

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZN4ardb6Buffer5WriteEPKvm(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef, i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4ardb12BufferHelper13WriteFixInt16ERNS_6BufferEsb(ptr noundef nonnull align 8 dereferenceable(33) %0, i16 noundef signext %1, i1 noundef zeroext %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i16 %1, ptr %5, align 2, !tbaa !9
  %7 = zext i1 %2 to i8
  store i8 %7, ptr %6, align 1, !tbaa !11
  %8 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %9 = trunc i8 %8 to i1
  %10 = zext i1 %9 to i32
  %11 = call noundef zeroext i1 @_ZN4ardb12is_bigendianEv()
  %12 = zext i1 %11 to i32
  %13 = icmp ne i32 %10, %12
  br i1 %13, label %14, label %17

14:                                               ; preds = %3
  %15 = load i16, ptr %5, align 2, !tbaa !9
  %16 = call noundef signext i16 @_ZN4ardb10swap_int16Es(i16 noundef signext %15)
  store i16 %16, ptr %5, align 2, !tbaa !9
  br label %17

17:                                               ; preds = %14, %3
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = call noundef i32 @_ZN4ardb6Buffer5WriteEPKvm(ptr noundef nonnull align 8 dereferenceable(33) %18, ptr noundef %5, i64 noundef 2)
  %20 = sext i32 %19 to i64
  %21 = icmp eq i64 8, %20
  ret i1 %21
}

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 = { inlinehint 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 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, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}


; 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 i1 @_ZN4ardb12is_bigendianEv() local_unnamed_addr #0

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZN4ardb6Buffer5WriteEPKvm(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef, i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4ardb12BufferHelper13WriteFixInt16ERNS_6BufferEsb(ptr noundef nonnull align 8 dereferenceable(33) %0, i16 noundef signext %1, i1 noundef zeroext %2) local_unnamed_addr #2 align 2 {
  %4 = alloca i16, align 2
  store i16 %1, ptr %4, align 2, !tbaa !5
  %5 = tail call noundef zeroext i1 @_ZN4ardb12is_bigendianEv()
  %6 = xor i1 %5, %2
  br i1 %6, label %7, label %9

7:                                                ; preds = %3
  %8 = tail call noundef signext i16 @_ZN4ardb10swap_int16Es(i16 noundef signext %1)
  store i16 %8, ptr %4, align 2, !tbaa !5
  br label %9

9:                                                ; preds = %7, %3
  %10 = call noundef i32 @_ZN4ardb6Buffer5WriteEPKvm(ptr noundef nonnull align 8 dereferenceable(33) %0, ptr noundef nonnull %4, i64 noundef 2)
  %11 = icmp eq i32 %10, 8
  ret i1 %11
}

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 = { inlinehint 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 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,ReassociatePass,SROAPass,TailCallElimPass