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

; 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_custom = type { %struct.pbuf, ptr }
%struct.pbuf = type { ptr, ptr, i16, i16, i8, i8, i8, i8 }

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

; Function Attrs: nounwind uwtable
declare hidden void @pbuf_init_alloced_pbuf(ptr noundef, ptr noundef, i16 noundef zeroext, i16 noundef zeroext, i32 noundef, i8 noundef zeroext) #1

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

; Function Attrs: nounwind uwtable
define dso_local ptr @pbuf_alloced_custom(i32 noundef %0, i16 noundef zeroext %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, i16 noundef zeroext %5) #1 {
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i16, align 2
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i16, align 2
  %14 = alloca i16, align 2
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  store i32 %0, ptr %8, align 4, !tbaa !5
  store i16 %1, ptr %9, align 2, !tbaa !9
  store i32 %2, ptr %10, align 4, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !11
  store ptr %4, ptr %12, align 8, !tbaa !11
  store i16 %5, ptr %13, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %14) #2
  %17 = load i32, ptr %8, align 4, !tbaa !5
  %18 = trunc i32 %17 to i16
  store i16 %18, ptr %14, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #2
  %19 = load i16, ptr %14, align 2, !tbaa !9
  %20 = zext i16 %19 to i32
  %21 = add nsw i32 %20, 4
  %22 = sub i32 %21, 1
  %23 = and i32 %22, -4
  %24 = load i16, ptr %9, align 2, !tbaa !9
  %25 = zext i16 %24 to i32
  %26 = add i32 %23, %25
  %27 = load i16, ptr %13, align 2, !tbaa !9
  %28 = zext i16 %27 to i32
  %29 = icmp ugt i32 %26, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %6
  store ptr null, ptr %7, align 8
  store i32 1, ptr %16, align 4
  br label %53

31:                                               ; preds = %6
  %32 = load ptr, ptr %12, align 8, !tbaa !11
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %43

34:                                               ; preds = %31
  %35 = load ptr, ptr %12, align 8, !tbaa !11
  %36 = load i16, ptr %14, align 2, !tbaa !9
  %37 = zext i16 %36 to i32
  %38 = add nsw i32 %37, 4
  %39 = sub i32 %38, 1
  %40 = and i32 %39, -4
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds i8, ptr %35, i64 %41
  store ptr %42, ptr %15, align 8, !tbaa !11
  br label %44

43:                                               ; preds = %31
  store ptr null, ptr %15, align 8, !tbaa !11
  br label %44

44:                                               ; preds = %43, %34
  %45 = load ptr, ptr %11, align 8, !tbaa !11
  %46 = getelementptr inbounds %struct.pbuf_custom, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %15, align 8, !tbaa !11
  %48 = load i16, ptr %9, align 2, !tbaa !9
  %49 = load i16, ptr %9, align 2, !tbaa !9
  %50 = load i32, ptr %10, align 4, !tbaa !5
  call void @pbuf_init_alloced_pbuf(ptr noundef %46, ptr noundef %47, i16 noundef zeroext %48, i16 noundef zeroext %49, i32 noundef %50, i8 noundef zeroext 2)
  %51 = load ptr, ptr %11, align 8, !tbaa !11
  %52 = getelementptr inbounds %struct.pbuf_custom, ptr %51, i32 0, i32 0
  store ptr %52, ptr %7, align 8
  store i32 1, ptr %16, align 4
  br label %53

53:                                               ; preds = %44, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %14) #2
  %54 = load ptr, ptr %7, align 8
  ret ptr %54
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}


; 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 hidden void @pbuf_init_alloced_pbuf(ptr noundef, ptr noundef, i16 noundef zeroext, i16 noundef zeroext, i32 noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @pbuf_alloced_custom(i32 noundef %0, i16 noundef zeroext %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, i16 noundef zeroext %5) local_unnamed_addr #0 {
  %7 = and i32 %0, 65535
  %8 = add nuw nsw i32 %7, 3
  %9 = and i32 %8, 131068
  %10 = zext i16 %1 to i32
  %11 = add nuw nsw i32 %9, %10
  %12 = zext i16 %5 to i32
  %13 = icmp ugt i32 %11, %12
  br i1 %13, label %17, label %14

14:                                               ; preds = %6
  %.not = icmp eq ptr %4, null
  %15 = zext nneg i32 %9 to i64
  %16 = getelementptr inbounds i8, ptr %4, i64 %15
  %.0 = select i1 %.not, ptr null, ptr %16
  tail call void @pbuf_init_alloced_pbuf(ptr noundef %3, ptr noundef %.0, i16 noundef zeroext %1, i16 noundef zeroext %1, i32 noundef %2, i8 noundef zeroext 2)
  br label %17

17:                                               ; preds = %6, %14
  %.013 = phi ptr [ %3, %14 ], [ null, %6 ]
  ret ptr %.013
}

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass