; LLVM IR from dmr-goncalves/HumanAwareRobotNavigation :: src/husky/husky_base/src/horizon_legacy/crc.ll (Z5crc16iiPh)

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

@_ZL5table = external hidden constant [256 x i16], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i16 @_Z5crc16iiPh(i32 noundef %0, i32 noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i16, align 2
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #2
  %8 = load i32, ptr %5, align 4, !tbaa !5
  %9 = trunc i32 %8 to i16
  store i16 %9, ptr %7, align 2, !tbaa !11
  br label %10

10:                                               ; preds = %14, %3
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = add nsw i32 %11, -1
  store i32 %12, ptr %4, align 4, !tbaa !5
  %13 = icmp ne i32 %11, 0
  br i1 %13, label %14, label %33

14:                                               ; preds = %10
  %15 = load i16, ptr %7, align 2, !tbaa !11
  %16 = zext i16 %15 to i32
  %17 = shl i32 %16, 8
  %18 = load i16, ptr %7, align 2, !tbaa !11
  %19 = zext i16 %18 to i32
  %20 = ashr i32 %19, 8
  %21 = load ptr, ptr %6, align 8, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %21, i32 1
  store ptr %22, ptr %6, align 8, !tbaa !9
  %23 = load i8, ptr %21, align 1, !tbaa !13
  %24 = zext i8 %23 to i32
  %25 = xor i32 %20, %24
  %26 = and i32 %25, 255
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [256 x i16], ptr @_ZL5table, i64 0, i64 %27
  %29 = load i16, ptr %28, align 2, !tbaa !11
  %30 = zext i16 %29 to i32
  %31 = xor i32 %17, %30
  %32 = trunc i32 %31 to i16
  store i16 %32, ptr %7, align 2, !tbaa !11
  br label %10, !llvm.loop !14

33:                                               ; preds = %10
  %34 = load i16, ptr %7, align 2, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #2
  ret i16 %34
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@_ZL5table = external hidden local_unnamed_addr constant [256 x i16], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i16 @_Z5crc16iiPh(i32 noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %.not7 = icmp eq i32 %0, 0
  br i1 %.not7, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %xtraiter = and i32 %0, 1
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader
  %4 = add nsw i32 %0, -1
  %5 = shl i32 %1, 8
  %6 = and i32 %5, 16776960
  %7 = lshr i32 %1, 8
  %8 = getelementptr inbounds i8, ptr %2, i64 1
  %9 = load i8, ptr %2, align 1, !tbaa !5
  %.tr.prol = trunc i32 %7 to i8
  %.narrow.prol = xor i8 %9, %.tr.prol
  %10 = zext i8 %.narrow.prol to i64
  %11 = getelementptr inbounds [256 x i16], ptr @_ZL5table, i64 0, i64 %10
  %12 = load i16, ptr %11, align 2, !tbaa !8
  %13 = zext i16 %12 to i32
  %14 = xor i32 %6, %13
  br label %.lr.ph.prol.loopexit

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.lcssa.unr = phi i32 [ poison, %.lr.ph.preheader ], [ %14, %.lr.ph.prol ]
  %.0.in10.unr = phi i32 [ %1, %.lr.ph.preheader ], [ %14, %.lr.ph.prol ]
  %.059.unr = phi ptr [ %2, %.lr.ph.preheader ], [ %8, %.lr.ph.prol ]
  %.068.unr = phi i32 [ %0, %.lr.ph.preheader ], [ %4, %.lr.ph.prol ]
  %15 = icmp eq i32 %0, 1
  br i1 %15, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.0.in10 = phi i32 [ %36, %.lr.ph ], [ %.0.in10.unr, %.lr.ph.prol.loopexit ]
  %.059 = phi ptr [ %30, %.lr.ph ], [ %.059.unr, %.lr.ph.prol.loopexit ]
  %.068 = phi i32 [ %26, %.lr.ph ], [ %.068.unr, %.lr.ph.prol.loopexit ]
  %16 = shl i32 %.0.in10, 8
  %17 = and i32 %16, 16776960
  %18 = lshr i32 %.0.in10, 8
  %19 = getelementptr inbounds i8, ptr %.059, i64 1
  %20 = load i8, ptr %.059, align 1, !tbaa !5
  %.tr = trunc i32 %18 to i8
  %.narrow = xor i8 %20, %.tr
  %21 = zext i8 %.narrow to i64
  %22 = getelementptr inbounds [256 x i16], ptr @_ZL5table, i64 0, i64 %21
  %23 = load i16, ptr %22, align 2, !tbaa !8
  %24 = zext i16 %23 to i32
  %25 = xor i32 %17, %24
  %26 = add nsw i32 %.068, -2
  %27 = shl nuw i32 %25, 8
  %28 = and i32 %27, 16776960
  %29 = lshr i32 %25, 8
  %30 = getelementptr inbounds i8, ptr %.059, i64 2
  %31 = load i8, ptr %19, align 1, !tbaa !5
  %.tr.1 = trunc i32 %29 to i8
  %.narrow.1 = xor i8 %31, %.tr.1
  %32 = zext i8 %.narrow.1 to i64
  %33 = getelementptr inbounds [256 x i16], ptr @_ZL5table, i64 0, i64 %32
  %34 = load i16, ptr %33, align 2, !tbaa !8
  %35 = zext i16 %34 to i32
  %36 = xor i32 %28, %35
  %.not.1 = icmp eq i32 %26, 0
  br i1 %.not.1, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %3
  %.0.in.lcssa = phi i32 [ %1, %3 ], [ %.lcssa.unr, %.lr.ph.prol.loopexit ], [ %36, %.lr.ph ]
  %.0 = trunc i32 %.0.in.lcssa to i16
  ret i16 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"short", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass