; LLVM IR from devantler/software-engineering-f22-shared :: IOT/BudgetManagementExcercise-03-28/ESP-Project/components/components/nghttp (ccitt)

; 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: nounwind uwtable
define dso_local zeroext i16 @calc_crc_16_ccitt(ptr noundef %0, i64 noundef %1, i16 noundef zeroext %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i16, align 2
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i16 %2, ptr %6, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %10 = load i16, ptr %6, align 2, !tbaa !11
  %11 = zext i16 %10 to i32
  %12 = shl i32 %11, 8
  store i32 %12, ptr %9, align 4, !tbaa !13
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %13

13:                                               ; preds = %43, %3
  %14 = load i64, ptr %7, align 8, !tbaa !9
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = icmp ult i64 %14, %15
  br i1 %16, label %17, label %46

17:                                               ; preds = %13
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i32 1
  store ptr %19, ptr %4, align 8, !tbaa !5
  %20 = load i8, ptr %18, align 1, !tbaa !15
  %21 = zext i8 %20 to i32
  %22 = load i32, ptr %9, align 4, !tbaa !13
  %23 = or i32 %22, %21
  store i32 %23, ptr %9, align 4, !tbaa !13
  store i32 0, ptr %8, align 4, !tbaa !13
  br label %24

24:                                               ; preds = %39, %17
  %25 = load i32, ptr %8, align 4, !tbaa !13
  %26 = icmp ult i32 %25, 8
  br i1 %26, label %27, label %42

27:                                               ; preds = %24
  %28 = load i32, ptr %9, align 4, !tbaa !13
  %29 = shl i32 %28, 1
  store i32 %29, ptr %9, align 4, !tbaa !13
  %30 = load i32, ptr %9, align 4, !tbaa !13
  %31 = and i32 %30, 16777216
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %38

33:                                               ; preds = %27
  %34 = load i32, ptr %9, align 4, !tbaa !13
  %35 = zext i32 %34 to i64
  %36 = xor i64 %35, 17834240
  %37 = trunc i64 %36 to i32
  store i32 %37, ptr %9, align 4, !tbaa !13
  br label %38

38:                                               ; preds = %33, %27
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %8, align 4, !tbaa !13
  %41 = add i32 %40, 1
  store i32 %41, ptr %8, align 4, !tbaa !13
  br label %24, !llvm.loop !16

42:                                               ; preds = %24
  br label %43

43:                                               ; preds = %42
  %44 = load i64, ptr %7, align 8, !tbaa !9
  %45 = add i64 %44, 1
  store i64 %45, ptr %7, align 8, !tbaa !9
  br label %13, !llvm.loop !18

46:                                               ; preds = %13
  %47 = load i32, ptr %9, align 4, !tbaa !13
  %48 = lshr i32 %47, 8
  %49 = trunc i32 %48 to i16
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret i16 %49
}

; 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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local zeroext i16 @calc_crc_16_ccitt(ptr nocapture noundef readonly %0, i64 noundef %1, i16 noundef zeroext %2) local_unnamed_addr #0 {
  %.not19 = icmp eq i64 %1, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %4 = zext i16 %2 to i32
  %5 = shl nuw nsw i32 %4, 8
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.018 = phi i32 [ %spec.select.7, %.lr.ph ], [ %5, %.lr.ph.preheader ]
  %.01217 = phi i64 [ %34, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %.01316 = phi ptr [ %33, %.lr.ph ], [ %0, %.lr.ph.preheader ]
  %6 = load i8, ptr %.01316, align 1, !tbaa !5
  %7 = zext i8 %6 to i32
  %8 = or i32 %.018, %7
  %9 = shl i32 %8, 1
  %10 = and i32 %.018, 8388608
  %.not = icmp eq i32 %10, 0
  %11 = xor i32 %9, 17834240
  %spec.select = select i1 %.not, i32 %9, i32 %11
  %12 = shl i32 %spec.select, 1
  %13 = and i32 %spec.select, 8388608
  %.not.1 = icmp eq i32 %13, 0
  %14 = xor i32 %12, 17834240
  %spec.select.1 = select i1 %.not.1, i32 %12, i32 %14
  %15 = shl i32 %spec.select.1, 1
  %16 = and i32 %spec.select.1, 8388608
  %.not.2 = icmp eq i32 %16, 0
  %17 = xor i32 %15, 17834240
  %spec.select.2 = select i1 %.not.2, i32 %15, i32 %17
  %18 = shl i32 %spec.select.2, 1
  %19 = and i32 %spec.select.2, 8388608
  %.not.3 = icmp eq i32 %19, 0
  %20 = xor i32 %18, 17834240
  %spec.select.3 = select i1 %.not.3, i32 %18, i32 %20
  %21 = shl i32 %spec.select.3, 1
  %22 = and i32 %spec.select.3, 8388608
  %.not.4 = icmp eq i32 %22, 0
  %23 = xor i32 %21, 17834240
  %spec.select.4 = select i1 %.not.4, i32 %21, i32 %23
  %24 = shl i32 %spec.select.4, 1
  %25 = and i32 %spec.select.4, 8388608
  %.not.5 = icmp eq i32 %25, 0
  %26 = xor i32 %24, 17834240
  %spec.select.5 = select i1 %.not.5, i32 %24, i32 %26
  %27 = shl i32 %spec.select.5, 1
  %28 = and i32 %spec.select.5, 8388608
  %.not.6 = icmp eq i32 %28, 0
  %29 = xor i32 %27, 17834240
  %spec.select.6 = select i1 %.not.6, i32 %27, i32 %29
  %30 = shl i32 %spec.select.6, 1
  %31 = and i32 %spec.select.6, 8388608
  %.not.7 = icmp eq i32 %31, 0
  %32 = xor i32 %30, 17834240
  %spec.select.7 = select i1 %.not.7, i32 %30, i32 %32
  %33 = getelementptr inbounds i8, ptr %.01316, i64 1
  %34 = add nuw i64 %.01217, 1
  %exitcond.not = icmp eq i64 %34, %1
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !8

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %35 = lshr i32 %spec.select.7, 8
  %36 = trunc i32 %35 to i16
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %3
  %.0.lcssa = phi i16 [ %2, %3 ], [ %36, %._crit_edge.loopexit ]
  ret i16 %.0.lcssa
}

attributes #0 = { nofree norecurse nosync nounwind 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/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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