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

; 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.35 = external hidden unnamed_addr constant [23 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
declare dso_local ptr @pbuf_skip(ptr noundef, i16 noundef zeroext, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @pbuf_take(ptr noundef, ptr noundef, i16 noundef zeroext) #3

; Function Attrs: nounwind uwtable
define dso_local signext i8 @pbuf_take_at(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2, i16 noundef zeroext %3) #3 {
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i16, align 2
  %9 = alloca i16, align 2
  %10 = alloca i16, align 2
  %11 = alloca ptr, align 8
  %12 = alloca i16, align 2
  %13 = alloca ptr, align 8
  %14 = alloca i16, align 2
  %15 = 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 2, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load i16, ptr %9, align 2, !tbaa !9
  %18 = call ptr @pbuf_skip(ptr noundef %16, i16 noundef zeroext %17, ptr noundef %10)
  store ptr %18, ptr %11, align 8, !tbaa !5
  %19 = load ptr, ptr %11, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %108

21:                                               ; preds = %4
  %22 = load ptr, ptr %11, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.pbuf, ptr %22, i32 0, i32 2
  %24 = load i16, ptr %23, align 8, !tbaa !11
  %25 = zext i16 %24 to i32
  %26 = load i16, ptr %10, align 2, !tbaa !9
  %27 = zext i16 %26 to i32
  %28 = load i16, ptr %8, align 2, !tbaa !9
  %29 = zext i16 %28 to i32
  %30 = add nsw i32 %27, %29
  %31 = icmp sge i32 %25, %30
  br i1 %31, label %32, label %108

32:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #4
  %33 = load i16, ptr %8, align 2, !tbaa !9
  store i16 %33, ptr %12, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %34, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %14) #4
  br label %35

35:                                               ; preds = %32
  %36 = load i16, ptr %10, align 2, !tbaa !9
  %37 = zext i16 %36 to i32
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.pbuf, ptr %38, i32 0, i32 3
  %40 = load i16, ptr %39, align 2, !tbaa !13
  %41 = zext i16 %40 to i32
  %42 = icmp slt i32 %37, %41
  br i1 %42, label %48, label %43

43:                                               ; preds = %35
  br label %44

44:                                               ; preds = %43
  %45 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.35, i32 noundef 1251, ptr noundef @.str.2)
  br label %46

46:                                               ; preds = %44
  br label %47

47:                                               ; preds = %46
  br label %48

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

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.pbuf, ptr %51, i32 0, i32 3
  %53 = load i16, ptr %52, align 2, !tbaa !13
  %54 = zext i16 %53 to i32
  %55 = load i16, ptr %10, align 2, !tbaa !9
  %56 = zext i16 %55 to i32
  %57 = sub nsw i32 %54, %56
  %58 = load i16, ptr %8, align 2, !tbaa !9
  %59 = zext i16 %58 to i32
  %60 = icmp slt i32 %57, %59
  br i1 %60, label %61, label %69

61:                                               ; preds = %50
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.pbuf, ptr %62, i32 0, i32 3
  %64 = load i16, ptr %63, align 2, !tbaa !13
  %65 = zext i16 %64 to i32
  %66 = load i16, ptr %10, align 2, !tbaa !9
  %67 = zext i16 %66 to i32
  %68 = sub nsw i32 %65, %67
  br label %72

69:                                               ; preds = %50
  %70 = load i16, ptr %8, align 2, !tbaa !9
  %71 = zext i16 %70 to i32
  br label %72

72:                                               ; preds = %69, %61
  %73 = phi i32 [ %68, %61 ], [ %71, %69 ]
  %74 = trunc i32 %73 to i16
  store i16 %74, ptr %14, align 2, !tbaa !9
  %75 = load ptr, ptr %11, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.pbuf, ptr %75, i32 0, i32 1
  %77 = load ptr, ptr %76, align 8, !tbaa !14
  %78 = load i16, ptr %10, align 2, !tbaa !9
  %79 = zext i16 %78 to i32
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds i8, ptr %77, i64 %80
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = load i16, ptr %14, align 2, !tbaa !9
  %84 = zext i16 %83 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %81, ptr align 1 %82, i64 %84, i1 false)
  %85 = load i16, ptr %12, align 2, !tbaa !9
  %86 = zext i16 %85 to i32
  %87 = load i16, ptr %14, align 2, !tbaa !9
  %88 = zext i16 %87 to i32
  %89 = sub nsw i32 %86, %88
  %90 = trunc i32 %89 to i16
  store i16 %90, ptr %12, align 2, !tbaa !9
  %91 = load i16, ptr %14, align 2, !tbaa !9
  %92 = zext i16 %91 to i32
  %93 = load ptr, ptr %13, align 8, !tbaa !5
  %94 = sext i32 %92 to i64
  %95 = getelementptr inbounds i8, ptr %93, i64 %94
  store ptr %95, ptr %13, align 8, !tbaa !5
  %96 = load i16, ptr %12, align 2, !tbaa !9
  %97 = zext i16 %96 to i32
  %98 = icmp sgt i32 %97, 0
  br i1 %98, label %99, label %106

99:                                               ; preds = %72
  %100 = load ptr, ptr %11, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.pbuf, ptr %100, i32 0, i32 0
  %102 = load ptr, ptr %101, align 8, !tbaa !15
  %103 = load ptr, ptr %13, align 8, !tbaa !5
  %104 = load i16, ptr %12, align 2, !tbaa !9
  %105 = call signext i8 @pbuf_take(ptr noundef %102, ptr noundef %103, i16 noundef zeroext %104)
  store i8 %105, ptr %5, align 1
  store i32 1, ptr %15, align 4
  br label %107

106:                                              ; preds = %72
  store i8 0, ptr %5, align 1
  store i32 1, ptr %15, align 4
  br label %107

107:                                              ; preds = %106, %99
  call void @llvm.lifetime.end.p0(i64 2, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #4
  br label %109

108:                                              ; preds = %21, %4
  store i8 -1, ptr %5, align 1
  store i32 1, ptr %15, align 4
  br label %109

109:                                              ; preds = %108, %107
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #4
  %110 = load i8, ptr %5, align 1
  ret i8 %110
}

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 16}
!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, !10, i64 18}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !6, 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"

@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [179 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [23 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: 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) #2

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

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @pbuf_take(ptr noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #3

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

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %6, i64 16
  %9 = load i16, ptr %8, align 8, !tbaa !5
  %10 = zext i16 %9 to i32
  %11 = load i16, ptr %5, align 2, !tbaa !11
  %12 = zext i16 %11 to i32
  %13 = zext i16 %2 to i32
  %14 = add nuw nsw i32 %12, %13
  %.not26 = icmp ugt i32 %14, %10
  br i1 %.not26, label %39, label %15

15:                                               ; preds = %7
  %16 = getelementptr inbounds i8, ptr %6, i64 18
  %17 = load i16, ptr %16, align 2, !tbaa !12
  %18 = icmp ult i16 %11, %17
  br i1 %18, label %21, label %19

19:                                               ; preds = %15
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.35, i32 noundef 1251, ptr noundef nonnull @.str.2)
  %.pre = load i16, ptr %16, align 2, !tbaa !12
  %.pre28 = load i16, ptr %5, align 2, !tbaa !11
  %.pre29 = zext i16 %.pre28 to i32
  br label %21

21:                                               ; preds = %19, %15
  %.pre-phi = phi i32 [ %.pre29, %19 ], [ %12, %15 ]
  %22 = phi i16 [ %.pre28, %19 ], [ %11, %15 ]
  %23 = phi i16 [ %.pre, %19 ], [ %17, %15 ]
  %24 = zext i16 %23 to i32
  %25 = sub nsw i32 %24, %.pre-phi
  %26 = icmp slt i32 %25, %13
  %27 = trunc i32 %25 to i16
  %28 = select i1 %26, i16 %27, i16 %2
  %29 = getelementptr inbounds i8, ptr %6, i64 8
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  %31 = zext i16 %22 to i64
  %32 = getelementptr inbounds i8, ptr %30, i64 %31
  %33 = zext i16 %28 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %32, ptr align 1 %1, i64 %33, i1 false)
  %.not27 = icmp eq i16 %28, %2
  br i1 %.not27, label %39, label %34

34:                                               ; preds = %21
  %35 = sub i16 %2, %28
  %36 = getelementptr inbounds i8, ptr %1, i64 %33
  %37 = load ptr, ptr %6, align 8, !tbaa !14
  %38 = call signext i8 @pbuf_take(ptr noundef %37, ptr noundef %36, i16 noundef zeroext %35)
  br label %39

39:                                               ; preds = %4, %7, %34, %21
  %.1 = phi i8 [ %38, %34 ], [ 0, %21 ], [ -1, %7 ], [ -1, %4 ]
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %5) #4
  ret i8 %.1
}

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 = { mustprogress 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, !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 = !{!10, !10, i64 0}
!12 = !{!6, !10, i64 18}
!13 = !{!6, !7, i64 8}
!14 = !{!6, !7, i64 0}


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