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

; 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.tcp_pcb = type { %struct.ip4_addr, %struct.ip4_addr, i8, i8, i8, i8, ptr, ptr, i32, i8, i16, i16, i16, i8, i8, i8, i32, i32, i16, i16, i32, i16, i16, i32, i32, i16, i16, i16, i8, i8, i32, i16, i16, i32, i32, i32, i32, i32, i16, i16, i16, i16, i16, i16, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i8, i8, i8, i8 }
%struct.ip4_addr = type { i32 }
%struct.tcp_seg = type { ptr, ptr, i16, i8, ptr }
%struct.tcp_hdr = type { i16, i16, i32, i32, i16, i16, i16, i16 }

@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [182 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [26 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

declare zeroext i16 @lwip_htons(i16 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local signext i8 @tcp_send_fin(ptr noundef %0) #2 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %1
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %13, label %9

9:                                                ; preds = %6
  br label %10

10:                                               ; preds = %9
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.20, i32 noundef 1003, ptr noundef @.str.2)
  br label %12

12:                                               ; preds = %10
  br label %13

13:                                               ; preds = %12, %6
  br label %14

14:                                               ; preds = %13
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.tcp_pcb, ptr %15, i32 0, i32 44
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %76

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.tcp_pcb, ptr %20, i32 0, i32 44
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  store ptr %22, ptr %4, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %29, %19
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.tcp_seg, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %33

28:                                               ; preds = %23
  br label %29

29:                                               ; preds = %28
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.tcp_seg, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  store ptr %32, ptr %4, align 8, !tbaa !5
  br label %23, !llvm.loop !16

33:                                               ; preds = %23
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.tcp_seg, ptr %34, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !18
  %37 = getelementptr inbounds %struct.tcp_hdr, ptr %36, i32 0, i32 4
  %38 = load i16, ptr %37, align 1, !tbaa !19
  %39 = call zeroext i16 @lwip_htons(i16 noundef zeroext %38)
  %40 = zext i16 %39 to i32
  %41 = and i32 %40, 63
  %42 = trunc i32 %41 to i8
  %43 = zext i8 %42 to i32
  %44 = and i32 %43, 7
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %46, label %72

46:                                               ; preds = %33
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.tcp_seg, ptr %47, i32 0, i32 4
  %49 = load ptr, ptr %48, align 8, !tbaa !18
  %50 = getelementptr inbounds %struct.tcp_hdr, ptr %49, i32 0, i32 4
  %51 = load i16, ptr %50, align 1, !tbaa !19
  %52 = zext i16 %51 to i32
  %53 = call zeroext i16 @lwip_htons(i16 noundef zeroext 1)
  %54 = zext i16 %53 to i32
  %55 = or i32 %52, %54
  %56 = trunc i32 %55 to i16
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.tcp_seg, ptr %57, i32 0, i32 4
  %59 = load ptr, ptr %58, align 8, !tbaa !18
  %60 = getelementptr inbounds %struct.tcp_hdr, ptr %59, i32 0, i32 4
  store i16 %56, ptr %60, align 1, !tbaa !19
  br label %61

61:                                               ; preds = %46
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.tcp_pcb, ptr %62, i32 0, i32 12
  %64 = load i16, ptr %63, align 2, !tbaa !21
  %65 = zext i16 %64 to i32
  %66 = or i32 %65, 32
  %67 = trunc i32 %66 to i16
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.tcp_pcb, ptr %68, i32 0, i32 12
  store i16 %67, ptr %69, align 2, !tbaa !21
  br label %70

70:                                               ; preds = %61
  br label %71

71:                                               ; preds = %70
  store i8 0, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %73

72:                                               ; preds = %33
  store i32 0, ptr %5, align 4
  br label %73

73:                                               ; preds = %72, %71
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %74 = load i32, ptr %5, align 4
  switch i32 %74, label %81 [
    i32 0, label %75
    i32 1, label %79
  ]

75:                                               ; preds = %73
  br label %76

76:                                               ; preds = %75, %14
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = call signext i8 @tcp_enqueue_flags(ptr noundef %77, i8 noundef zeroext 1)
  store i8 %78, ptr %2, align 1
  br label %79

79:                                               ; preds = %76, %73
  %80 = load i8, ptr %2, align 1
  ret i8 %80

81:                                               ; preds = %73
  unreachable
}

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @tcp_enqueue_flags(ptr noundef, i8 noundef zeroext) #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, !6, i64 128}
!10 = !{!"tcp_pcb", !11, i64 0, !11, i64 4, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !6, i64 16, !6, i64 24, !12, i64 32, !7, i64 36, !13, i64 38, !13, i64 40, !13, i64 42, !7, i64 44, !7, i64 45, !7, i64 46, !12, i64 48, !12, i64 52, !13, i64 56, !13, i64 58, !12, i64 60, !13, i64 64, !13, i64 66, !12, i64 68, !12, i64 72, !13, i64 76, !13, i64 78, !13, i64 80, !7, i64 82, !7, i64 83, !12, i64 84, !13, i64 88, !13, i64 90, !12, i64 92, !12, i64 96, !12, i64 100, !12, i64 104, !12, i64 108, !13, i64 112, !13, i64 114, !13, i64 116, !13, i64 118, !13, i64 120, !13, i64 122, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !12, i64 200, !7, i64 204, !7, i64 205, !7, i64 206, !7, i64 207}
!11 = !{!"ip4_addr", !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"tcp_seg", !6, i64 0, !6, i64 8, !13, i64 16, !7, i64 18, !6, i64 24}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!15, !6, i64 24}
!19 = !{!20, !13, i64 12}
!20 = !{!"tcp_hdr", !13, i64 0, !13, i64 2, !12, i64 4, !12, i64 8, !13, i64 12, !13, i64 14, !13, i64 16, !13, i64 18}
!21 = !{!10, !13, i64 42}


; 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 [182 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [26 x i8], align 1

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

declare zeroext i16 @lwip_htons(i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local signext i8 @tcp_send_fin(ptr noundef %0) local_unnamed_addr #2 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %2, label %4

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

4:                                                ; preds = %1, %2
  %5 = getelementptr inbounds i8, ptr %0, i64 128
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not16 = icmp eq ptr %6, null
  br i1 %.not16, label %.thread, label %.preheader

.preheader:                                       ; preds = %4, %.preheader
  %.012 = phi ptr [ %7, %.preheader ], [ %6, %4 ]
  %7 = load ptr, ptr %.012, align 8, !tbaa !13
  %.not17 = icmp eq ptr %7, null
  br i1 %.not17, label %8, label %.preheader, !llvm.loop !15

8:                                                ; preds = %.preheader
  %9 = getelementptr inbounds i8, ptr %.012, i64 24
  %10 = load ptr, ptr %9, align 8, !tbaa !17
  %11 = getelementptr inbounds i8, ptr %10, i64 12
  %12 = load i16, ptr %11, align 1, !tbaa !18
  %13 = tail call zeroext i16 @lwip_htons(i16 noundef zeroext %12) #3
  %14 = and i16 %13, 7
  %15 = icmp eq i16 %14, 0
  br i1 %15, label %16, label %.thread

16:                                               ; preds = %8
  %17 = load ptr, ptr %9, align 8, !tbaa !17
  %18 = getelementptr inbounds i8, ptr %17, i64 12
  %19 = load i16, ptr %18, align 1, !tbaa !18
  %20 = tail call zeroext i16 @lwip_htons(i16 noundef zeroext 1) #3
  %21 = or i16 %20, %19
  %22 = load ptr, ptr %9, align 8, !tbaa !17
  %23 = getelementptr inbounds i8, ptr %22, i64 12
  store i16 %21, ptr %23, align 1, !tbaa !18
  %24 = getelementptr inbounds i8, ptr %0, i64 42
  %25 = load i16, ptr %24, align 2, !tbaa !20
  %26 = or i16 %25, 32
  store i16 %26, ptr %24, align 2, !tbaa !20
  br label %28

.thread:                                          ; preds = %8, %4
  %27 = tail call signext i8 @tcp_enqueue_flags(ptr noundef %0, i8 noundef zeroext 1)
  br label %28

28:                                               ; preds = %16, %.thread
  %.1 = phi i8 [ 0, %16 ], [ %27, %.thread ]
  ret i8 %.1
}

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @tcp_enqueue_flags(ptr noundef, i8 noundef zeroext) local_unnamed_addr #2

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 = { "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, !11, i64 128}
!6 = !{!"tcp_pcb", !7, i64 0, !7, i64 4, !9, i64 8, !9, i64 9, !9, i64 10, !9, i64 11, !11, i64 16, !11, i64 24, !8, i64 32, !9, i64 36, !12, i64 38, !12, i64 40, !12, i64 42, !9, i64 44, !9, i64 45, !9, i64 46, !8, i64 48, !8, i64 52, !12, i64 56, !12, i64 58, !8, i64 60, !12, i64 64, !12, i64 66, !8, i64 68, !8, i64 72, !12, i64 76, !12, i64 78, !12, i64 80, !9, i64 82, !9, i64 83, !8, i64 84, !12, i64 88, !12, i64 90, !8, i64 92, !8, i64 96, !8, i64 100, !8, i64 104, !8, i64 108, !12, i64 112, !12, i64 114, !12, i64 116, !12, i64 118, !12, i64 120, !12, i64 122, !11, i64 128, !11, i64 136, !11, i64 144, !11, i64 152, !11, i64 160, !11, i64 168, !11, i64 176, !11, i64 184, !11, i64 192, !8, i64 200, !9, i64 204, !9, i64 205, !9, i64 206, !9, i64 207}
!7 = !{!"ip4_addr", !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"short", !9, i64 0}
!13 = !{!14, !11, i64 0}
!14 = !{!"tcp_seg", !11, i64 0, !11, i64 8, !12, i64 16, !9, i64 18, !11, i64 24}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!14, !11, i64 24}
!18 = !{!19, !12, i64 12}
!19 = !{!"tcp_hdr", !12, i64 0, !12, i64 2, !8, i64 4, !8, i64 8, !12, i64 12, !12, i64 14, !12, i64 16, !12, i64 18}
!20 = !{!6, !12, i64 42}


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