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

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

@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [179 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [22 x i8], align 1

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local signext i8 @pbuf_take(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2) #3 {
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i16, align 2
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i16 %2, ptr %7, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %13 = load i16, ptr %7, align 2, !tbaa !9
  %14 = zext i16 %13 to i64
  store i64 %14, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 0, ptr %11, align 8, !tbaa !11
  br label %15

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %23, label %18

18:                                               ; preds = %15
  br label %19

19:                                               ; preds = %18
  %20 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.30, i32 noundef 1203, ptr noundef @.str.2)
  br label %21

21:                                               ; preds = %19
  br label %22

22:                                               ; preds = %21
  store i8 -16, ptr %4, align 1
  store i32 1, ptr %12, align 4
  br label %131

23:                                               ; preds = %15
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = icmp ne ptr %27, null
  br i1 %28, label %34, label %29

29:                                               ; preds = %26
  br label %30

30:                                               ; preds = %29
  %31 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.31, i32 noundef 1204, ptr noundef @.str.2)
  br label %32

32:                                               ; preds = %30
  br label %33

33:                                               ; preds = %32
  store i8 -16, ptr %4, align 1
  store i32 1, ptr %12, align 4
  br label %131

34:                                               ; preds = %26
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.pbuf, ptr %38, i32 0, i32 2
  %40 = load i16, ptr %39, align 8, !tbaa !13
  %41 = zext i16 %40 to i32
  %42 = load i16, ptr %7, align 2, !tbaa !9
  %43 = zext i16 %42 to i32
  %44 = icmp sge i32 %41, %43
  br i1 %44, label %50, label %45

45:                                               ; preds = %37
  br label %46

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

48:                                               ; preds = %46
  br label %49

49:                                               ; preds = %48
  store i8 -1, ptr %4, align 1
  store i32 1, ptr %12, align 4
  br label %131

50:                                               ; preds = %37
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = icmp eq ptr %53, null
  br i1 %54, label %66, label %55

55:                                               ; preds = %52
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = icmp eq ptr %56, null
  br i1 %57, label %66, label %58

58:                                               ; preds = %55
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.pbuf, ptr %59, i32 0, i32 2
  %61 = load i16, ptr %60, align 8, !tbaa !13
  %62 = zext i16 %61 to i32
  %63 = load i16, ptr %7, align 2, !tbaa !9
  %64 = zext i16 %63 to i32
  %65 = icmp slt i32 %62, %64
  br i1 %65, label %66, label %67

66:                                               ; preds = %58, %55, %52
  store i8 -16, ptr %4, align 1
  store i32 1, ptr %12, align 4
  br label %131

67:                                               ; preds = %58
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %68, ptr %8, align 8, !tbaa !5
  br label %69

69:                                               ; preds = %110, %67
  %70 = load i64, ptr %10, align 8, !tbaa !11
  %71 = icmp ne i64 %70, 0
  br i1 %71, label %72, label %114

72:                                               ; preds = %69
  br label %73

73:                                               ; preds = %72
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = icmp ne ptr %74, null
  br i1 %75, label %81, label %76

76:                                               ; preds = %73
  br label %77

77:                                               ; preds = %76
  %78 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.33, i32 noundef 1213, ptr noundef @.str.2)
  br label %79

79:                                               ; preds = %77
  br label %80

80:                                               ; preds = %79
  br label %81

81:                                               ; preds = %80, %73
  br label %82

82:                                               ; preds = %81
  br label %83

83:                                               ; preds = %82
  %84 = load i64, ptr %10, align 8, !tbaa !11
  store i64 %84, ptr %9, align 8, !tbaa !11
  %85 = load i64, ptr %9, align 8, !tbaa !11
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.pbuf, ptr %86, i32 0, i32 3
  %88 = load i16, ptr %87, align 2, !tbaa !15
  %89 = zext i16 %88 to i64
  %90 = icmp ugt i64 %85, %89
  br i1 %90, label %91, label %96

91:                                               ; preds = %83
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.pbuf, ptr %92, i32 0, i32 3
  %94 = load i16, ptr %93, align 2, !tbaa !15
  %95 = zext i16 %94 to i64
  store i64 %95, ptr %9, align 8, !tbaa !11
  br label %96

96:                                               ; preds = %91, %83
  %97 = load ptr, ptr %8, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.pbuf, ptr %97, i32 0, i32 1
  %99 = load ptr, ptr %98, align 8, !tbaa !16
  %100 = load ptr, ptr %6, align 8, !tbaa !5
  %101 = load i64, ptr %11, align 8, !tbaa !11
  %102 = getelementptr inbounds i8, ptr %100, i64 %101
  %103 = load i64, ptr %9, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %99, ptr align 1 %102, i64 %103, i1 false)
  %104 = load i64, ptr %9, align 8, !tbaa !11
  %105 = load i64, ptr %10, align 8, !tbaa !11
  %106 = sub i64 %105, %104
  store i64 %106, ptr %10, align 8, !tbaa !11
  %107 = load i64, ptr %9, align 8, !tbaa !11
  %108 = load i64, ptr %11, align 8, !tbaa !11
  %109 = add i64 %108, %107
  store i64 %109, ptr %11, align 8, !tbaa !11
  br label %110

110:                                              ; preds = %96
  %111 = load ptr, ptr %8, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.pbuf, ptr %111, i32 0, i32 0
  %113 = load ptr, ptr %112, align 8, !tbaa !17
  store ptr %113, ptr %8, align 8, !tbaa !5
  br label %69, !llvm.loop !18

114:                                              ; preds = %69
  br label %115

115:                                              ; preds = %114
  %116 = load i64, ptr %10, align 8, !tbaa !11
  %117 = icmp eq i64 %116, 0
  br i1 %117, label %118, label %123

118:                                              ; preds = %115
  %119 = load i64, ptr %11, align 8, !tbaa !11
  %120 = load i16, ptr %7, align 2, !tbaa !9
  %121 = zext i16 %120 to i64
  %122 = icmp eq i64 %119, %121
  br i1 %122, label %128, label %123

123:                                              ; preds = %118, %115
  br label %124

124:                                              ; preds = %123
  %125 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.34, i32 noundef 1224, ptr noundef @.str.2)
  br label %126

126:                                              ; preds = %124
  br label %127

127:                                              ; preds = %126
  br label %128

128:                                              ; preds = %127, %118
  br label %129

129:                                              ; preds = %128
  br label %130

130:                                              ; preds = %129
  store i8 0, ptr %4, align 1
  store i32 1, ptr %12, align 4
  br label %131

131:                                              ; preds = %130, %66, %49, %33, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %132 = load i8, ptr %4, align 1
  ret i8 %132
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !10, i64 16}
!14 = !{!"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}
!15 = !{!14, !10, i64 18}
!16 = !{!14, !6, i64 8}
!17 = !{!14, !6, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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"

@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [179 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [22 x i8], align 1

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nofree nounwind uwtable
define dso_local signext range(i8 -16, 1) i8 @pbuf_take(ptr noundef readonly %0, ptr noundef readonly %1, i16 noundef zeroext %2) local_unnamed_addr #2 {
  %4 = zext i16 %2 to i64
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %5, label %7

5:                                                ; preds = %3
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.30, i32 noundef 1203, ptr noundef nonnull @.str.2)
  br label %30

7:                                                ; preds = %3
  %.not38 = icmp eq ptr %1, null
  br i1 %.not38, label %8, label %10

8:                                                ; preds = %7
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.31, i32 noundef 1204, ptr noundef nonnull @.str.2)
  br label %30

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load i16, ptr %11, align 8, !tbaa !5
  %.not39 = icmp ult i16 %12, %2
  br i1 %.not39, label %13, label %.preheader

.preheader:                                       ; preds = %10
  %.not4042 = icmp eq i16 %2, 0
  br i1 %.not4042, label %._crit_edge, label %.lr.ph

13:                                               ; preds = %10
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.32, i32 noundef 1205, ptr noundef nonnull @.str.2)
  br label %30

.lr.ph:                                           ; preds = %.preheader, %17
  %.045 = phi i64 [ %25, %17 ], [ 0, %.preheader ]
  %.02944 = phi i64 [ %24, %17 ], [ %4, %.preheader ]
  %.03143 = phi ptr [ %26, %17 ], [ %0, %.preheader ]
  %.not41 = icmp eq ptr %.03143, null
  br i1 %.not41, label %15, label %17

15:                                               ; preds = %.lr.ph
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.33, i32 noundef 1213, ptr noundef nonnull @.str.2)
  br label %17

17:                                               ; preds = %15, %.lr.ph
  %18 = getelementptr inbounds i8, ptr %.03143, i64 18
  %19 = load i16, ptr %18, align 2, !tbaa !11
  %20 = zext i16 %19 to i64
  %spec.select = tail call i64 @llvm.umin.i64(i64 %.02944, i64 %20)
  %21 = getelementptr inbounds i8, ptr %.03143, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !12
  %23 = getelementptr inbounds i8, ptr %1, i64 %.045
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %22, ptr nonnull align 1 %23, i64 %spec.select, i1 false)
  %24 = sub i64 %.02944, %spec.select
  %25 = add i64 %spec.select, %.045
  %26 = load ptr, ptr %.03143, align 8, !tbaa !13
  %.not40 = icmp eq i64 %24, 0
  br i1 %.not40, label %._crit_edge, label %.lr.ph, !llvm.loop !14

._crit_edge:                                      ; preds = %17, %.preheader
  %.0.lcssa = phi i64 [ 0, %.preheader ], [ %25, %17 ]
  %27 = icmp eq i64 %.0.lcssa, %4
  br i1 %27, label %30, label %28

28:                                               ; preds = %._crit_edge
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.34, i32 noundef 1224, ptr noundef nonnull @.str.2)
  br label %30

30:                                               ; preds = %._crit_edge, %28, %13, %8, %5
  %.032 = phi i8 [ -1, %13 ], [ -16, %8 ], [ -16, %5 ], [ 0, %28 ], [ 0, %._crit_edge ]
  ret i8 %.032
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #3

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree 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 #3 = { 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, !10, i64 16}
!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 8}
!13 = !{!6, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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