; LLVM IR from kkumatani/distant_speech_recognition :: btk20_src/common/mach_ind_io.ll (Z15check_byte_swapPsi)

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

@.str.21 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [102 x i8], align 1
@__PRETTY_FUNCTION__._Z15check_byte_swapPsi = external hidden unnamed_addr constant [34 x i8], align 1

; 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: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z15check_byte_swapPsi(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = icmp sge i32 %12, 139
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  br label %17

15:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.21, ptr noundef @.str.22, i32 noundef 1306, ptr noundef @__PRETTY_FUNCTION__._Z15check_byte_swapPsi) #5
  unreachable

16:                                               ; No predecessors!
  br label %17

17:                                               ; preds = %16, %14
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds i16, ptr %18, i64 128
  %20 = load i16, ptr %19, align 2, !tbaa !11
  %21 = sext i16 %20 to i32
  store i32 %21, ptr %9, align 4, !tbaa !9
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds i16, ptr %22, i64 128
  %24 = load i16, ptr %23, align 2, !tbaa !11
  %25 = sext i16 %24 to i32
  %26 = shl i32 %25, 8
  %27 = trunc i32 %26 to i16
  %28 = sext i16 %27 to i32
  %29 = and i32 65280, %28
  %30 = trunc i32 %29 to i16
  %31 = sext i16 %30 to i32
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds i16, ptr %32, i64 128
  %34 = load i16, ptr %33, align 2, !tbaa !11
  %35 = sext i16 %34 to i32
  %36 = ashr i32 %35, 8
  %37 = trunc i32 %36 to i16
  %38 = sext i16 %37 to i32
  %39 = and i32 255, %38
  %40 = trunc i32 %39 to i16
  %41 = sext i16 %40 to i32
  %42 = or i32 %31, %41
  %43 = trunc i32 %42 to i16
  %44 = sext i16 %43 to i32
  store i32 %44, ptr %10, align 4, !tbaa !9
  store i32 129, ptr %11, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %90, %17
  %46 = load i32, ptr %11, align 4, !tbaa !9
  %47 = icmp slt i32 %46, 139
  br i1 %47, label %48, label %93

48:                                               ; preds = %45
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = load i32, ptr %11, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i16, ptr %49, i64 %51
  %53 = load i16, ptr %52, align 2, !tbaa !11
  %54 = sext i16 %53 to i32
  store i32 %54, ptr %7, align 4, !tbaa !9
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = trunc i32 %55 to i16
  %57 = sext i16 %56 to i32
  %58 = shl i32 %57, 8
  %59 = trunc i32 %58 to i16
  %60 = sext i16 %59 to i32
  %61 = and i32 65280, %60
  %62 = trunc i32 %61 to i16
  %63 = sext i16 %62 to i32
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = trunc i32 %64 to i16
  %66 = sext i16 %65 to i32
  %67 = ashr i32 %66, 8
  %68 = trunc i32 %67 to i16
  %69 = sext i16 %68 to i32
  %70 = and i32 255, %69
  %71 = trunc i32 %70 to i16
  %72 = sext i16 %71 to i32
  %73 = or i32 %63, %72
  %74 = trunc i32 %73 to i16
  %75 = sext i16 %74 to i32
  store i32 %75, ptr %8, align 4, !tbaa !9
  %76 = load i32, ptr %7, align 4, !tbaa !9
  %77 = load i32, ptr %9, align 4, !tbaa !9
  %78 = sub nsw i32 %76, %77
  %79 = call i32 @llvm.abs.i32(i32 %78, i1 true)
  %80 = load i32, ptr %5, align 4, !tbaa !9
  %81 = add nsw i32 %80, %79
  store i32 %81, ptr %5, align 4, !tbaa !9
  %82 = load i32, ptr %8, align 4, !tbaa !9
  %83 = load i32, ptr %10, align 4, !tbaa !9
  %84 = sub nsw i32 %82, %83
  %85 = call i32 @llvm.abs.i32(i32 %84, i1 true)
  %86 = load i32, ptr %6, align 4, !tbaa !9
  %87 = add nsw i32 %86, %85
  store i32 %87, ptr %6, align 4, !tbaa !9
  %88 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %88, ptr %9, align 4, !tbaa !9
  %89 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %89, ptr %10, align 4, !tbaa !9
  br label %90

90:                                               ; preds = %48
  %91 = load i32, ptr %11, align 4, !tbaa !9
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %11, align 4, !tbaa !9
  br label %45, !llvm.loop !13

93:                                               ; preds = %45
  %94 = load i32, ptr %6, align 4, !tbaa !9
  %95 = load i32, ptr %5, align 4, !tbaa !9
  %96 = icmp slt i32 %94, %95
  %97 = zext i1 %96 to i32
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret i32 %97
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { noreturn nounwind "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind }
attributes #5 = { noreturn 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

@.str.21 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [102 x i8], align 1
@__PRETTY_FUNCTION__._Z15check_byte_swapPsi = external hidden unnamed_addr constant [34 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 0, 2) i32 @_Z15check_byte_swapPsi(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %1, 138
  br i1 %3, label %5, label %4

4:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.21, ptr noundef nonnull @.str.22, i32 noundef 1306, ptr noundef nonnull @__PRETTY_FUNCTION__._Z15check_byte_swapPsi) #4
  unreachable

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 256
  %7 = load i16, ptr %6, align 2, !tbaa !5
  %8 = sext i16 %7 to i32
  %9 = tail call i16 @llvm.bswap.i16(i16 %7)
  %10 = sext i16 %9 to i32
  %11 = getelementptr inbounds i8, ptr %0, i64 258
  %12 = load <8 x i16>, ptr %11, align 2, !tbaa !5
  %13 = tail call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %12)
  %14 = sext <8 x i16> %13 to <8 x i32>
  %15 = shufflevector <8 x i32> %14, <8 x i32> poison, <8 x i32> <i32 poison, i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6>
  %16 = insertelement <8 x i32> %15, i32 %10, i64 0
  %17 = sub nsw <8 x i32> %14, %16
  %18 = tail call <8 x i32> @llvm.abs.v8i32(<8 x i32> %17, i1 true)
  %19 = sext <8 x i16> %12 to <8 x i32>
  %20 = shufflevector <8 x i32> %19, <8 x i32> poison, <8 x i32> <i32 poison, i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6>
  %21 = insertelement <8 x i32> %20, i32 %8, i64 0
  %22 = sub nsw <8 x i32> %19, %21
  %23 = tail call <8 x i32> @llvm.abs.v8i32(<8 x i32> %22, i1 true)
  %24 = getelementptr inbounds i8, ptr %0, i64 274
  %25 = load i16, ptr %24, align 2, !tbaa !5
  %26 = sext i16 %25 to i32
  %27 = tail call i16 @llvm.bswap.i16(i16 %25)
  %28 = sext i16 %27 to i32
  %29 = extractelement <8 x i32> %19, i64 7
  %30 = sub nsw i32 %26, %29
  %31 = tail call i32 @llvm.abs.i32(i32 %30, i1 true)
  %32 = extractelement <8 x i32> %14, i64 7
  %33 = sub nsw i32 %28, %32
  %34 = tail call i32 @llvm.abs.i32(i32 %33, i1 true)
  %35 = getelementptr inbounds i8, ptr %0, i64 276
  %36 = load i16, ptr %35, align 2, !tbaa !5
  %37 = sext i16 %36 to i32
  %38 = tail call i16 @llvm.bswap.i16(i16 %36)
  %39 = sext i16 %38 to i32
  %40 = sub nsw i32 %37, %26
  %41 = tail call i32 @llvm.abs.i32(i32 %40, i1 true)
  %42 = tail call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> %23)
  %op.rdx31 = add i32 %42, %31
  %op.rdx32 = add i32 %op.rdx31, %41
  %43 = sub nsw i32 %39, %28
  %44 = tail call i32 @llvm.abs.i32(i32 %43, i1 true)
  %45 = tail call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> %18)
  %op.rdx = add i32 %45, %34
  %op.rdx30 = add i32 %op.rdx, %44
  %46 = icmp ult i32 %op.rdx30, %op.rdx32
  %47 = zext i1 %46 to i32
  ret i32 %47
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i16 @llvm.bswap.i16(i16) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <8 x i16> @llvm.bswap.v8i16(<8 x i16>) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <8 x i32> @llvm.abs.v8i32(<8 x i32>, i1 immarg) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v8i32(<8 x i32>) #3

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 = { noreturn nounwind "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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { noreturn 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,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass