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

; 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 i32 @lwip_shutdown(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  store i8 0, ptr %8, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  store i8 0, ptr %9, align 1, !tbaa !9
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = call ptr @get_socket(i32 noundef %15)
  store ptr %16, ptr %6, align 8, !tbaa !10
  %17 = load ptr, ptr %6, align 8, !tbaa !10
  %18 = icmp ne ptr %17, null
  br i1 %18, label %20, label %19

19:                                               ; preds = %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %94

20:                                               ; preds = %2
  %21 = load ptr, ptr %6, align 8, !tbaa !10
  %22 = getelementptr inbounds %struct.lwip_sock, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !12
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %41

25:                                               ; preds = %20
  %26 = load ptr, ptr %6, align 8, !tbaa !10
  %27 = getelementptr inbounds %struct.lwip_sock, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !12
  %29 = getelementptr inbounds %struct.netconn, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !15
  %31 = and i32 %30, 240
  %32 = icmp ne i32 %31, 16
  br i1 %32, label %33, label %40

33:                                               ; preds = %25
  br label %34

34:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 95, ptr %11, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %34
  store i32 95, ptr @errno, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %35
  br label %37

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

38:                                               ; preds = %37
  br label %39

39:                                               ; preds = %38
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %94

40:                                               ; preds = %25
  br label %48

41:                                               ; preds = %20
  br label %42

42:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 107, ptr %12, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %42
  store i32 107, ptr @errno, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %43
  br label %45

45:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %46

46:                                               ; preds = %45
  br label %47

47:                                               ; preds = %46
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %94

48:                                               ; preds = %40
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = icmp eq i32 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %48
  store i8 1, ptr %8, align 1, !tbaa !9
  br label %69

52:                                               ; preds = %48
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = icmp eq i32 %53, 1
  br i1 %54, label %55, label %56

55:                                               ; preds = %52
  store i8 1, ptr %9, align 1, !tbaa !9
  br label %68

56:                                               ; preds = %52
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = icmp eq i32 %57, 2
  br i1 %58, label %59, label %60

59:                                               ; preds = %56
  store i8 1, ptr %8, align 1, !tbaa !9
  store i8 1, ptr %9, align 1, !tbaa !9
  br label %67

60:                                               ; preds = %56
  br label %61

61:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 22, ptr %13, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %61
  store i32 22, ptr @errno, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %62
  br label %64

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

65:                                               ; preds = %64
  br label %66

66:                                               ; preds = %65
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %94

67:                                               ; preds = %59
  br label %68

68:                                               ; preds = %67, %55
  br label %69

69:                                               ; preds = %68, %51
  %70 = load ptr, ptr %6, align 8, !tbaa !10
  %71 = getelementptr inbounds %struct.lwip_sock, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !12
  %73 = load i8, ptr %8, align 1, !tbaa !9
  %74 = load i8, ptr %9, align 1, !tbaa !9
  %75 = call signext i8 @netconn_shutdown(ptr noundef %72, i8 noundef zeroext %73, i8 noundef zeroext %74)
  store i8 %75, ptr %7, align 1, !tbaa !9
  br label %76

76:                                               ; preds = %69
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %77 = load i8, ptr %7, align 1, !tbaa !9
  %78 = call i32 @err_to_errno(i8 noundef signext %77)
  store i32 %78, ptr %14, align 4, !tbaa !5
  br label %79

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

82:                                               ; preds = %79
  %83 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %83, ptr @errno, align 4, !tbaa !5
  br label %84

84:                                               ; preds = %82, %79
  br label %85

85:                                               ; preds = %84
  br label %86

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

87:                                               ; preds = %86
  br label %88

88:                                               ; preds = %87
  %89 = load i8, ptr %7, align 1, !tbaa !9
  %90 = sext i8 %89 to i32
  %91 = icmp eq i32 %90, 0
  %92 = zext i1 %91 to i64
  %93 = select i1 %91, i32 0, i32 -1
  store i32 %93, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %94

94:                                               ; preds = %88, %66, %47, %39, %19
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %95 = load i32, ptr %3, align 4
  ret i32 %95
}

declare signext i8 @netconn_shutdown(ptr noundef, i8 noundef zeroext, i8 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"lwip_sock", !11, i64 0, !7, i64 8, !14, i64 16, !14, i64 18, !14, i64 20, !7, i64 22}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"netconn", !6, i64 0, !6, i64 4, !7, i64 8, !7, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !6, i64 48, !6, i64 52, !6, i64 56, !7, i64 60, !11, i64 64, !11, i64 72}


; 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: nounwind uwtable
declare hidden ptr @get_socket(i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @lwip_shutdown(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call ptr @get_socket(i32 noundef %0)
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %20, label %4

4:                                                ; preds = %2
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %.not20 = icmp eq ptr %5, null
  br i1 %.not20, label %10, label %6

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

9:                                                ; preds = %6
  store i32 95, ptr @errno, align 4, !tbaa !14
  br label %20

10:                                               ; preds = %4
  store i32 107, ptr @errno, align 4, !tbaa !14
  br label %20

11:                                               ; preds = %6
  %12 = icmp ult i32 %1, 3
  br i1 %12, label %switch.lookup, label %13

13:                                               ; preds = %11
  store i32 22, ptr @errno, align 4, !tbaa !14
  br label %20

switch.lookup:                                    ; preds = %11
  %switch.cast = trunc nuw i32 %1 to i24
  %switch.shiftamt = shl nuw nsw i24 %switch.cast, 3
  %switch.downshift = lshr i24 65792, %switch.shiftamt
  %switch.masked = trunc i24 %switch.downshift to i8
  %switch.cast23 = trunc nuw i32 %1 to i24
  %switch.shiftamt24 = shl nuw nsw i24 %switch.cast23, 3
  %switch.downshift25 = lshr i24 65537, %switch.shiftamt24
  %switch.masked26 = trunc i24 %switch.downshift25 to i8
  %14 = tail call signext i8 @netconn_shutdown(ptr noundef nonnull %5, i8 noundef zeroext %switch.masked26, i8 noundef zeroext %switch.masked) #2
  %15 = tail call i32 @err_to_errno(i8 noundef signext %14) #2
  %.not22 = icmp eq i32 %15, 0
  br i1 %.not22, label %17, label %16

16:                                               ; preds = %switch.lookup
  store i32 %15, ptr @errno, align 4, !tbaa !14
  br label %17

17:                                               ; preds = %16, %switch.lookup
  %18 = icmp ne i8 %14, 0
  %19 = sext i1 %18 to i32
  br label %20

20:                                               ; preds = %2, %17, %13, %10, %9
  %.0 = phi i32 [ -1, %9 ], [ %19, %17 ], [ -1, %13 ], [ -1, %10 ], [ -1, %2 ]
  ret i32 %.0
}

declare signext i8 @netconn_shutdown(ptr noundef, i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #1

attributes #0 = { 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 #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 }

!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 = !{!13, !13, i64 0}


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