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

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

@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [180 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [36 x i8], align 1

declare zeroext i8 @pbuf_free(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local ptr @netbuf_alloc(ptr noundef %0, i16 noundef zeroext %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i16 %1, ptr %5, align 2, !tbaa !9
  br label %6

6:                                                ; preds = %2
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %13, label %9

9:                                                ; preds = %6
  br label %10

10:                                               ; preds = %9
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 104, ptr noundef @.str.2)
  br label %12

12:                                               ; preds = %10
  store ptr null, ptr %3, align 8
  br label %61

13:                                               ; preds = %6
  br label %14

14:                                               ; preds = %13
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.netbuf, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %24

19:                                               ; preds = %14
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.netbuf, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = call zeroext i8 @pbuf_free(ptr noundef %22)
  br label %24

24:                                               ; preds = %19, %14
  %25 = load i16, ptr %5, align 2, !tbaa !9
  %26 = call ptr @pbuf_alloc(i32 noundef 56, i16 noundef zeroext %25, i32 noundef 640)
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.netbuf, ptr %27, i32 0, i32 0
  store ptr %26, ptr %28, align 8, !tbaa !11
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.netbuf, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %34

33:                                               ; preds = %24
  store ptr null, ptr %3, align 8
  br label %61

34:                                               ; preds = %24
  br label %35

35:                                               ; preds = %34
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.netbuf, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = getelementptr inbounds %struct.pbuf, ptr %38, i32 0, i32 3
  %40 = load i16, ptr %39, align 2, !tbaa !15
  %41 = zext i16 %40 to i32
  %42 = load i16, ptr %5, align 2, !tbaa !9
  %43 = zext i16 %42 to i32
  %44 = icmp sge i32 %41, %43
  br i1 %44, label %49, label %45

45:                                               ; preds = %35
  br label %46

46:                                               ; preds = %45
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.3, i32 noundef 115, ptr noundef @.str.2)
  br label %48

48:                                               ; preds = %46
  br label %49

49:                                               ; preds = %48, %35
  br label %50

50:                                               ; preds = %49
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.netbuf, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !11
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.netbuf, ptr %54, i32 0, i32 1
  store ptr %53, ptr %55, align 8, !tbaa !17
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.netbuf, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !11
  %59 = getelementptr inbounds %struct.pbuf, ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %59, align 8, !tbaa !18
  store ptr %60, ptr %3, align 8
  br label %61

61:                                               ; preds = %50, %33, %12
  %62 = load ptr, ptr %3, align 8
  ret ptr %62
}

declare i32 @printf(ptr noundef, ...) #0

declare ptr @pbuf_alloc(i32 noundef, i16 noundef zeroext, i32 noundef) #0

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


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

@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [180 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [36 x i8], align 1

declare zeroext i8 @pbuf_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @netbuf_alloc(ptr noundef %0, i16 noundef zeroext %1) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %3, label %5

3:                                                ; preds = %2
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.1, i32 noundef 104, ptr noundef nonnull @.str.2)
  br label %22

5:                                                ; preds = %2
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  %.not14 = icmp eq ptr %6, null
  br i1 %.not14, label %9, label %7

7:                                                ; preds = %5
  %8 = tail call zeroext i8 @pbuf_free(ptr noundef nonnull %6) #3
  br label %9

9:                                                ; preds = %7, %5
  %10 = tail call ptr @pbuf_alloc(i32 noundef 56, i16 noundef zeroext %1, i32 noundef 640) #3
  store ptr %10, ptr %0, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %22, label %12

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %10, i64 18
  %14 = load i16, ptr %13, align 2, !tbaa !13
  %.not15 = icmp ult i16 %14, %1
  br i1 %.not15, label %15, label %17

15:                                               ; preds = %12
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.3, i32 noundef 115, ptr noundef nonnull @.str.2)
  %.pre = load ptr, ptr %0, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %12, %15
  %18 = phi ptr [ %10, %12 ], [ %.pre, %15 ]
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %18, ptr %19, align 8, !tbaa !15
  %20 = getelementptr inbounds i8, ptr %18, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  br label %22

22:                                               ; preds = %9, %17, %3
  %.0 = phi ptr [ %21, %17 ], [ null, %3 ], [ null, %9 ]
  ret ptr %.0
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

declare ptr @pbuf_alloc(i32 noundef, i16 noundef zeroext, i32 noundef) local_unnamed_addr #0

attributes #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 = { 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 = { nofree nounwind "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 #3 = { 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, !7, i64 0}
!6 = !{!"netbuf", !7, i64 0, !7, i64 8, !10, i64 16, !12, i64 20}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"ip4_addr", !11, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!14, !12, i64 18}
!14 = !{!"pbuf", !7, i64 0, !7, i64 8, !12, i64 16, !12, i64 18, !8, i64 20, !8, i64 21, !8, i64 22, !8, i64 23}
!15 = !{!6, !7, i64 8}
!16 = !{!14, !7, i64 8}


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