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

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

@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.4 = external hidden unnamed_addr constant [27 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_bind(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 %struct.ip4_addr, align 4
  %10 = alloca i16, align 2
  %11 = alloca i8, align 1
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = 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 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #3
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = call ptr @get_socket(i32 noundef %16)
  store ptr %17, ptr %8, align 8, !tbaa !9
  %18 = load ptr, ptr %8, align 8, !tbaa !9
  %19 = icmp ne ptr %18, null
  br i1 %19, label %21, label %20

20:                                               ; preds = %3
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %99

21:                                               ; preds = %3
  br label %22

22:                                               ; preds = %21
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = zext i32 %23 to i64
  %25 = icmp eq i64 %24, 16
  br i1 %25, label %26, label %37

26:                                               ; preds = %22
  %27 = load ptr, ptr %6, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.sockaddr, ptr %27, i32 0, i32 1
  %29 = load i8, ptr %28, align 1, !tbaa !11
  %30 = zext i8 %29 to i32
  %31 = icmp eq i32 %30, 2
  br i1 %31, label %32, label %37

32:                                               ; preds = %26
  %33 = load ptr, ptr %6, align 8, !tbaa !9
  %34 = ptrtoint ptr %33 to i64
  %35 = urem i64 %34, 4
  %36 = icmp eq i64 %35, 0
  br i1 %36, label %54, label %37

37:                                               ; preds = %32, %26, %22
  br label %38

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

40:                                               ; preds = %38
  br label %41

41:                                               ; preds = %40
  br label %42

42:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %43 = call i32 @err_to_errno(i8 noundef signext -16)
  store i32 %43, ptr %13, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %42
  %45 = load i32, ptr %13, align 4, !tbaa !5
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %49

47:                                               ; preds = %44
  %48 = load i32, ptr %13, align 4, !tbaa !5
  store i32 %48, ptr @errno, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %47, %44
  br label %50

50:                                               ; preds = %49
  br label %51

51:                                               ; preds = %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %99

54:                                               ; preds = %32
  br label %55

55:                                               ; preds = %54
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %7, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %56
  %59 = load ptr, ptr %6, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.sockaddr_in, ptr %59, i32 0, i32 3
  %61 = getelementptr inbounds %struct.in_addr, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 4, !tbaa !13
  %63 = getelementptr inbounds %struct.ip4_addr, ptr %9, i32 0, i32 0
  store i32 %62, ptr %63, align 4, !tbaa !17
  %64 = load ptr, ptr %6, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.sockaddr_in, ptr %64, i32 0, i32 2
  %66 = load i16, ptr %65, align 2, !tbaa !19
  %67 = call zeroext i16 @lwip_htons(i16 noundef zeroext %66)
  store i16 %67, ptr %10, align 2, !tbaa !20
  br label %68

68:                                               ; preds = %58
  br label %69

69:                                               ; preds = %68
  %70 = load ptr, ptr %8, align 8, !tbaa !9
  %71 = getelementptr inbounds %struct.lwip_sock, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !21
  %73 = load i16, ptr %10, align 2, !tbaa !20
  %74 = call signext i8 @netconn_bind(ptr noundef %72, ptr noundef %9, i16 noundef zeroext %73)
  store i8 %74, ptr %11, align 1, !tbaa !23
  %75 = load i8, ptr %11, align 1, !tbaa !23
  %76 = sext i8 %75 to i32
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %78, label %92

78:                                               ; preds = %69
  br label %79

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

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

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

87:                                               ; preds = %85, %82
  br label %88

88:                                               ; preds = %87
  br label %89

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

90:                                               ; preds = %89
  br label %91

91:                                               ; preds = %90
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %99

92:                                               ; preds = %69
  br label %93

93:                                               ; preds = %92
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  store i32 0, ptr %15, align 4, !tbaa !5
  br label %94

94:                                               ; preds = %93
  br label %95

95:                                               ; preds = %94
  br label %96

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

97:                                               ; preds = %96
  br label %98

98:                                               ; preds = %97
  store i32 0, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %99

99:                                               ; preds = %98, %91, %53, %20
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %100 = load i32, ptr %4, align 4
  ret i32 %100
}

declare signext i8 @netconn_bind(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, !6, i64 4}
!14 = !{!"sockaddr_in", !7, i64 0, !7, i64 1, !15, i64 2, !16, i64 4, !7, i64 8}
!15 = !{!"short", !7, i64 0}
!16 = !{!"in_addr", !6, i64 0}
!17 = !{!18, !6, i64 0}
!18 = !{!"ip4_addr", !6, i64 0}
!19 = !{!14, !15, i64 2}
!20 = !{!15, !15, i64 0}
!21 = !{!22, !10, i64 0}
!22 = !{!"lwip_sock", !10, i64 0, !7, i64 8, !15, i64 16, !15, i64 18, !15, i64 20, !7, i64 22}
!23 = !{!7, !7, 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.4 = external hidden unnamed_addr constant [27 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_bind(i32 noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca %struct.ip4_addr, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  %5 = tail call ptr @get_socket(i32 noundef %0)
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %28, label %6

6:                                                ; preds = %3
  %7 = icmp eq i32 %2, 16
  br i1 %7, label %8, label %15

8:                                                ; preds = %6
  %9 = getelementptr inbounds i8, ptr %1, i64 1
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %11 = icmp eq i8 %10, 2
  %12 = ptrtoint ptr %1 to i64
  %13 = and i64 %12, 3
  %14 = icmp eq i64 %13, 0
  %or.cond = and i1 %14, %11
  br i1 %or.cond, label %18, label %15

15:                                               ; preds = %6, %8
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.4, i32 noundef 740, ptr noundef nonnull @.str.2)
  %17 = tail call i32 @err_to_errno(i8 noundef signext -16) #4
  %.not19 = icmp eq i32 %17, 0
  br i1 %.not19, label %28, label %.sink.split

18:                                               ; preds = %8
  %19 = getelementptr inbounds i8, ptr %1, i64 4
  %20 = load i32, ptr %19, align 4, !tbaa !9
  store i32 %20, ptr %4, align 4, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %1, i64 2
  %22 = load i16, ptr %21, align 2, !tbaa !16
  %23 = tail call zeroext i16 @lwip_htons(i16 noundef zeroext %22) #4
  %24 = load ptr, ptr %5, align 8, !tbaa !17
  %25 = call signext i8 @netconn_bind(ptr noundef %24, ptr noundef nonnull %4, i16 noundef zeroext %23) #4
  %.not20 = icmp eq i8 %25, 0
  br i1 %.not20, label %28, label %26

26:                                               ; preds = %18
  %27 = call i32 @err_to_errno(i8 noundef signext %25) #4
  %.not21 = icmp eq i32 %27, 0
  br i1 %.not21, label %28, label %.sink.split

.sink.split:                                      ; preds = %26, %15
  %.sink = phi i32 [ %17, %15 ], [ %27, %26 ]
  store i32 %.sink, ptr @errno, align 4, !tbaa !20
  br label %28

28:                                               ; preds = %.sink.split, %18, %26, %15, %3
  %.0 = phi i32 [ -1, %3 ], [ -1, %15 ], [ -1, %26 ], [ 0, %18 ], [ -1, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  ret i32 %.0
}

declare signext i8 @netconn_bind(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, !13, i64 4}
!10 = !{!"sockaddr_in", !7, i64 0, !7, i64 1, !11, i64 2, !12, i64 4, !7, i64 8}
!11 = !{!"short", !7, i64 0}
!12 = !{!"in_addr", !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"ip4_addr", !13, i64 0}
!16 = !{!10, !11, i64 2}
!17 = !{!18, !19, i64 0}
!18 = !{!"lwip_sock", !19, i64 0, !7, i64 8, !11, i64 16, !11, i64 18, !11, i64 20, !7, i64 22}
!19 = !{!"any pointer", !7, i64 0}
!20 = !{!13, !13, i64 0}


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