; 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.ip4_addr = type { i32 }
%struct.sockaddr = type { i8, i8, [14 x i8] }
%struct.lwip_sock = type { ptr, %union.lwip_sock_lastdata, i16, i16, i16, i8 }
%union.lwip_sock_lastdata = type { ptr }
%struct.sockaddr_in = type { i8, i8, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }

@errno = external global i32, align 4
@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [181 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [30 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
declare hidden ptr @get_socket(i32 noundef) #1

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

declare i32 @err_to_errno(i8 noundef signext) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @lwip_connect(i32 noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca %struct.ip4_addr, align 4
  %13 = alloca i16, align 2
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = call ptr @get_socket(i32 noundef %17)
  store ptr %18, ptr %8, align 8, !tbaa !9
  %19 = load ptr, ptr %8, align 8, !tbaa !9
  %20 = icmp ne ptr %19, null
  br i1 %20, label %22, label %21

21:                                               ; preds = %3
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %141

22:                                               ; preds = %3
  %23 = load ptr, ptr %6, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.sockaddr, ptr %23, i32 0, i32 1
  %25 = load i8, ptr %24, align 1, !tbaa !11
  %26 = zext i8 %25 to i32
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %42, label %28

28:                                               ; preds = %22
  br i1 true, label %42, label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %31 = call i32 @err_to_errno(i8 noundef signext -6)
  store i32 %31, ptr %11, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %30
  %33 = load i32, ptr %11, align 4, !tbaa !5
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %37

35:                                               ; preds = %32
  %36 = load i32, ptr %11, align 4, !tbaa !5
  store i32 %36, ptr @errno, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %35, %32
  br label %38

38:                                               ; preds = %37
  br label %39

39:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %40

40:                                               ; preds = %39
  br label %41

41:                                               ; preds = %40
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %141

42:                                               ; preds = %28, %22
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = load ptr, ptr %6, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.sockaddr, ptr %44, i32 0, i32 1
  %46 = load i8, ptr %45, align 1, !tbaa !11
  %47 = zext i8 %46 to i32
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %54

49:                                               ; preds = %42
  %50 = load ptr, ptr %8, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.lwip_sock, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !13
  %53 = call signext i8 @netconn_disconnect(ptr noundef %52)
  store i8 %53, ptr %9, align 1, !tbaa !16
  br label %116

54:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %13) #3
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = zext i32 %56 to i64
  %58 = icmp eq i64 %57, 16
  br i1 %58, label %59, label %76

59:                                               ; preds = %55
  %60 = load ptr, ptr %6, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.sockaddr, ptr %60, i32 0, i32 1
  %62 = load i8, ptr %61, align 1, !tbaa !11
  %63 = zext i8 %62 to i32
  %64 = icmp eq i32 %63, 0
  br i1 %64, label %71, label %65

65:                                               ; preds = %59
  %66 = load ptr, ptr %6, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.sockaddr, ptr %66, i32 0, i32 1
  %68 = load i8, ptr %67, align 1, !tbaa !11
  %69 = zext i8 %68 to i32
  %70 = icmp eq i32 %69, 2
  br i1 %70, label %71, label %76

71:                                               ; preds = %65, %59
  %72 = load ptr, ptr %6, align 8, !tbaa !9
  %73 = ptrtoint ptr %72 to i64
  %74 = urem i64 %73, 4
  %75 = icmp eq i64 %74, 0
  br i1 %75, label %93, label %76

76:                                               ; preds = %71, %65, %55
  br label %77

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

79:                                               ; preds = %77
  br label %80

80:                                               ; preds = %79
  br label %81

81:                                               ; preds = %80
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %82 = call i32 @err_to_errno(i8 noundef signext -16)
  store i32 %82, ptr %14, align 4, !tbaa !5
  br label %83

83:                                               ; preds = %81
  %84 = load i32, ptr %14, align 4, !tbaa !5
  %85 = icmp ne i32 %84, 0
  br i1 %85, label %86, label %88

86:                                               ; preds = %83
  %87 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %87, ptr @errno, align 4, !tbaa !5
  br label %88

88:                                               ; preds = %86, %83
  br label %89

89:                                               ; preds = %88
  br label %90

90:                                               ; preds = %89
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %91

91:                                               ; preds = %90
  br label %92

92:                                               ; preds = %91
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %113

93:                                               ; preds = %71
  br label %94

94:                                               ; preds = %93
  br label %95

95:                                               ; preds = %94
  br label %96

96:                                               ; preds = %95
  %97 = load ptr, ptr %6, align 8, !tbaa !9
  %98 = getelementptr inbounds %struct.sockaddr_in, ptr %97, i32 0, i32 3
  %99 = getelementptr inbounds %struct.in_addr, ptr %98, i32 0, i32 0
  %100 = load i32, ptr %99, align 4, !tbaa !17
  %101 = getelementptr inbounds %struct.ip4_addr, ptr %12, i32 0, i32 0
  store i32 %100, ptr %101, align 4, !tbaa !20
  %102 = load ptr, ptr %6, align 8, !tbaa !9
  %103 = getelementptr inbounds %struct.sockaddr_in, ptr %102, i32 0, i32 2
  %104 = load i16, ptr %103, align 2, !tbaa !22
  %105 = call zeroext i16 @lwip_htons(i16 noundef zeroext %104)
  store i16 %105, ptr %13, align 2, !tbaa !23
  br label %106

106:                                              ; preds = %96
  br label %107

107:                                              ; preds = %106
  %108 = load ptr, ptr %8, align 8, !tbaa !9
  %109 = getelementptr inbounds %struct.lwip_sock, ptr %108, i32 0, i32 0
  %110 = load ptr, ptr %109, align 8, !tbaa !13
  %111 = load i16, ptr %13, align 2, !tbaa !23
  %112 = call signext i8 @netconn_connect(ptr noundef %110, ptr noundef %12, i16 noundef zeroext %111)
  store i8 %112, ptr %9, align 1, !tbaa !16
  store i32 0, ptr %10, align 4
  br label %113

113:                                              ; preds = %107, %92
  call void @llvm.lifetime.end.p0(i64 2, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %114 = load i32, ptr %10, align 4
  switch i32 %114, label %141 [
    i32 0, label %115
  ]

115:                                              ; preds = %113
  br label %116

116:                                              ; preds = %115, %49
  %117 = load i8, ptr %9, align 1, !tbaa !16
  %118 = sext i8 %117 to i32
  %119 = icmp ne i32 %118, 0
  br i1 %119, label %120, label %134

120:                                              ; preds = %116
  br label %121

121:                                              ; preds = %120
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %122 = load i8, ptr %9, align 1, !tbaa !16
  %123 = call i32 @err_to_errno(i8 noundef signext %122)
  store i32 %123, ptr %15, align 4, !tbaa !5
  br label %124

124:                                              ; preds = %121
  %125 = load i32, ptr %15, align 4, !tbaa !5
  %126 = icmp ne i32 %125, 0
  br i1 %126, label %127, label %129

127:                                              ; preds = %124
  %128 = load i32, ptr %15, align 4, !tbaa !5
  store i32 %128, ptr @errno, align 4, !tbaa !5
  br label %129

129:                                              ; preds = %127, %124
  br label %130

130:                                              ; preds = %129
  br label %131

131:                                              ; preds = %130
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  br label %132

132:                                              ; preds = %131
  br label %133

133:                                              ; preds = %132
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %141

134:                                              ; preds = %116
  br label %135

135:                                              ; preds = %134
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  store i32 0, ptr %16, align 4, !tbaa !5
  br label %136

136:                                              ; preds = %135
  br label %137

137:                                              ; preds = %136
  br label %138

138:                                              ; preds = %137
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  br label %139

139:                                              ; preds = %138
  br label %140

140:                                              ; preds = %139
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %141

141:                                              ; preds = %140, %133, %113, %41, %21
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %142 = load i32, ptr %4, align 4
  ret i32 %142
}

declare signext i8 @netconn_disconnect(ptr noundef) #2

declare signext i8 @netconn_connect(ptr noundef, ptr noundef, i16 noundef zeroext) #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !7, i64 1}
!12 = !{!"sockaddr", !7, i64 0, !7, i64 1, !7, i64 2}
!13 = !{!14, !10, i64 0}
!14 = !{!"lwip_sock", !10, i64 0, !7, i64 8, !15, i64 16, !15, i64 18, !15, i64 20, !7, i64 22}
!15 = !{!"short", !7, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !6, i64 4}
!18 = !{!"sockaddr_in", !7, i64 0, !7, i64 1, !15, i64 2, !19, i64 4, !7, i64 8}
!19 = !{!"in_addr", !6, i64 0}
!20 = !{!21, !6, i64 0}
!21 = !{!"ip4_addr", !6, i64 0}
!22 = !{!18, !15, i64 2}
!23 = !{!15, !15, 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"

%struct.ip4_addr = type { i32 }

@errno = external local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [181 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [30 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: nounwind uwtable
declare hidden ptr @get_socket(i32 noundef) 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

declare i32 @err_to_errno(i8 noundef signext) local_unnamed_addr #2

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @lwip_connect(i32 noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca %struct.ip4_addr, align 4
  %5 = tail call ptr @get_socket(i32 noundef %0)
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %34, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %1, i64 1
  %8 = load i8, ptr %7, align 1, !tbaa !5
  %9 = icmp eq i8 %8, 0
  br i1 %9, label %10, label %13

10:                                               ; preds = %6
  %11 = load ptr, ptr %5, align 8, !tbaa !9
  %12 = tail call signext i8 @netconn_disconnect(ptr noundef %11) #4
  br label %30

13:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  %14 = icmp eq i32 %2, 16
  %cond = icmp eq i8 %8, 2
  %or.cond = and i1 %14, %cond
  %15 = ptrtoint ptr %1 to i64
  %16 = and i64 %15, 3
  %17 = icmp eq i64 %16, 0
  %or.cond34 = and i1 %17, %or.cond
  br i1 %or.cond34, label %22, label %18

18:                                               ; preds = %13
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.6, i32 noundef 841, ptr noundef nonnull @.str.2)
  %20 = tail call i32 @err_to_errno(i8 noundef signext -16) #4
  %.not27 = icmp eq i32 %20, 0
  br i1 %.not27, label %.thread, label %21

21:                                               ; preds = %18
  store i32 %20, ptr @errno, align 4, !tbaa !13
  br label %.thread

.thread:                                          ; preds = %21, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  br label %34

22:                                               ; preds = %13
  %23 = getelementptr inbounds i8, ptr %1, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !15
  store i32 %24, ptr %4, align 4, !tbaa !18
  %25 = getelementptr inbounds i8, ptr %1, i64 2
  %26 = load i16, ptr %25, align 2, !tbaa !20
  %27 = tail call zeroext i16 @lwip_htons(i16 noundef zeroext %26) #4
  %28 = load ptr, ptr %5, align 8, !tbaa !9
  %29 = call signext i8 @netconn_connect(ptr noundef %28, ptr noundef nonnull %4, i16 noundef zeroext %27) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  br label %30

30:                                               ; preds = %22, %10
  %.122 = phi i8 [ %12, %10 ], [ %29, %22 ]
  %.not28 = icmp eq i8 %.122, 0
  br i1 %.not28, label %34, label %31

31:                                               ; preds = %30
  %32 = call i32 @err_to_errno(i8 noundef signext %.122) #4
  %.not29 = icmp eq i32 %32, 0
  br i1 %.not29, label %34, label %33

33:                                               ; preds = %31
  store i32 %32, ptr @errno, align 4, !tbaa !13
  br label %34

34:                                               ; preds = %.thread, %30, %31, %33, %3
  %.1 = phi i32 [ -1, %3 ], [ -1, %33 ], [ -1, %31 ], [ 0, %30 ], [ -1, %.thread ]
  ret i32 %.1
}

declare signext i8 @netconn_disconnect(ptr noundef) local_unnamed_addr #2

declare signext i8 @netconn_connect(ptr noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { 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 #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, !7, i64 1}
!6 = !{!"sockaddr", !7, i64 0, !7, i64 1, !7, i64 2}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"lwip_sock", !11, i64 0, !7, i64 8, !12, i64 16, !12, i64 18, !12, i64 20, !7, i64 22}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !14, i64 4}
!16 = !{!"sockaddr_in", !7, i64 0, !7, i64 1, !12, i64 2, !17, i64 4, !7, i64 8}
!17 = !{!"in_addr", !14, i64 0}
!18 = !{!19, !14, i64 0}
!19 = !{!"ip4_addr", !14, i64 0}
!20 = !{!16, !12, i64 2}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass