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

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4ardb12BufferHelper12ReadFixInt16ERNS_6BufferERsb(ptr noundef nonnull align 8 dereferenceable(33) %0, ptr noundef nonnull align 2 dereferenceable(2) %1, i1 noundef zeroext %2) #3 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i16, align 2
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  %10 = zext i1 %2 to i8
  store i8 %10, ptr %7, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #4
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call noundef i32 @_ZN4ardb6Buffer4ReadEPvm(ptr noundef nonnull align 8 dereferenceable(33) %11, ptr noundef %8, i64 noundef 2)
  %13 = sext i32 %12 to i64
  %14 = icmp ne i64 %13, 2
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %31

16:                                               ; preds = %3
  %17 = load i8, ptr %7, align 1, !tbaa !9, !range !11, !noundef !12
  %18 = trunc i8 %17 to i1
  %19 = zext i1 %18 to i32
  %20 = call noundef zeroext i1 @_ZN4ardb12is_bigendianEv()
  %21 = zext i1 %20 to i32
  %22 = icmp eq i32 %19, %21
  br i1 %22, label %23, label %26

23:                                               ; preds = %16
  %24 = load i16, ptr %8, align 2, !tbaa !13
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  store i16 %24, ptr %25, align 2, !tbaa !13
  br label %30

26:                                               ; preds = %16
  %27 = load i16, ptr %8, align 2, !tbaa !13
  %28 = call noundef signext i16 @_ZN4ardb10swap_int16Es(i16 noundef signext %27)
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  store i16 %28, ptr %29, align 2, !tbaa !13
  br label %30

30:                                               ; preds = %26, %23
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %31

31:                                               ; preds = %30, %15
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #4
  %32 = load i1, ptr %4, align 1
  ret i1 %32
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { 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 #4 = { 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 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4ardb12BufferHelper12ReadFixInt16ERNS_6BufferERsb(ptr noundef nonnull align 8 dereferenceable(33) %0, ptr nocapture noundef nonnull writeonly align 2 dereferenceable(2) %1, i1 noundef zeroext %2) local_unnamed_addr #3 align 2 {
  %4 = alloca i16, align 2
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %4) #4
  %5 = call noundef i32 @_ZN4ardb6Buffer4ReadEPvm(ptr noundef nonnull align 8 dereferenceable(33) %0, ptr noundef nonnull %4, i64 noundef 2)
  %.not = icmp eq i32 %5, 2
  br i1 %.not, label %6, label %13

6:                                                ; preds = %3
  %7 = call noundef zeroext i1 @_ZN4ardb12is_bigendianEv()
  %8 = xor i1 %7, %2
  %9 = load i16, ptr %4, align 2, !tbaa !5
  br i1 %8, label %10, label %12

10:                                               ; preds = %6
  %11 = call noundef signext i16 @_ZN4ardb10swap_int16Es(i16 noundef signext %9)
  br label %12

12:                                               ; preds = %6, %10
  %storemerge = phi i16 [ %11, %10 ], [ %9, %6 ]
  store i16 %storemerge, ptr %1, align 2, !tbaa !5
  br label %13

13:                                               ; preds = %3, %12
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %4) #4
  ret i1 %.not
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { 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 #4 = { 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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