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

; 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.28 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [37 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: nounwind uwtable
declare dso_local zeroext i16 @pbuf_copy_partial(ptr noundef, ptr noundef, i16 noundef zeroext, i16 noundef zeroext) #2

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

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

21:                                               ; preds = %19
  br label %22

22:                                               ; preds = %21
  store ptr null, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %88

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

32:                                               ; preds = %30
  br label %33

33:                                               ; preds = %32
  store ptr null, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %88

34:                                               ; preds = %26
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36
  %38 = load i64, ptr %9, align 8, !tbaa !9
  %39 = load i16, ptr %10, align 2, !tbaa !11
  %40 = zext i16 %39 to i64
  %41 = icmp uge i64 %38, %40
  br i1 %41, label %47, label %42

42:                                               ; preds = %37
  br label %43

43:                                               ; preds = %42
  %44 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.29, i32 noundef 1081, ptr noundef @.str.2)
  br label %45

45:                                               ; preds = %43
  br label %46

46:                                               ; preds = %45
  store ptr null, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %88

47:                                               ; preds = %37
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = load i16, ptr %11, align 2, !tbaa !11
  %52 = call ptr @pbuf_skip_const(ptr noundef %50, i16 noundef zeroext %51, ptr noundef %13)
  store ptr %52, ptr %12, align 8, !tbaa !5
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %87

55:                                               ; preds = %49
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.pbuf, ptr %56, i32 0, i32 3
  %58 = load i16, ptr %57, align 2, !tbaa !13
  %59 = zext i16 %58 to i32
  %60 = load i16, ptr %13, align 2, !tbaa !11
  %61 = zext i16 %60 to i32
  %62 = load i16, ptr %10, align 2, !tbaa !11
  %63 = zext i16 %62 to i32
  %64 = add nsw i32 %61, %63
  %65 = icmp sge i32 %59, %64
  br i1 %65, label %66, label %74

66:                                               ; preds = %55
  %67 = load ptr, ptr %12, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.pbuf, ptr %67, i32 0, i32 1
  %69 = load ptr, ptr %68, align 8, !tbaa !15
  %70 = load i16, ptr %13, align 2, !tbaa !11
  %71 = zext i16 %70 to i32
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds i8, ptr %69, i64 %72
  store ptr %73, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %88

74:                                               ; preds = %55
  %75 = load ptr, ptr %12, align 8, !tbaa !5
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = load i16, ptr %10, align 2, !tbaa !11
  %78 = load i16, ptr %13, align 2, !tbaa !11
  %79 = call zeroext i16 @pbuf_copy_partial(ptr noundef %75, ptr noundef %76, i16 noundef zeroext %77, i16 noundef zeroext %78)
  %80 = zext i16 %79 to i32
  %81 = load i16, ptr %10, align 2, !tbaa !11
  %82 = zext i16 %81 to i32
  %83 = icmp ne i32 %80, %82
  br i1 %83, label %84, label %85

84:                                               ; preds = %74
  store ptr null, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %88

85:                                               ; preds = %74
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %86, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %88

87:                                               ; preds = %49
  store ptr null, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %88

88:                                               ; preds = %87, %85, %84, %66, %46, %33, %22
  call void @llvm.lifetime.end.p0(i64 2, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %89 = load ptr, ptr %6, align 8
  ret ptr %89
}

; Function Attrs: nounwind uwtable
declare hidden ptr @pbuf_skip_const(ptr noundef, i16 noundef zeroext, ptr noundef) #2

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 = { 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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !12, i64 18}
!14 = !{!"pbuf", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 18, !7, i64 20, !7, i64 21, !7, i64 22, !7, i64 23}
!15 = !{!14, !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.2 = external hidden unnamed_addr constant [179 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [37 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i16 @pbuf_copy_partial(ptr noundef, ptr noundef, i16 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local ptr @pbuf_get_contiguous(ptr noundef %0, ptr noundef %1, i64 noundef %2, i16 noundef zeroext %3, i16 noundef zeroext %4) local_unnamed_addr #2 {
  %6 = alloca i16, align 2
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %6) #3
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %7, label %9

7:                                                ; preds = %5
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.28, i32 noundef 1079, ptr noundef nonnull @.str.2)
  br label %33

9:                                                ; preds = %5
  %.not18 = icmp eq ptr %1, null
  br i1 %.not18, label %10, label %12

10:                                               ; preds = %9
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.29, i32 noundef 1080, ptr noundef nonnull @.str.2)
  br label %33

12:                                               ; preds = %9
  %13 = zext i16 %3 to i64
  %.not19 = icmp ugt i64 %13, %2
  br i1 %.not19, label %14, label %16

14:                                               ; preds = %12
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.29, i32 noundef 1081, ptr noundef nonnull @.str.2)
  br label %33

16:                                               ; preds = %12
  %17 = call ptr @pbuf_skip_const(ptr noundef nonnull %0, i16 noundef zeroext %4, ptr noundef nonnull %6)
  %.not20 = icmp eq ptr %17, null
  br i1 %.not20, label %33, label %18

18:                                               ; preds = %16
  %19 = getelementptr inbounds i8, ptr %17, i64 18
  %20 = load i16, ptr %19, align 2, !tbaa !5
  %21 = zext i16 %20 to i32
  %22 = load i16, ptr %6, align 2, !tbaa !11
  %23 = zext i16 %22 to i32
  %24 = zext i16 %3 to i32
  %25 = add nuw nsw i32 %23, %24
  %.not21 = icmp ugt i32 %25, %21
  br i1 %.not21, label %31, label %26

26:                                               ; preds = %18
  %27 = getelementptr inbounds i8, ptr %17, i64 8
  %28 = load ptr, ptr %27, align 8, !tbaa !12
  %29 = zext i16 %22 to i64
  %30 = getelementptr inbounds i8, ptr %28, i64 %29
  br label %33

31:                                               ; preds = %18
  %32 = call zeroext i16 @pbuf_copy_partial(ptr noundef nonnull %17, ptr noundef nonnull %1, i16 noundef zeroext %3, i16 noundef zeroext %22)
  %.not22 = icmp eq i16 %32, %3
  %. = select i1 %.not22, ptr %1, ptr null
  br label %33

33:                                               ; preds = %16, %31, %26, %14, %10, %7
  %.0 = phi ptr [ %30, %26 ], [ null, %14 ], [ null, %10 ], [ null, %7 ], [ %., %31 ], [ null, %16 ]
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %6) #3
  ret ptr %.0
}

; Function Attrs: nounwind uwtable
declare hidden ptr @pbuf_skip_const(ptr noundef, i16 noundef zeroext, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = { 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, !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 = !{!10, !10, i64 0}
!12 = !{!6, !7, i64 8}


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