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

; 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 }
%struct.pbuf_custom = type { %struct.pbuf, ptr }

@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [179 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [18 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

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

13:                                               ; preds = %1
  br label %14

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

17:                                               ; preds = %14
  br label %18

18:                                               ; preds = %17
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.10, i32 noundef 732, ptr noundef @.str.2)
  br label %20

20:                                               ; preds = %18
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21, %14
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  store i8 0, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %125

25:                                               ; preds = %1
  store i8 0, ptr %6, align 1, !tbaa !9
  br label %26

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

29:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %30 = call i32 @sys_arch_protect()
  store i32 %30, ptr %9, align 4, !tbaa !10
  br label %31

31:                                               ; preds = %29
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.pbuf, ptr %32, i32 0, i32 6
  %34 = load i8, ptr %33, align 2, !tbaa !12
  %35 = zext i8 %34 to i32
  %36 = icmp sgt i32 %35, 0
  br i1 %36, label %42, label %37

37:                                               ; preds = %31
  br label %38

38:                                               ; preds = %37
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.12, i32 noundef 753, ptr noundef @.str.2)
  br label %40

40:                                               ; preds = %38
  br label %41

41:                                               ; preds = %40
  br label %42

42:                                               ; preds = %41, %31
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.pbuf, ptr %45, i32 0, i32 6
  %47 = load i8, ptr %46, align 2, !tbaa !12
  %48 = add i8 %47, -1
  store i8 %48, ptr %46, align 2, !tbaa !12
  store i8 %48, ptr %8, align 1, !tbaa !9
  %49 = load i32, ptr %9, align 4, !tbaa !10
  call void @sys_arch_unprotect(i32 noundef %49)
  %50 = load i8, ptr %8, align 1, !tbaa !9
  %51 = zext i8 %50 to i32
  %52 = icmp eq i32 %51, 0
  br i1 %52, label %53, label %121

53:                                               ; preds = %44
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.pbuf, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !15
  store ptr %56, ptr %5, align 8, !tbaa !5
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.pbuf, ptr %57, i32 0, i32 4
  %59 = load i8, ptr %58, align 4, !tbaa !16
  %60 = zext i8 %59 to i32
  %61 = and i32 %60, 15
  %62 = trunc i32 %61 to i8
  store i8 %62, ptr %4, align 1, !tbaa !9
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.pbuf, ptr %63, i32 0, i32 5
  %65 = load i8, ptr %64, align 1, !tbaa !17
  %66 = zext i8 %65 to i32
  %67 = and i32 %66, 2
  %68 = icmp ne i32 %67, 0
  br i1 %68, label %69, label %88

69:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %70, ptr %10, align 8, !tbaa !5
  br label %71

71:                                               ; preds = %69
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.pbuf_custom, ptr %72, i32 0, i32 1
  %74 = load ptr, ptr %73, align 8, !tbaa !18
  %75 = icmp ne ptr %74, null
  br i1 %75, label %81, label %76

76:                                               ; preds = %71
  br label %77

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

79:                                               ; preds = %77
  br label %80

80:                                               ; preds = %79
  br label %81

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

82:                                               ; preds = %81
  br label %83

83:                                               ; preds = %82
  %84 = load ptr, ptr %10, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.pbuf_custom, ptr %84, i32 0, i32 1
  %86 = load ptr, ptr %85, align 8, !tbaa !18
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  call void %86(ptr noundef %87)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %117

88:                                               ; preds = %53
  %89 = load i8, ptr %4, align 1, !tbaa !9
  %90 = zext i8 %89 to i32
  %91 = icmp eq i32 %90, 2
  br i1 %91, label %92, label %94

92:                                               ; preds = %88
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  call void @memp_free(i32 noundef 13, ptr noundef %93)
  br label %116

94:                                               ; preds = %88
  %95 = load i8, ptr %4, align 1, !tbaa !9
  %96 = zext i8 %95 to i32
  %97 = icmp eq i32 %96, 1
  br i1 %97, label %98, label %100

98:                                               ; preds = %94
  %99 = load ptr, ptr %3, align 8, !tbaa !5
  call void @memp_free(i32 noundef 12, ptr noundef %99)
  br label %115

100:                                              ; preds = %94
  %101 = load i8, ptr %4, align 1, !tbaa !9
  %102 = zext i8 %101 to i32
  %103 = icmp eq i32 %102, 0
  br i1 %103, label %104, label %106

104:                                              ; preds = %100
  %105 = load ptr, ptr %3, align 8, !tbaa !5
  call void @mem_free(ptr noundef %105)
  br label %114

106:                                              ; preds = %100
  br label %107

107:                                              ; preds = %106
  br label %108

108:                                              ; preds = %107
  %109 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.14, i32 noundef 783, ptr noundef @.str.2)
  br label %110

110:                                              ; preds = %108
  br label %111

111:                                              ; preds = %110
  br label %112

112:                                              ; preds = %111
  br label %113

113:                                              ; preds = %112
  br label %114

114:                                              ; preds = %113, %104
  br label %115

115:                                              ; preds = %114, %98
  br label %116

116:                                              ; preds = %115, %92
  br label %117

117:                                              ; preds = %116, %83
  %118 = load i8, ptr %6, align 1, !tbaa !9
  %119 = add i8 %118, 1
  store i8 %119, ptr %6, align 1, !tbaa !9
  %120 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %120, ptr %3, align 8, !tbaa !5
  br label %122

121:                                              ; preds = %44
  store ptr null, ptr %3, align 8, !tbaa !5
  br label %122

122:                                              ; preds = %121, %117
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  br label %26, !llvm.loop !20

123:                                              ; preds = %26
  %124 = load i8, ptr %6, align 1, !tbaa !9
  store i8 %124, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %125

125:                                              ; preds = %123, %24
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  %126 = load i8, ptr %2, align 1
  ret i8 %126
}

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

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

declare i32 @sys_arch_protect() #2

declare void @sys_arch_unprotect(i32 noundef) #2

declare void @memp_free(i32 noundef, ptr noundef) #2

declare void @mem_free(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !7, i64 22}
!13 = !{!"pbuf", !6, i64 0, !6, i64 8, !14, i64 16, !14, i64 18, !7, i64 20, !7, i64 21, !7, i64 22, !7, i64 23}
!14 = !{!"short", !7, i64 0}
!15 = !{!13, !6, i64 0}
!16 = !{!13, !7, i64 20}
!17 = !{!13, !7, i64 21}
!18 = !{!19, !6, i64 24}
!19 = !{!"pbuf_custom", !13, i64 0, !6, i64 24}
!20 = distinct !{!20, !21}
!21 = !{!"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.10 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @pbuf_free(ptr noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %3, label %.preheader

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

.preheader:                                       ; preds = %1, %35
  %.02332 = phi ptr [ %15, %35 ], [ %0, %1 ]
  %.02431 = phi i8 [ %36, %35 ], [ 0, %1 ]
  %5 = tail call i32 @sys_arch_protect() #3
  %6 = getelementptr inbounds i8, ptr %.02332, i64 22
  %7 = load i8, ptr %6, align 2, !tbaa !5
  %.not28 = icmp eq i8 %7, 0
  br i1 %.not28, label %8, label %10

8:                                                ; preds = %.preheader
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.12, i32 noundef 753, ptr noundef nonnull @.str.2)
  %.pre = load i8, ptr %6, align 2, !tbaa !5
  br label %10

10:                                               ; preds = %8, %.preheader
  %11 = phi i8 [ %.pre, %8 ], [ %7, %.preheader ]
  %12 = add i8 %11, -1
  store i8 %12, ptr %6, align 2, !tbaa !5
  tail call void @sys_arch_unprotect(i32 noundef %5) #3
  %13 = icmp eq i8 %12, 0
  br i1 %13, label %14, label %.loopexit

14:                                               ; preds = %10
  %15 = load ptr, ptr %.02332, align 8, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %.02332, i64 21
  %17 = load i8, ptr %16, align 1, !tbaa !12
  %18 = and i8 %17, 2
  %.not29 = icmp eq i8 %18, 0
  br i1 %.not29, label %26, label %19

19:                                               ; preds = %14
  %20 = getelementptr inbounds i8, ptr %.02332, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %.not30 = icmp eq ptr %21, null
  br i1 %.not30, label %22, label %24

22:                                               ; preds = %19
  %23 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.13, i32 noundef 767, ptr noundef nonnull @.str.2)
  %.pre33 = load ptr, ptr %20, align 8, !tbaa !13
  br label %24

24:                                               ; preds = %22, %19
  %25 = phi ptr [ %.pre33, %22 ], [ %21, %19 ]
  tail call void %25(ptr noundef nonnull %.02332) #3
  br label %35

26:                                               ; preds = %14
  %27 = getelementptr inbounds i8, ptr %.02332, i64 20
  %28 = load i8, ptr %27, align 4, !tbaa !15
  %29 = and i8 %28, 15
  switch i8 %29, label %33 [
    i8 2, label %30
    i8 1, label %31
    i8 0, label %32
  ]

30:                                               ; preds = %26
  tail call void @memp_free(i32 noundef 13, ptr noundef nonnull %.02332) #3
  br label %35

31:                                               ; preds = %26
  tail call void @memp_free(i32 noundef 12, ptr noundef nonnull %.02332) #3
  br label %35

32:                                               ; preds = %26
  tail call void @mem_free(ptr noundef nonnull %.02332) #3
  br label %35

33:                                               ; preds = %26
  %34 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.14, i32 noundef 783, ptr noundef nonnull @.str.2)
  br label %35

35:                                               ; preds = %24, %31, %33, %32, %30
  %36 = add i8 %.02431, 1
  %.not = icmp eq ptr %15, null
  br i1 %.not, label %.loopexit, label %.preheader, !llvm.loop !16

.loopexit:                                        ; preds = %10, %35, %3
  %.0 = phi i8 [ 0, %3 ], [ %.02431, %10 ], [ %36, %35 ]
  ret i8 %.0
}

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

declare i32 @sys_arch_protect() local_unnamed_addr #2

declare void @sys_arch_unprotect(i32 noundef) local_unnamed_addr #2

declare void @memp_free(i32 noundef, ptr noundef) local_unnamed_addr #2

declare void @mem_free(ptr noundef) local_unnamed_addr #2

attributes #0 = { 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 #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 = { "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, !8, i64 22}
!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 0}
!12 = !{!6, !8, i64 21}
!13 = !{!14, !7, i64 24}
!14 = !{!"pbuf_custom", !6, i64 0, !7, i64 24}
!15 = !{!6, !8, i64 20}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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