; LLVM IR from whoiswelliton/Computer_Engineering_UTFPR-PB :: Embedded_Systems/TIVA Connected TM4C1294XL Projects/01 - lwIP_HTTPServer_on_TIVA (pbuf)

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

%struct.pbuf = type { ptr, ptr, i16, i16, i8, i8, i8, i8 }

; Function Attrs: nounwind uwtable
declare dso_local zeroext i16 @lwip_standard_chksum(ptr noundef, i32 noundef) #0

; 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

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

7:                                                ; preds = %49, %1
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %53

10:                                               ; preds = %7
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.pbuf, ptr %11, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.pbuf, ptr %14, i32 0, i32 3
  %16 = load i16, ptr %15, align 2, !tbaa !14
  %17 = zext i16 %16 to i32
  %18 = call zeroext i16 @lwip_standard_chksum(ptr noundef %13, i32 noundef %17)
  %19 = zext i16 %18 to i32
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = add i32 %20, %19
  store i32 %21, ptr %3, align 4, !tbaa !9
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = lshr i32 %22, 16
  %24 = zext i32 %23 to i64
  %25 = load i32, ptr %3, align 4, !tbaa !9
  %26 = zext i32 %25 to i64
  %27 = and i64 %26, 65535
  %28 = add i64 %24, %27
  %29 = trunc i64 %28 to i32
  store i32 %29, ptr %3, align 4, !tbaa !9
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.pbuf, ptr %30, i32 0, i32 3
  %32 = load i16, ptr %31, align 2, !tbaa !14
  %33 = zext i16 %32 to i32
  %34 = srem i32 %33, 2
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %48

36:                                               ; preds = %10
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = icmp ne i32 %37, 0
  %39 = xor i1 %38, true
  %40 = zext i1 %39 to i32
  store i32 %40, ptr %5, align 4, !tbaa !9
  %41 = load i32, ptr %3, align 4, !tbaa !9
  %42 = and i32 %41, 255
  %43 = shl i32 %42, 8
  %44 = load i32, ptr %3, align 4, !tbaa !9
  %45 = and i32 %44, 65280
  %46 = lshr i32 %45, 8
  %47 = or i32 %43, %46
  store i32 %47, ptr %3, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %36, %10
  br label %49

49:                                               ; preds = %48
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.pbuf, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !15
  store ptr %52, ptr %4, align 8, !tbaa !5
  br label %7, !llvm.loop !16

53:                                               ; preds = %7
  %54 = load i32, ptr %5, align 4, !tbaa !9
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %64

56:                                               ; preds = %53
  %57 = load i32, ptr %3, align 4, !tbaa !9
  %58 = and i32 %57, 255
  %59 = shl i32 %58, 8
  %60 = load i32, ptr %3, align 4, !tbaa !9
  %61 = and i32 %60, 65280
  %62 = lshr i32 %61, 8
  %63 = or i32 %59, %62
  store i32 %63, ptr %3, align 4, !tbaa !9
  br label %64

64:                                               ; preds = %56, %53
  %65 = load i32, ptr %3, align 4, !tbaa !9
  %66 = zext i32 %65 to i64
  %67 = and i64 %66, 65535
  %68 = xor i64 %67, -1
  %69 = trunc i64 %68 to i16
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i16 %69
}

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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"pbuf", !6, i64 0, !6, i64 8, !13, i64 16, !13, i64 18, !7, i64 20, !7, i64 21, !7, i64 22, !7, i64 23}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !13, i64 18}
!15 = !{!12, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

; Function Attrs: nounwind uwtable
declare dso_local zeroext i16 @lwip_standard_chksum(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i16 @inet_chksum_pbuf(ptr noundef readonly %0) local_unnamed_addr #0 {
  %.not23 = icmp eq ptr %0, null
  br i1 %.not23, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %1, %17
  %.026 = phi i32 [ %.1, %17 ], [ 0, %1 ]
  %.01525 = phi ptr [ %18, %17 ], [ %0, %1 ]
  %.01624 = phi i32 [ %.117, %17 ], [ 0, %1 ]
  %2 = getelementptr inbounds i8, ptr %.01525, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %.01525, i64 18
  %5 = load i16, ptr %4, align 2, !tbaa !11
  %6 = zext i16 %5 to i32
  %7 = tail call zeroext i16 @lwip_standard_chksum(ptr noundef %3, i32 noundef %6)
  %8 = zext i16 %7 to i32
  %9 = add nuw nsw i32 %.01624, %8
  %10 = lshr i32 %9, 16
  %11 = and i32 %9, 65535
  %narrow = add nuw nsw i32 %10, %11
  %12 = load i16, ptr %4, align 2, !tbaa !11
  %13 = and i16 %12, 1
  %.not19 = icmp eq i16 %13, 0
  br i1 %.not19, label %17, label %14

14:                                               ; preds = %.lr.ph
  %.not20 = icmp eq i32 %.026, 0
  %15 = zext i1 %.not20 to i32
  %trunc21 = trunc i32 %narrow to i16
  %rev22 = tail call i16 @llvm.bswap.i16(i16 %trunc21)
  %16 = zext i16 %rev22 to i32
  br label %17

17:                                               ; preds = %.lr.ph, %14
  %.117 = phi i32 [ %16, %14 ], [ %narrow, %.lr.ph ]
  %.1 = phi i32 [ %15, %14 ], [ %.026, %.lr.ph ]
  %18 = load ptr, ptr %.01525, align 8, !tbaa !12
  %.not = icmp eq ptr %18, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %17
  %19 = icmp eq i32 %.1, 0
  %trunc = trunc i32 %.117 to i16
  %rev = tail call i16 @llvm.bswap.i16(i16 %trunc)
  %20 = zext i16 %rev to i32
  %spec.select = select i1 %19, i32 %.117, i32 %20
  %21 = trunc i32 %spec.select to i16
  %22 = xor i16 %21, -1
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %._crit_edge, %1
  %23 = phi i16 [ -1, %1 ], [ %22, %._crit_edge ]
  ret i16 %23
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i16 @llvm.bswap.i16(i16) #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 speculatable willreturn memory(none) }

!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, !7, i64 8}
!6 = !{!"pbuf", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 18, !8, i64 20, !8, i64 21, !8, i64 22, !8, i64 23}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!6, !10, i64 18}
!12 = !{!6, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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