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

; 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.api_msg = type { ptr, i8, %union.anon }
%union.anon = type { %struct.anon.2 }
%struct.anon.2 = type { ptr, i16, i64, i64, i64, i8, i32 }
%struct.netconn = type { i32, i32, %union.anon.5, i8, ptr, ptr, ptr, i32, i32, i32, i8, ptr, ptr }
%union.anon.5 = type { ptr }
%struct.anon.4 = type { i8, i32 }

@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [181 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [7 x i8], align 1
@lock_tcpip_core = external global ptr, align 8

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

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

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

; Function Attrs: nounwind uwtable
declare hidden void @netconn_drain(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden signext i8 @lwip_netconn_do_close_internal(ptr noundef, i8 noundef zeroext) #2

declare void @sys_mutex_unlock(ptr noundef) #0

declare i32 @sys_arch_sem_wait(ptr noundef, i32 noundef) #0

declare void @sys_mutex_lock(ptr noundef) #0

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

18:                                               ; preds = %1
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.api_msg, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.netconn, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !16
  %24 = and i32 %23, 240
  %25 = icmp eq i32 %24, 16
  br i1 %25, label %26, label %130

26:                                               ; preds = %18
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.api_msg, ptr %27, i32 0, i32 2
  %29 = getelementptr inbounds %struct.anon.4, ptr %28, i32 0, i32 0
  %30 = load i8, ptr %29, align 8, !tbaa !15
  %31 = zext i8 %30 to i32
  %32 = icmp eq i32 %31, 3
  br i1 %32, label %36, label %33

33:                                               ; preds = %26
  %34 = load i32, ptr %4, align 4, !tbaa !14
  %35 = icmp ne i32 %34, 2
  br i1 %35, label %36, label %130

36:                                               ; preds = %33, %26
  %37 = load i32, ptr %4, align 4, !tbaa !14
  %38 = icmp eq i32 %37, 3
  br i1 %38, label %39, label %42

39:                                               ; preds = %36
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.api_msg, ptr %40, i32 0, i32 1
  store i8 -11, ptr %41, align 8, !tbaa !17
  br label %129

42:                                               ; preds = %36
  %43 = load i32, ptr %4, align 4, !tbaa !14
  %44 = icmp eq i32 %43, 1
  br i1 %44, label %45, label %48

45:                                               ; preds = %42
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.api_msg, ptr %46, i32 0, i32 1
  store i8 -5, ptr %47, align 8, !tbaa !17
  br label %128

48:                                               ; preds = %42
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.api_msg, ptr %49, i32 0, i32 2
  %51 = getelementptr inbounds %struct.anon.4, ptr %50, i32 0, i32 0
  %52 = load i8, ptr %51, align 8, !tbaa !15
  %53 = zext i8 %52 to i32
  %54 = and i32 %53, 1
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %60

56:                                               ; preds = %48
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.api_msg, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !9
  call void @netconn_drain(ptr noundef %59)
  br label %60

60:                                               ; preds = %56, %48
  br label %61

61:                                               ; preds = %60
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.api_msg, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.netconn, ptr %64, i32 0, i32 11
  %66 = load ptr, ptr %65, align 8, !tbaa !18
  %67 = icmp eq ptr %66, null
  br i1 %67, label %73, label %68

68:                                               ; preds = %61
  br label %69

69:                                               ; preds = %68
  %70 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.9, i32 noundef 1981, ptr noundef @.str.2)
  br label %71

71:                                               ; preds = %69
  br label %72

72:                                               ; preds = %71
  br label %73

73:                                               ; preds = %72, %61
  br label %74

74:                                               ; preds = %73
  br label %75

75:                                               ; preds = %74
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.api_msg, ptr %76, i32 0, i32 0
  %78 = load ptr, ptr %77, align 8, !tbaa !9
  %79 = getelementptr inbounds %struct.netconn, ptr %78, i32 0, i32 1
  store i32 4, ptr %79, align 4, !tbaa !11
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.api_msg, ptr %81, i32 0, i32 0
  %83 = load ptr, ptr %82, align 8, !tbaa !9
  %84 = getelementptr inbounds %struct.netconn, ptr %83, i32 0, i32 11
  store ptr %80, ptr %84, align 8, !tbaa !18
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.api_msg, ptr %85, i32 0, i32 0
  %87 = load ptr, ptr %86, align 8, !tbaa !9
  %88 = call signext i8 @lwip_netconn_do_close_internal(ptr noundef %87, i8 noundef zeroext 0)
  %89 = sext i8 %88 to i32
  %90 = icmp ne i32 %89, 0
  br i1 %90, label %91, label %127

91:                                               ; preds = %75
  br label %92

92:                                               ; preds = %91
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.api_msg, ptr %93, i32 0, i32 0
  %95 = load ptr, ptr %94, align 8, !tbaa !9
  %96 = getelementptr inbounds %struct.netconn, ptr %95, i32 0, i32 1
  %97 = load i32, ptr %96, align 4, !tbaa !11
  %98 = icmp eq i32 %97, 4
  br i1 %98, label %104, label %99

99:                                               ; preds = %92
  br label %100

100:                                              ; preds = %99
  %101 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.10, i32 noundef 1986, ptr noundef @.str.2)
  br label %102

102:                                              ; preds = %100
  br label %103

103:                                              ; preds = %102
  br label %104

104:                                              ; preds = %103, %92
  br label %105

105:                                              ; preds = %104
  br label %106

106:                                              ; preds = %105
  call void @sys_mutex_unlock(ptr noundef @lock_tcpip_core)
  %107 = load ptr, ptr %3, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.api_msg, ptr %107, i32 0, i32 0
  %109 = load ptr, ptr %108, align 8, !tbaa !9
  %110 = getelementptr inbounds %struct.netconn, ptr %109, i32 0, i32 4
  %111 = call i32 @sys_arch_sem_wait(ptr noundef %110, i32 noundef 0)
  call void @sys_mutex_lock(ptr noundef @lock_tcpip_core)
  br label %112

112:                                              ; preds = %106
  %113 = load ptr, ptr %3, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.api_msg, ptr %113, i32 0, i32 0
  %115 = load ptr, ptr %114, align 8, !tbaa !9
  %116 = getelementptr inbounds %struct.netconn, ptr %115, i32 0, i32 1
  %117 = load i32, ptr %116, align 4, !tbaa !11
  %118 = icmp eq i32 %117, 0
  br i1 %118, label %124, label %119

119:                                              ; preds = %112
  br label %120

120:                                              ; preds = %119
  %121 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.10, i32 noundef 1990, ptr noundef @.str.2)
  br label %122

122:                                              ; preds = %120
  br label %123

123:                                              ; preds = %122
  br label %124

124:                                              ; preds = %123, %112
  br label %125

125:                                              ; preds = %124
  br label %126

126:                                              ; preds = %125
  br label %127

127:                                              ; preds = %126, %75
  store i32 1, ptr %5, align 4
  br label %134

128:                                              ; preds = %45
  br label %129

129:                                              ; preds = %128, %39
  br label %133

130:                                              ; preds = %33, %18, %1
  %131 = load ptr, ptr %3, align 8, !tbaa !5
  %132 = getelementptr inbounds %struct.api_msg, ptr %131, i32 0, i32 1
  store i8 -11, ptr %132, align 8, !tbaa !17
  br label %133

133:                                              ; preds = %130, %129
  store i32 0, ptr %5, align 4
  br label %134

134:                                              ; preds = %133, %127
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %135 = load i32, ptr %5, align 4
  switch i32 %135, label %137 [
    i32 0, label %136
    i32 1, label %136
  ]

136:                                              ; preds = %134, %134
  ret void

137:                                              ; preds = %134
  unreachable
}

attributes #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"api_msg", !6, i64 0, !7, i64 8, !7, i64 16}
!11 = !{!12, !13, i64 4}
!12 = !{!"netconn", !13, i64 0, !13, i64 4, !7, i64 8, !7, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !13, i64 48, !13, i64 52, !13, i64 56, !7, i64 60, !6, i64 64, !6, i64 72}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!12, !13, i64 0}
!17 = !{!10, !7, i64 8}
!18 = !{!12, !6, i64 64}


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

@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [181 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [7 x i8], align 1
@lock_tcpip_core = external global ptr, align 8

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

; Function Attrs: nounwind uwtable
declare hidden void @netconn_drain(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden signext i8 @lwip_netconn_do_close_internal(ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

declare void @sys_mutex_unlock(ptr noundef) local_unnamed_addr #2

declare i32 @sys_arch_sem_wait(ptr noundef, i32 noundef) local_unnamed_addr #2

declare void @sys_mutex_lock(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @lwip_netconn_do_close(ptr noundef %0) local_unnamed_addr #1 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !10
  %5 = getelementptr inbounds i8, ptr %2, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !13
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %53, label %7

7:                                                ; preds = %1
  %8 = load i32, ptr %2, align 8, !tbaa !14
  %9 = and i32 %8, 240
  %10 = icmp eq i32 %9, 16
  br i1 %10, label %11, label %53

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = load i8, ptr %12, align 8, !tbaa !13
  %14 = icmp eq i8 %13, 3
  %15 = icmp ne i32 %4, 2
  %or.cond = select i1 %14, i1 true, i1 %15
  br i1 %or.cond, label %16, label %53

16:                                               ; preds = %11
  switch i32 %4, label %21 [
    i32 3, label %17
    i32 1, label %19
  ]

17:                                               ; preds = %16
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  store i8 -11, ptr %18, align 8, !tbaa !15
  br label %55

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  store i8 -5, ptr %20, align 8, !tbaa !15
  br label %55

21:                                               ; preds = %16
  %22 = and i8 %13, 1
  %.not21 = icmp eq i8 %22, 0
  br i1 %.not21, label %24, label %23

23:                                               ; preds = %21
  tail call void @netconn_drain(ptr noundef nonnull %2)
  %.pre = load ptr, ptr %0, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %21, %23
  %25 = phi ptr [ %2, %21 ], [ %.pre, %23 ]
  %26 = getelementptr inbounds i8, ptr %25, i64 64
  %27 = load ptr, ptr %26, align 8, !tbaa !16
  %28 = icmp eq ptr %27, null
  br i1 %28, label %31, label %29

29:                                               ; preds = %24
  %30 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.9, i32 noundef 1981, ptr noundef nonnull @.str.2)
  %.pre23 = load ptr, ptr %0, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %29, %24
  %32 = phi ptr [ %.pre23, %29 ], [ %25, %24 ]
  %33 = getelementptr inbounds i8, ptr %32, i64 4
  store i32 4, ptr %33, align 4, !tbaa !10
  %34 = getelementptr inbounds i8, ptr %32, i64 64
  store ptr %0, ptr %34, align 8, !tbaa !16
  %35 = tail call signext i8 @lwip_netconn_do_close_internal(ptr noundef %32, i8 noundef zeroext 0)
  %.not22 = icmp eq i8 %35, 0
  br i1 %.not22, label %55, label %36

36:                                               ; preds = %31
  %37 = load ptr, ptr %0, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 4
  %39 = load i32, ptr %38, align 4, !tbaa !10
  %40 = icmp eq i32 %39, 4
  br i1 %40, label %43, label %41

41:                                               ; preds = %36
  %42 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.10, i32 noundef 1986, ptr noundef nonnull @.str.2)
  br label %43

43:                                               ; preds = %41, %36
  tail call void @sys_mutex_unlock(ptr noundef nonnull @lock_tcpip_core) #3
  %44 = load ptr, ptr %0, align 8, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %44, i64 24
  %46 = tail call i32 @sys_arch_sem_wait(ptr noundef nonnull %45, i32 noundef 0) #3
  tail call void @sys_mutex_lock(ptr noundef nonnull @lock_tcpip_core) #3
  %47 = load ptr, ptr %0, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %47, i64 4
  %49 = load i32, ptr %48, align 4, !tbaa !10
  %50 = icmp eq i32 %49, 0
  br i1 %50, label %55, label %51

51:                                               ; preds = %43
  %52 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.10, i32 noundef 1990, ptr noundef nonnull @.str.2)
  br label %55

53:                                               ; preds = %11, %7, %1
  %54 = getelementptr inbounds i8, ptr %0, i64 8
  store i8 -11, ptr %54, align 8, !tbaa !15
  br label %55

55:                                               ; preds = %53, %19, %17, %31, %51, %43
  ret void
}

attributes #0 = { 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 #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 = !{!"api_msg", !7, i64 0, !8, i64 8, !8, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 4}
!11 = !{!"netconn", !12, i64 0, !12, i64 4, !8, i64 8, !8, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !12, i64 48, !12, i64 52, !12, i64 56, !8, i64 60, !7, i64 64, !7, i64 72}
!12 = !{!"int", !8, i64 0}
!13 = !{!8, !8, i64 0}
!14 = !{!11, !12, i64 0}
!15 = !{!6, !8, i64 8}
!16 = !{!11, !7, i64 64}


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