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

; 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.30 = external hidden unnamed_addr constant [36 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

declare i32 @lwip_htonl(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local signext i8 @tcp_rexmit_rto_prepare(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
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  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 %14, label %9

9:                                                ; preds = %6
  br label %10

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

12:                                               ; preds = %10
  br label %13

13:                                               ; preds = %12
  br label %14

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

15:                                               ; preds = %14
  br label %16

16:                                               ; preds = %15
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.tcp_pcb, ptr %17, i32 0, i32 45
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %16
  store i8 -6, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %100

22:                                               ; preds = %16
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.tcp_pcb, ptr %23, i32 0, i32 45
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  store ptr %25, ptr %4, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %37, %22
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.tcp_seg, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %41

31:                                               ; preds = %26
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = call i32 @tcp_output_segment_busy(ptr noundef %32)
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %31
  store i8 -6, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %100

36:                                               ; preds = %31
  br label %37

37:                                               ; preds = %36
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.tcp_seg, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  store ptr %40, ptr %4, align 8, !tbaa !5
  br label %26, !llvm.loop !16

41:                                               ; preds = %26
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = call i32 @tcp_output_segment_busy(ptr noundef %42)
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %41
  store i8 -6, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %100

46:                                               ; preds = %41
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.tcp_pcb, ptr %47, i32 0, i32 44
  %49 = load ptr, ptr %48, align 8, !tbaa !18
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.tcp_seg, ptr %50, i32 0, i32 0
  store ptr %49, ptr %51, align 8, !tbaa !14
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.tcp_pcb, ptr %52, i32 0, i32 45
  %54 = load ptr, ptr %53, align 8, !tbaa !9
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.tcp_pcb, ptr %55, i32 0, i32 44
  store ptr %54, ptr %56, align 8, !tbaa !18
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.tcp_pcb, ptr %57, i32 0, i32 45
  store ptr null, ptr %58, align 8, !tbaa !9
  br label %59

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

68:                                               ; preds = %59
  br label %69

69:                                               ; preds = %68
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.tcp_seg, ptr %70, i32 0, i32 4
  %72 = load ptr, ptr %71, align 8, !tbaa !20
  %73 = getelementptr inbounds %struct.tcp_hdr, ptr %72, i32 0, i32 2
  %74 = load i32, ptr %73, align 1, !tbaa !21
  %75 = call i32 @lwip_htonl(i32 noundef %74)
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.tcp_seg, ptr %76, i32 0, i32 2
  %78 = load i16, ptr %77, align 8, !tbaa !23
  %79 = zext i16 %78 to i32
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.tcp_seg, ptr %80, i32 0, i32 4
  %82 = load ptr, ptr %81, align 8, !tbaa !20
  %83 = getelementptr inbounds %struct.tcp_hdr, ptr %82, i32 0, i32 4
  %84 = load i16, ptr %83, align 1, !tbaa !24
  %85 = call zeroext i16 @lwip_htons(i16 noundef zeroext %84)
  %86 = zext i16 %85 to i32
  %87 = and i32 %86, 63
  %88 = trunc i32 %87 to i8
  %89 = zext i8 %88 to i32
  %90 = and i32 %89, 3
  %91 = icmp ne i32 %90, 0
  %92 = zext i1 %91 to i64
  %93 = select i1 %91, i32 1, i32 0
  %94 = add i32 %79, %93
  %95 = add i32 %75, %94
  %96 = load ptr, ptr %3, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.tcp_pcb, ptr %96, i32 0, i32 33
  store i32 %95, ptr %97, align 4, !tbaa !25
  %98 = load ptr, ptr %3, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.tcp_pcb, ptr %98, i32 0, i32 23
  store i32 0, ptr %99, align 4, !tbaa !26
  store i8 0, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %100

100:                                              ; preds = %69, %45, %35, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %101 = load i8, ptr %2, align 1
  ret i8 %101
}

; Function Attrs: nounwind uwtable
declare hidden i32 @tcp_output_segment_busy(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, !6, i64 136}
!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 = !{!10, !6, i64 128}
!19 = !{!10, !13, i64 42}
!20 = !{!15, !6, i64 24}
!21 = !{!22, !12, i64 4}
!22 = !{!"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}
!23 = !{!15, !13, i64 16}
!24 = !{!22, !13, i64 12}
!25 = !{!10, !12, i64 92}
!26 = !{!10, !12, i64 68}


; 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.30 = external hidden unnamed_addr constant [36 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

declare i32 @lwip_htonl(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local signext range(i8 -6, 1) i8 @tcp_rexmit_rto_prepare(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.30, i32 noundef 1635, ptr noundef nonnull @.str.2)
  br label %4

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

.preheader:                                       ; preds = %4
  %8 = load ptr, ptr %6, align 8, !tbaa !13
  %.not2126 = icmp eq ptr %8, null
  br i1 %.not2126, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %10
  %.027 = phi ptr [ %11, %10 ], [ %6, %.preheader ]
  %9 = tail call i32 @tcp_output_segment_busy(ptr noundef nonnull %.027)
  %.not24 = icmp eq i32 %9, 0
  br i1 %.not24, label %10, label %.loopexit

10:                                               ; preds = %.lr.ph
  %11 = load ptr, ptr %.027, align 8, !tbaa !13
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %.not21 = icmp eq ptr %12, null
  br i1 %.not21, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %10, %.preheader
  %.0.lcssa = phi ptr [ %6, %.preheader ], [ %11, %10 ]
  %13 = tail call i32 @tcp_output_segment_busy(ptr noundef nonnull %.0.lcssa)
  %.not22 = icmp eq i32 %13, 0
  br i1 %.not22, label %14, label %.loopexit

14:                                               ; preds = %._crit_edge
  %15 = getelementptr inbounds i8, ptr %0, i64 128
  %16 = load ptr, ptr %15, align 8, !tbaa !17
  store ptr %16, ptr %.0.lcssa, align 8, !tbaa !13
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %17, ptr %15, align 8, !tbaa !17
  store ptr null, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %0, i64 42
  %19 = load i16, ptr %18, align 2, !tbaa !18
  %20 = or i16 %19, 2048
  store i16 %20, ptr %18, align 2, !tbaa !18
  %21 = getelementptr inbounds i8, ptr %.0.lcssa, i64 24
  %22 = load ptr, ptr %21, align 8, !tbaa !19
  %23 = getelementptr inbounds i8, ptr %22, i64 4
  %24 = load i32, ptr %23, align 1, !tbaa !20
  %25 = tail call i32 @lwip_htonl(i32 noundef %24) #3
  %26 = getelementptr inbounds i8, ptr %.0.lcssa, i64 16
  %27 = load i16, ptr %26, align 8, !tbaa !22
  %28 = zext i16 %27 to i32
  %29 = load ptr, ptr %21, align 8, !tbaa !19
  %30 = getelementptr inbounds i8, ptr %29, i64 12
  %31 = load i16, ptr %30, align 1, !tbaa !23
  %32 = tail call zeroext i16 @lwip_htons(i16 noundef zeroext %31) #3
  %33 = and i16 %32, 3
  %.not23 = icmp ne i16 %33, 0
  %34 = zext i1 %.not23 to i32
  %35 = add i32 %25, %28
  %36 = add i32 %35, %34
  %37 = getelementptr inbounds i8, ptr %0, i64 92
  store i32 %36, ptr %37, align 4, !tbaa !24
  %38 = getelementptr inbounds i8, ptr %0, i64 68
  store i32 0, ptr %38, align 4, !tbaa !25
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %._crit_edge, %4, %14
  %.019 = phi i8 [ 0, %14 ], [ -6, %4 ], [ -6, %._crit_edge ], [ -6, %.lr.ph ]
  ret i8 %.019
}

; Function Attrs: nounwind uwtable
declare hidden i32 @tcp_output_segment_busy(ptr noundef) 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 136}
!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 = !{!6, !11, i64 128}
!18 = !{!6, !12, i64 42}
!19 = !{!14, !11, i64 24}
!20 = !{!21, !8, i64 4}
!21 = !{!"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}
!22 = !{!14, !12, i64 16}
!23 = !{!21, !12, i64 12}
!24 = !{!6, !8, i64 92}
!25 = !{!6, !8, i64 68}


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