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

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

@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [178 x i8], align 1
@udp_pcbs = external dso_local global ptr, align 8
@.str.21 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [28 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 signext i8 @udp_bind(ptr noundef, ptr noundef, i16 noundef zeroext) #2

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

11:                                               ; preds = %3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %19, label %14

14:                                               ; preds = %11
  br label %15

15:                                               ; preds = %14
  %16 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.21, i32 noundef 1077, ptr noundef @.str.2)
  br label %17

17:                                               ; preds = %15
  br label %18

18:                                               ; preds = %17
  store i8 -16, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %96

19:                                               ; preds = %11
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %30, label %25

25:                                               ; preds = %22
  br label %26

26:                                               ; preds = %25
  %27 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.22, i32 noundef 1078, ptr noundef @.str.2)
  br label %28

28:                                               ; preds = %26
  br label %29

29:                                               ; preds = %28
  store i8 -16, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %96

30:                                               ; preds = %22
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.udp_pcb, ptr %33, i32 0, i32 8
  %35 = load i16, ptr %34, align 2, !tbaa !11
  %36 = zext i16 %35 to i32
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %55

38:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #3
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.udp_pcb, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.udp_pcb, ptr %42, i32 0, i32 8
  %44 = load i16, ptr %43, align 2, !tbaa !11
  %45 = call signext i8 @udp_bind(ptr noundef %39, ptr noundef %41, i16 noundef zeroext %44)
  store i8 %45, ptr %10, align 1, !tbaa !15
  %46 = load i8, ptr %10, align 1, !tbaa !15
  %47 = sext i8 %46 to i32
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %51

49:                                               ; preds = %38
  %50 = load i8, ptr %10, align 1, !tbaa !15
  store i8 %50, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %52

51:                                               ; preds = %38
  store i32 0, ptr %9, align 4
  br label %52

52:                                               ; preds = %51, %49
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  %53 = load i32, ptr %9, align 4
  switch i32 %53, label %96 [
    i32 0, label %54
  ]

54:                                               ; preds = %52
  br label %55

55:                                               ; preds = %54, %32
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = icmp eq ptr %56, null
  br i1 %57, label %58, label %59

58:                                               ; preds = %55
  br label %63

59:                                               ; preds = %55
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ip4_addr, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 4, !tbaa !16
  br label %63

63:                                               ; preds = %59, %58
  %64 = phi i32 [ 0, %58 ], [ %62, %59 ]
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.udp_pcb, ptr %65, i32 0, i32 1
  %67 = getelementptr inbounds %struct.ip4_addr, ptr %66, i32 0, i32 0
  store i32 %64, ptr %67, align 4, !tbaa !17
  %68 = load i16, ptr %7, align 2, !tbaa !9
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.udp_pcb, ptr %69, i32 0, i32 9
  store i16 %68, ptr %70, align 4, !tbaa !18
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.udp_pcb, ptr %71, i32 0, i32 7
  %73 = load i8, ptr %72, align 8, !tbaa !19
  %74 = zext i8 %73 to i32
  %75 = or i32 %74, 4
  %76 = trunc i32 %75 to i8
  store i8 %76, ptr %72, align 8, !tbaa !19
  %77 = load ptr, ptr @udp_pcbs, align 8, !tbaa !5
  store ptr %77, ptr %8, align 8, !tbaa !5
  br label %78

78:                                               ; preds = %87, %63
  %79 = load ptr, ptr %8, align 8, !tbaa !5
  %80 = icmp ne ptr %79, null
  br i1 %80, label %81, label %91

81:                                               ; preds = %78
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = icmp eq ptr %82, %83
  br i1 %84, label %85, label %86

85:                                               ; preds = %81
  store i8 0, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %96

86:                                               ; preds = %81
  br label %87

87:                                               ; preds = %86
  %88 = load ptr, ptr %8, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.udp_pcb, ptr %88, i32 0, i32 6
  %90 = load ptr, ptr %89, align 8, !tbaa !20
  store ptr %90, ptr %8, align 8, !tbaa !5
  br label %78, !llvm.loop !21

91:                                               ; preds = %78
  %92 = load ptr, ptr @udp_pcbs, align 8, !tbaa !5
  %93 = load ptr, ptr %5, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.udp_pcb, ptr %93, i32 0, i32 6
  store ptr %92, ptr %94, align 8, !tbaa !20
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %95, ptr @udp_pcbs, align 8, !tbaa !5
  store i8 0, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %96

96:                                               ; preds = %91, %85, %52, %29, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %97 = load i8, ptr %4, align 1
  ret i8 %97
}

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 = !{!"short", !7, i64 0}
!11 = !{!12, !10, i64 26}
!12 = !{!"udp_pcb", !13, i64 0, !13, i64 4, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !6, i64 16, !7, i64 24, !10, i64 26, !10, i64 28, !6, i64 32, !6, i64 40}
!13 = !{!"ip4_addr", !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!13, !14, i64 0}
!17 = !{!12, !14, i64 4}
!18 = !{!12, !10, i64 28}
!19 = !{!12, !7, i64 24}
!20 = !{!12, !6, i64 16}
!21 = distinct !{!21, !22}
!22 = !{!"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 [178 x i8], align 1
@udp_pcbs = external dso_local local_unnamed_addr global ptr, align 8
@.str.21 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [28 x i8], align 1

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

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

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

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

6:                                                ; preds = %3
  %.not24 = icmp eq ptr %1, null
  br i1 %.not24, label %7, label %9

7:                                                ; preds = %6
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.22, i32 noundef 1078, ptr noundef nonnull @.str.2)
  br label %.loopexit

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 26
  %11 = load i16, ptr %10, align 2, !tbaa !5
  %12 = icmp eq i16 %11, 0
  br i1 %12, label %13, label %15

13:                                               ; preds = %9
  %14 = tail call signext i8 @udp_bind(ptr noundef nonnull %0, ptr noundef nonnull %0, i16 noundef zeroext 0)
  %.not25 = icmp eq i8 %14, 0
  br i1 %.not25, label %15, label %.loopexit

15:                                               ; preds = %13, %9
  %16 = load i32, ptr %1, align 4, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %16, ptr %17, align 4, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %0, i64 28
  store i16 %2, ptr %18, align 4, !tbaa !15
  %19 = getelementptr inbounds i8, ptr %0, i64 24
  %20 = load i8, ptr %19, align 8, !tbaa !16
  %21 = or i8 %20, 4
  store i8 %21, ptr %19, align 8, !tbaa !16
  %.02227 = load ptr, ptr @udp_pcbs, align 8, !tbaa !17
  %.not2628 = icmp eq ptr %.02227, null
  br i1 %.not2628, label %._crit_edge, label %.lr.ph

22:                                               ; preds = %.lr.ph
  %23 = getelementptr inbounds i8, ptr %.02229, i64 16
  %.022 = load ptr, ptr %23, align 8, !tbaa !17
  %.not26 = icmp eq ptr %.022, null
  br i1 %.not26, label %._crit_edge, label %.lr.ph, !llvm.loop !18

.lr.ph:                                           ; preds = %15, %22
  %.02229 = phi ptr [ %.022, %22 ], [ %.02227, %15 ]
  %24 = icmp eq ptr %.02229, %0
  br i1 %24, label %.loopexit, label %22

._crit_edge:                                      ; preds = %22, %15
  %25 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %.02227, ptr %25, align 8, !tbaa !20
  store ptr %0, ptr @udp_pcbs, align 8, !tbaa !17
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %13, %._crit_edge, %7, %4
  %.1 = phi i8 [ 0, %._crit_edge ], [ %14, %13 ], [ -16, %7 ], [ -16, %4 ], [ 0, %.lr.ph ]
  ret i8 %.1
}

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 = { 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" }

!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, !12, i64 26}
!6 = !{!"udp_pcb", !7, i64 0, !7, i64 4, !9, i64 8, !9, i64 9, !9, i64 10, !9, i64 11, !11, i64 16, !9, i64 24, !12, i64 26, !12, i64 28, !11, i64 32, !11, i64 40}
!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 = !{!7, !8, i64 0}
!14 = !{!6, !8, i64 4}
!15 = !{!6, !12, i64 28}
!16 = !{!6, !9, i64 24}
!17 = !{!11, !11, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!6, !11, i64 16}


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