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

; 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

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

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

18:                                               ; preds = %3
  %19 = load i64, ptr %6, align 8, !tbaa !9
  switch i64 %19, label %73 [
    i64 2148034174, label %20
  ]

20:                                               ; preds = %18
  store i8 0, ptr %9, align 1, !tbaa !13
  %21 = load ptr, ptr %7, align 8, !tbaa !11
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %28

23:                                               ; preds = %20
  %24 = load ptr, ptr %7, align 8, !tbaa !11
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %23
  store i8 1, ptr %9, align 1, !tbaa !13
  br label %28

28:                                               ; preds = %27, %23, %20
  br label %29

29:                                               ; preds = %28
  %30 = load i8, ptr %9, align 1, !tbaa !13
  %31 = icmp ne i8 %30, 0
  br i1 %31, label %32, label %48

32:                                               ; preds = %29
  br label %33

33:                                               ; preds = %32
  %34 = load ptr, ptr %8, align 8, !tbaa !11
  %35 = getelementptr inbounds %struct.lwip_sock, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  %37 = getelementptr inbounds %struct.netconn, ptr %36, i32 0, i32 10
  %38 = load i8, ptr %37, align 4, !tbaa !17
  %39 = zext i8 %38 to i32
  %40 = or i32 %39, 2
  %41 = trunc i32 %40 to i8
  %42 = load ptr, ptr %8, align 8, !tbaa !11
  %43 = getelementptr inbounds %struct.lwip_sock, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !14
  %45 = getelementptr inbounds %struct.netconn, ptr %44, i32 0, i32 10
  store i8 %41, ptr %45, align 4, !tbaa !17
  br label %46

46:                                               ; preds = %33
  br label %47

47:                                               ; preds = %46
  br label %64

48:                                               ; preds = %29
  br label %49

49:                                               ; preds = %48
  %50 = load ptr, ptr %8, align 8, !tbaa !11
  %51 = getelementptr inbounds %struct.lwip_sock, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !14
  %53 = getelementptr inbounds %struct.netconn, ptr %52, i32 0, i32 10
  %54 = load i8, ptr %53, align 4, !tbaa !17
  %55 = zext i8 %54 to i32
  %56 = and i32 %55, 253
  %57 = trunc i32 %56 to i8
  %58 = load ptr, ptr %8, align 8, !tbaa !11
  %59 = getelementptr inbounds %struct.lwip_sock, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !14
  %61 = getelementptr inbounds %struct.netconn, ptr %60, i32 0, i32 10
  store i8 %57, ptr %61, align 4, !tbaa !17
  br label %62

62:                                               ; preds = %49
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63, %47
  br label %65

65:                                               ; preds = %64
  br label %66

66:                                               ; preds = %65
  br label %67

67:                                               ; preds = %66
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %68

68:                                               ; preds = %67
  br label %69

69:                                               ; preds = %68
  br label %70

70:                                               ; preds = %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %71

71:                                               ; preds = %70
  br label %72

72:                                               ; preds = %71
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %81

73:                                               ; preds = %18
  br label %74

74:                                               ; preds = %73
  br label %75

75:                                               ; preds = %74
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 38, ptr %12, align 4, !tbaa !5
  br label %76

76:                                               ; preds = %75
  store i32 38, ptr @errno, align 4, !tbaa !5
  br label %77

77:                                               ; preds = %76
  br label %78

78:                                               ; preds = %77
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  br label %79

79:                                               ; preds = %78
  br label %80

80:                                               ; preds = %79
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %81

81:                                               ; preds = %80, %72, %17
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %82 = load i32, ptr %4, align 4
  ret i32 %82
}

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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !12, i64 0}
!15 = !{!"lwip_sock", !12, i64 0, !7, i64 8, !16, i64 16, !16, i64 18, !16, i64 20, !7, i64 22}
!16 = !{!"short", !7, i64 0}
!17 = !{!18, !7, i64 60}
!18 = !{!"netconn", !6, i64 0, !6, i64 4, !7, i64 8, !7, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !6, i64 48, !6, i64 52, !6, i64 56, !7, i64 60, !12, i64 64, !12, 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

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

5:                                                ; preds = %3
  %cond = icmp eq i64 %1, 2148034174
  br i1 %cond, label %6, label %18

6:                                                ; preds = %5
  %.not13 = icmp eq ptr %2, null
  br i1 %.not13, label %.critedge, label %7

7:                                                ; preds = %6
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %.not14 = icmp eq i32 %8, 0
  br i1 %.not14, label %.critedge, label %9

9:                                                ; preds = %7
  %10 = load ptr, ptr %4, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %10, i64 60
  %12 = load i8, ptr %11, align 4, !tbaa !13
  %13 = or i8 %12, 2
  store i8 %13, ptr %11, align 4, !tbaa !13
  br label %19

.critedge:                                        ; preds = %6, %7
  %14 = load ptr, ptr %4, align 8, !tbaa !9
  %15 = getelementptr inbounds i8, ptr %14, i64 60
  %16 = load i8, ptr %15, align 4, !tbaa !13
  %17 = and i8 %16, -3
  store i8 %17, ptr %15, align 4, !tbaa !13
  br label %19

18:                                               ; preds = %5
  store i32 38, ptr @errno, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %.critedge, %9, %3, %18
  %.0 = phi i32 [ -1, %18 ], [ -1, %3 ], [ 0, %9 ], [ 0, %.critedge ]
  ret i32 %.0
}

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

!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, !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, !7, i64 60}
!14 = !{!"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}


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