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

; 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.lwip_sock = type { ptr, %union.lwip_sock_lastdata, i16, i16, i16, i8 }
%union.lwip_sock_lastdata = type { ptr }
%struct.netconn = type { i32, i32, %union.anon, i8, ptr, ptr, ptr, i32, i32, i32, i8, ptr, ptr }
%union.anon = type { ptr }

@errno = external global i32, align 4

; 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

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

20:                                               ; preds = %4
  store i64 -1, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %77

21:                                               ; preds = %4
  %22 = load ptr, ptr %10, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.lwip_sock, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = getelementptr inbounds %struct.netconn, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !16
  %27 = and i32 %26, 240
  %28 = icmp ne i32 %27, 16
  br i1 %28, label %29, label %35

29:                                               ; preds = %21
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = load ptr, ptr %7, align 8, !tbaa !9
  %32 = load i64, ptr %8, align 8, !tbaa !11
  %33 = load i32, ptr %9, align 4, !tbaa !5
  %34 = call i64 @lwip_sendto(i32 noundef %30, ptr noundef %31, i64 noundef %32, i32 noundef %33, ptr noundef null, i32 noundef 0)
  store i64 %34, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %77

35:                                               ; preds = %21
  %36 = load i32, ptr %9, align 4, !tbaa !5
  %37 = and i32 %36, 16
  %38 = icmp ne i32 %37, 0
  %39 = zext i1 %38 to i64
  %40 = select i1 %38, i32 2, i32 0
  %41 = or i32 1, %40
  %42 = load i32, ptr %9, align 4, !tbaa !5
  %43 = and i32 %42, 8
  %44 = icmp ne i32 %43, 0
  %45 = zext i1 %44 to i64
  %46 = select i1 %44, i32 4, i32 0
  %47 = or i32 %41, %46
  %48 = trunc i32 %47 to i8
  store i8 %48, ptr %12, align 1, !tbaa !18
  store i64 0, ptr %13, align 8, !tbaa !11
  %49 = load ptr, ptr %10, align 8, !tbaa !9
  %50 = getelementptr inbounds %struct.lwip_sock, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !13
  %52 = load ptr, ptr %7, align 8, !tbaa !9
  %53 = load i64, ptr %8, align 8, !tbaa !11
  %54 = load i8, ptr %12, align 1, !tbaa !18
  %55 = call signext i8 @netconn_write_partly(ptr noundef %51, ptr noundef %52, i64 noundef %53, i8 noundef zeroext %54, ptr noundef %13)
  store i8 %55, ptr %11, align 1, !tbaa !18
  br label %56

56:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %57 = load i8, ptr %11, align 1, !tbaa !18
  %58 = call i32 @err_to_errno(i8 noundef signext %57)
  store i32 %58, ptr %15, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %56
  %60 = load i32, ptr %15, align 4, !tbaa !5
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %64

62:                                               ; preds = %59
  %63 = load i32, ptr %15, align 4, !tbaa !5
  store i32 %63, ptr @errno, align 4, !tbaa !5
  br label %64

64:                                               ; preds = %62, %59
  br label %65

65:                                               ; preds = %64
  br label %66

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

67:                                               ; preds = %66
  br label %68

68:                                               ; preds = %67
  %69 = load i8, ptr %11, align 1, !tbaa !18
  %70 = sext i8 %69 to i32
  %71 = icmp eq i32 %70, 0
  br i1 %71, label %72, label %74

72:                                               ; preds = %68
  %73 = load i64, ptr %13, align 8, !tbaa !11
  br label %75

74:                                               ; preds = %68
  br label %75

75:                                               ; preds = %74, %72
  %76 = phi i64 [ %73, %72 ], [ -1, %74 ]
  store i64 %76, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %77

77:                                               ; preds = %75, %29, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %78 = load i64, ptr %5, align 8
  ret i64 %78
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @lwip_sendto(i32 noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i32 noundef) #1

declare signext i8 @netconn_write_partly(ptr noundef, ptr noundef, i64 noundef, i8 noundef zeroext, ptr noundef) #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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!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 = !{!17, !6, i64 0}
!17 = !{!"netconn", !6, i64 0, !6, i64 4, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !6, i64 48, !6, i64 52, !6, i64 56, !7, i64 60, !10, i64 64, !10, i64 72}
!18 = !{!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"

@errno = external local_unnamed_addr global i32, align 4

; 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: nounwind uwtable
define dso_local i64 @lwip_send(i32 noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %6 = tail call ptr @get_socket(i32 noundef %0)
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %28, label %7

7:                                                ; preds = %4
  %8 = load ptr, ptr %6, align 8, !tbaa !5
  %9 = load i32, ptr %8, align 8, !tbaa !11
  %10 = and i32 %9, 240
  %.not19 = icmp eq i32 %10, 16
  br i1 %.not19, label %13, label %11

11:                                               ; preds = %7
  %12 = tail call i64 @lwip_sendto(i32 noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, ptr noundef null, i32 noundef 0)
  br label %28

13:                                               ; preds = %7
  %14 = lshr i32 %3, 3
  %15 = and i32 %14, 2
  %16 = lshr i32 %3, 1
  %17 = and i32 %16, 4
  %18 = or disjoint i32 %15, %17
  %19 = trunc nuw nsw i32 %18 to i8
  %20 = or disjoint i8 %19, 1
  store i64 0, ptr %5, align 8, !tbaa !14
  %21 = call signext i8 @netconn_write_partly(ptr noundef nonnull %8, ptr noundef %1, i64 noundef %2, i8 noundef zeroext %20, ptr noundef nonnull %5) #3
  %22 = call i32 @err_to_errno(i8 noundef signext %21) #3
  %.not22 = icmp eq i32 %22, 0
  br i1 %.not22, label %24, label %23

23:                                               ; preds = %13
  store i32 %22, ptr @errno, align 4, !tbaa !16
  br label %24

24:                                               ; preds = %23, %13
  %25 = icmp eq i8 %21, 0
  %26 = load i64, ptr %5, align 8
  %27 = select i1 %25, i64 %26, i64 -1
  br label %28

28:                                               ; preds = %4, %24, %11
  %.0 = phi i64 [ %12, %11 ], [ %27, %24 ], [ -1, %4 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  ret i64 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @lwip_sendto(i32 noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare signext i8 @netconn_write_partly(ptr noundef, ptr noundef, i64 noundef, i8 noundef zeroext, ptr noundef) 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 = { 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 0}
!6 = !{!"lwip_sock", !7, i64 0, !8, i64 8, !10, i64 16, !10, i64 18, !10, i64 20, !8, i64 22}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"netconn", !13, i64 0, !13, i64 4, !8, i64 8, !8, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !13, i64 48, !13, i64 52, !13, i64 56, !8, i64 60, !7, i64 64, !7, i64 72}
!13 = !{!"int", !8, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !8, i64 0}
!16 = !{!13, !13, i64 0}


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