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

; 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.26 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [35 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 zeroext i16 @pbuf_copy_partial(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2, i16 noundef zeroext %3) #3 {
  %5 = alloca i16, align 2
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i16, align 2
  %9 = alloca i16, align 2
  %10 = alloca ptr, align 8
  %11 = alloca i16, align 2
  %12 = alloca i16, align 2
  %13 = alloca i16, align 2
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i16 %2, ptr %8, align 2, !tbaa !9
  store i16 %3, ptr %9, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #4
  store i16 0, ptr %11, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 2, ptr %13) #4
  store i16 0, ptr %13, align 2, !tbaa !9
  br label %15

15:                                               ; preds = %4
  %16 = load ptr, ptr %6, 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.26, i32 noundef 1034, ptr noundef @.str.2)
  br label %21

21:                                               ; preds = %19
  br label %22

22:                                               ; preds = %21
  store i16 0, ptr %5, align 2
  store i32 1, ptr %14, align 4
  br label %122

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 %7, 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.27, i32 noundef 1035, ptr noundef @.str.2)
  br label %32

32:                                               ; preds = %30
  br label %33

33:                                               ; preds = %32
  store i16 0, ptr %5, align 2
  store i32 1, ptr %14, align 4
  br label %122

34:                                               ; preds = %26
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %37, ptr %10, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %116, %36
  %39 = load i16, ptr %8, align 2, !tbaa !9
  %40 = zext i16 %39 to i32
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %45

42:                                               ; preds = %38
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br label %45

45:                                               ; preds = %42, %38
  %46 = phi i1 [ false, %38 ], [ %44, %42 ]
  br i1 %46, label %47, label %120

47:                                               ; preds = %45
  %48 = load i16, ptr %9, align 2, !tbaa !9
  %49 = zext i16 %48 to i32
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %68

51:                                               ; preds = %47
  %52 = load i16, ptr %9, align 2, !tbaa !9
  %53 = zext i16 %52 to i32
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.pbuf, ptr %54, i32 0, i32 3
  %56 = load i16, ptr %55, align 2, !tbaa !11
  %57 = zext i16 %56 to i32
  %58 = icmp sge i32 %53, %57
  br i1 %58, label %59, label %68

59:                                               ; preds = %51
  %60 = load i16, ptr %9, align 2, !tbaa !9
  %61 = zext i16 %60 to i32
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.pbuf, ptr %62, i32 0, i32 3
  %64 = load i16, ptr %63, align 2, !tbaa !11
  %65 = zext i16 %64 to i32
  %66 = sub nsw i32 %61, %65
  %67 = trunc i32 %66 to i16
  store i16 %67, ptr %9, align 2, !tbaa !9
  br label %115

68:                                               ; preds = %51, %47
  %69 = load ptr, ptr %10, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.pbuf, ptr %69, i32 0, i32 3
  %71 = load i16, ptr %70, align 2, !tbaa !11
  %72 = zext i16 %71 to i32
  %73 = load i16, ptr %9, align 2, !tbaa !9
  %74 = zext i16 %73 to i32
  %75 = sub nsw i32 %72, %74
  %76 = trunc i32 %75 to i16
  store i16 %76, ptr %12, align 2, !tbaa !9
  %77 = load i16, ptr %12, align 2, !tbaa !9
  %78 = zext i16 %77 to i32
  %79 = load i16, ptr %8, align 2, !tbaa !9
  %80 = zext i16 %79 to i32
  %81 = icmp sgt i32 %78, %80
  br i1 %81, label %82, label %84

82:                                               ; preds = %68
  %83 = load i16, ptr %8, align 2, !tbaa !9
  store i16 %83, ptr %12, align 2, !tbaa !9
  br label %84

84:                                               ; preds = %82, %68
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = load i16, ptr %11, align 2, !tbaa !9
  %87 = zext i16 %86 to i64
  %88 = getelementptr inbounds i8, ptr %85, i64 %87
  %89 = load ptr, ptr %10, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.pbuf, ptr %89, i32 0, i32 1
  %91 = load ptr, ptr %90, align 8, !tbaa !13
  %92 = load i16, ptr %9, align 2, !tbaa !9
  %93 = zext i16 %92 to i64
  %94 = getelementptr inbounds i8, ptr %91, i64 %93
  %95 = load i16, ptr %12, align 2, !tbaa !9
  %96 = zext i16 %95 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %88, ptr align 1 %94, i64 %96, i1 false)
  %97 = load i16, ptr %13, align 2, !tbaa !9
  %98 = zext i16 %97 to i32
  %99 = load i16, ptr %12, align 2, !tbaa !9
  %100 = zext i16 %99 to i32
  %101 = add nsw i32 %98, %100
  %102 = trunc i32 %101 to i16
  store i16 %102, ptr %13, align 2, !tbaa !9
  %103 = load i16, ptr %11, align 2, !tbaa !9
  %104 = zext i16 %103 to i32
  %105 = load i16, ptr %12, align 2, !tbaa !9
  %106 = zext i16 %105 to i32
  %107 = add nsw i32 %104, %106
  %108 = trunc i32 %107 to i16
  store i16 %108, ptr %11, align 2, !tbaa !9
  %109 = load i16, ptr %8, align 2, !tbaa !9
  %110 = zext i16 %109 to i32
  %111 = load i16, ptr %12, align 2, !tbaa !9
  %112 = zext i16 %111 to i32
  %113 = sub nsw i32 %110, %112
  %114 = trunc i32 %113 to i16
  store i16 %114, ptr %8, align 2, !tbaa !9
  store i16 0, ptr %9, align 2, !tbaa !9
  br label %115

115:                                              ; preds = %84, %59
  br label %116

116:                                              ; preds = %115
  %117 = load ptr, ptr %10, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.pbuf, ptr %117, i32 0, i32 0
  %119 = load ptr, ptr %118, align 8, !tbaa !14
  store ptr %119, ptr %10, align 8, !tbaa !5
  br label %38, !llvm.loop !15

120:                                              ; preds = %45
  %121 = load i16, ptr %13, align 2, !tbaa !9
  store i16 %121, ptr %5, align 2
  store i32 1, ptr %14, align 4
  br label %122

122:                                              ; preds = %120, %33, %22
  call void @llvm.lifetime.end.p0(i64 2, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %123 = load i16, ptr %5, align 2
  ret i16 %123
}

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, !10, i64 18}
!12 = !{!"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}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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.26 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [35 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 zeroext i16 @pbuf_copy_partial(ptr noundef readonly %0, ptr noundef writeonly %1, i16 noundef zeroext %2, i16 noundef zeroext %3) local_unnamed_addr #2 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %5, label %7

5:                                                ; preds = %4
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.26, i32 noundef 1034, ptr noundef nonnull @.str.2)
  br label %.loopexit

7:                                                ; preds = %4
  %.not42 = icmp eq ptr %1, null
  br i1 %.not42, label %8, label %.preheader

.preheader:                                       ; preds = %7
  %.not50 = icmp eq i16 %2, 0
  br i1 %.not50, label %.loopexit, label %.lr.ph

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

.lr.ph:                                           ; preds = %.preheader, %23
  %.049 = phi i16 [ %.1, %23 ], [ 0, %.preheader ]
  %.02948 = phi i16 [ %.130, %23 ], [ 0, %.preheader ]
  %.03147 = phi ptr [ %24, %23 ], [ %0, %.preheader ]
  %.03246 = phi i16 [ %.133, %23 ], [ %3, %.preheader ]
  %.03445 = phi i16 [ %.135, %23 ], [ %2, %.preheader ]
  %.not43 = icmp eq i16 %.03246, 0
  %.phi.trans.insert = getelementptr inbounds i8, ptr %.03147, i64 18
  %.pre = load i16, ptr %.phi.trans.insert, align 2, !tbaa !5
  %.not44 = icmp ult i16 %.03246, %.pre
  %or.cond = select i1 %.not43, i1 true, i1 %.not44
  br i1 %or.cond, label %.lr.ph._crit_edge, label %10

10:                                               ; preds = %.lr.ph
  %11 = sub i16 %.03246, %.pre
  br label %23

.lr.ph._crit_edge:                                ; preds = %.lr.ph
  %12 = sub i16 %.pre, %.03246
  %spec.select = tail call i16 @llvm.umin.i16(i16 %12, i16 %.03445)
  %13 = zext i16 %.02948 to i64
  %14 = getelementptr inbounds i8, ptr %1, i64 %13
  %15 = getelementptr inbounds i8, ptr %.03147, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = zext i16 %.03246 to i64
  %18 = getelementptr inbounds i8, ptr %16, i64 %17
  %19 = zext i16 %spec.select to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %14, ptr align 1 %18, i64 %19, i1 false)
  %20 = add i16 %spec.select, %.049
  %21 = add i16 %spec.select, %.02948
  %22 = sub i16 %.03445, %spec.select
  br label %23

23:                                               ; preds = %10, %.lr.ph._crit_edge
  %.135 = phi i16 [ %.03445, %10 ], [ %22, %.lr.ph._crit_edge ]
  %.133 = phi i16 [ %11, %10 ], [ 0, %.lr.ph._crit_edge ]
  %.130 = phi i16 [ %.02948, %10 ], [ %21, %.lr.ph._crit_edge ]
  %.1 = phi i16 [ %.049, %10 ], [ %20, %.lr.ph._crit_edge ]
  %24 = load ptr, ptr %.03147, align 8, !tbaa !12
  %25 = icmp ne i16 %.135, 0
  %26 = icmp ne ptr %24, null
  %27 = select i1 %25, i1 %26, i1 false
  br i1 %27, label %.lr.ph, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %23, %.preheader, %8, %5
  %.036 = phi i16 [ 0, %8 ], [ 0, %5 ], [ 0, %.preheader ], [ %.1, %23 ]
  ret i16 %.036
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i16 @llvm.umin.i16(i16, i16) #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 18}
!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, !7, i64 8}
!12 = !{!6, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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