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

; 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.ip_reassdata = type { ptr, ptr, %struct.ip_hdr, i16, i8, i8 }
%struct.ip_hdr = type { i8, i8, i16, i16, i16, i8, i8, i16, %struct.ip4_addr_packed, %struct.ip4_addr_packed }
%struct.ip4_addr_packed = type { i32 }

@reassdatagrams = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @ip_reass_tmr() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #2
  store ptr null, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr @reassdatagrams, align 8, !tbaa !5
  store ptr %4, ptr %1, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %31, %0
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %32

8:                                                ; preds = %5
  %9 = load ptr, ptr %1, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.ip_reassdata, ptr %9, i32 0, i32 5
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = zext i8 %11 to i32
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %14, label %23

14:                                               ; preds = %8
  %15 = load ptr, ptr %1, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ip_reassdata, ptr %15, i32 0, i32 5
  %17 = load i8, ptr %16, align 1, !tbaa !9
  %18 = add i8 %17, -1
  store i8 %18, ptr %16, align 1, !tbaa !9
  %19 = load ptr, ptr %1, align 8, !tbaa !5
  store ptr %19, ptr %2, align 8, !tbaa !5
  %20 = load ptr, ptr %1, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ip_reassdata, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  store ptr %22, ptr %1, align 8, !tbaa !5
  br label %31

23:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %24 = load ptr, ptr %1, align 8, !tbaa !5
  store ptr %24, ptr %3, align 8, !tbaa !5
  %25 = load ptr, ptr %1, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ip_reassdata, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  store ptr %27, ptr %1, align 8, !tbaa !5
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = call i32 @ip_reass_free_complete_datagram(ptr noundef %28, ptr noundef %29)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  br label %31

31:                                               ; preds = %23, %14
  br label %5, !llvm.loop !16

32:                                               ; preds = %5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  ret void
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @ip_reass_free_complete_datagram(ptr noundef, ptr noundef) #0

; 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, !7, i64 39}
!10 = !{!"ip_reassdata", !6, i64 0, !6, i64 8, !11, i64 16, !12, i64 36, !7, i64 38, !7, i64 39}
!11 = !{!"ip_hdr", !7, i64 0, !7, i64 1, !12, i64 2, !12, i64 4, !12, i64 6, !7, i64 8, !7, i64 9, !12, i64 10, !13, i64 12, !13, i64 16}
!12 = !{!"short", !7, i64 0}
!13 = !{!"ip4_addr_packed", !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!10, !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"

@reassdatagrams = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @ip_reass_tmr() local_unnamed_addr #0 {
  %1 = load ptr, ptr @reassdatagrams, align 8, !tbaa !5
  %.not12 = icmp eq ptr %1, null
  br i1 %.not12, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %10
  %.014 = phi ptr [ %.1, %10 ], [ %1, %0 ]
  %.0913 = phi ptr [ %.110, %10 ], [ null, %0 ]
  %2 = getelementptr inbounds i8, ptr %.014, i64 39
  %3 = load i8, ptr %2, align 1, !tbaa !9
  %.not11 = icmp eq i8 %3, 0
  br i1 %.not11, label %7, label %4

4:                                                ; preds = %.lr.ph
  %5 = add i8 %3, -1
  store i8 %5, ptr %2, align 1, !tbaa !9
  %6 = load ptr, ptr %.014, align 8, !tbaa !15
  br label %10

7:                                                ; preds = %.lr.ph
  %8 = load ptr, ptr %.014, align 8, !tbaa !15
  %9 = tail call i32 @ip_reass_free_complete_datagram(ptr noundef nonnull %.014, ptr noundef %.0913)
  br label %10

10:                                               ; preds = %7, %4
  %.110 = phi ptr [ %.014, %4 ], [ %.0913, %7 ]
  %.1 = phi ptr [ %6, %4 ], [ %8, %7 ]
  %.not = icmp eq ptr %.1, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %10, %0
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden i32 @ip_reass_free_complete_datagram(ptr noundef, ptr noundef) local_unnamed_addr #0

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

!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, !7, i64 39}
!10 = !{!"ip_reassdata", !6, i64 0, !6, i64 8, !11, i64 16, !12, i64 36, !7, i64 38, !7, i64 39}
!11 = !{!"ip_hdr", !7, i64 0, !7, i64 1, !12, i64 2, !12, i64 4, !12, i64 6, !7, i64 8, !7, i64 9, !12, i64 10, !13, i64 12, !13, i64 16}
!12 = !{!"short", !7, i64 0}
!13 = !{!"ip4_addr_packed", !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!10, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass