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

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

@.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
@.str.12 = external hidden unnamed_addr constant [20 x i8], align 1

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

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

declare signext i8 @netconn_err(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @lwip_netconn_do_write(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %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 1, 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 = call signext i8 @netconn_err(ptr noundef %9)
  store i8 %10, ptr %4, align 1, !tbaa !11
  %11 = load i8, ptr %4, align 1, !tbaa !11
  %12 = sext i8 %11 to i32
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %124

14:                                               ; preds = %1
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.api_msg, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.netconn, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !12
  %20 = and i32 %19, 240
  %21 = icmp eq i32 %20, 16
  br i1 %21, label %22, label %122

22:                                               ; preds = %14
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.api_msg, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.netconn, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %26, align 4, !tbaa !15
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %22
  store i8 -5, ptr %4, align 1, !tbaa !11
  br label %121

30:                                               ; preds = %22
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.api_msg, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.netconn, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %119

37:                                               ; preds = %30
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.api_msg, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.netconn, ptr %40, i32 0, i32 1
  store i32 1, ptr %41, align 4, !tbaa !15
  br label %42

42:                                               ; preds = %37
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.api_msg, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct.netconn, ptr %45, i32 0, i32 11
  %47 = load ptr, ptr %46, align 8, !tbaa !16
  %48 = icmp eq ptr %47, null
  br i1 %48, label %54, label %49

49:                                               ; preds = %42
  br label %50

50:                                               ; preds = %49
  %51 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.9, i32 noundef 1827, ptr noundef @.str.2)
  br label %52

52:                                               ; preds = %50
  br label %53

53:                                               ; preds = %52
  br label %54

54:                                               ; preds = %53, %42
  br label %55

55:                                               ; preds = %54
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.api_msg, ptr %58, i32 0, i32 2
  %60 = getelementptr inbounds %struct.anon.2, ptr %59, i32 0, i32 3
  %61 = load i64, ptr %60, align 8, !tbaa !11
  %62 = icmp ne i64 %61, 0
  br i1 %62, label %68, label %63

63:                                               ; preds = %57
  br label %64

64:                                               ; preds = %63
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.12, i32 noundef 1828, ptr noundef @.str.2)
  br label %66

66:                                               ; preds = %64
  br label %67

67:                                               ; preds = %66
  br label %68

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

69:                                               ; preds = %68
  br label %70

70:                                               ; preds = %69
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.api_msg, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !9
  %75 = getelementptr inbounds %struct.netconn, ptr %74, i32 0, i32 11
  store ptr %71, ptr %75, align 8, !tbaa !16
  %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 = call signext i8 @lwip_netconn_do_writemore(ptr noundef %78, i8 noundef zeroext 0)
  %80 = sext i8 %79 to i32
  %81 = icmp ne i32 %80, 0
  br i1 %81, label %82, label %118

82:                                               ; preds = %70
  br label %83

83:                                               ; preds = %82
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.api_msg, ptr %84, i32 0, i32 0
  %86 = load ptr, ptr %85, align 8, !tbaa !9
  %87 = getelementptr inbounds %struct.netconn, ptr %86, i32 0, i32 1
  %88 = load i32, ptr %87, align 4, !tbaa !15
  %89 = icmp eq i32 %88, 1
  br i1 %89, label %95, label %90

90:                                               ; preds = %83
  br label %91

91:                                               ; preds = %90
  %92 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.10, i32 noundef 1832, ptr noundef @.str.2)
  br label %93

93:                                               ; preds = %91
  br label %94

94:                                               ; preds = %93
  br label %95

95:                                               ; preds = %94, %83
  br label %96

96:                                               ; preds = %95
  br label %97

97:                                               ; preds = %96
  call void @sys_mutex_unlock(ptr noundef @lock_tcpip_core)
  %98 = load ptr, ptr %3, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.api_msg, ptr %98, i32 0, i32 0
  %100 = load ptr, ptr %99, align 8, !tbaa !9
  %101 = getelementptr inbounds %struct.netconn, ptr %100, i32 0, i32 4
  %102 = call i32 @sys_arch_sem_wait(ptr noundef %101, i32 noundef 0)
  call void @sys_mutex_lock(ptr noundef @lock_tcpip_core)
  br label %103

103:                                              ; preds = %97
  %104 = load ptr, ptr %3, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.api_msg, ptr %104, i32 0, i32 0
  %106 = load ptr, ptr %105, align 8, !tbaa !9
  %107 = getelementptr inbounds %struct.netconn, ptr %106, i32 0, i32 1
  %108 = load i32, ptr %107, align 4, !tbaa !15
  %109 = icmp ne i32 %108, 1
  br i1 %109, label %115, label %110

110:                                              ; preds = %103
  br label %111

111:                                              ; preds = %110
  %112 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.10, i32 noundef 1836, ptr noundef @.str.2)
  br label %113

113:                                              ; preds = %111
  br label %114

114:                                              ; preds = %113
  br label %115

115:                                              ; preds = %114, %103
  br label %116

116:                                              ; preds = %115
  br label %117

117:                                              ; preds = %116
  br label %118

118:                                              ; preds = %117, %70
  store i32 1, ptr %5, align 4
  br label %128

119:                                              ; preds = %30
  store i8 -11, ptr %4, align 1, !tbaa !11
  br label %120

120:                                              ; preds = %119
  br label %121

121:                                              ; preds = %120, %29
  br label %123

122:                                              ; preds = %14
  store i8 -6, ptr %4, align 1, !tbaa !11
  br label %123

123:                                              ; preds = %122, %121
  br label %124

124:                                              ; preds = %123, %1
  %125 = load i8, ptr %4, align 1, !tbaa !11
  %126 = load ptr, ptr %3, align 8, !tbaa !5
  %127 = getelementptr inbounds %struct.api_msg, ptr %126, i32 0, i32 1
  store i8 %125, ptr %127, align 8, !tbaa !17
  store i32 0, ptr %5, align 4
  br label %128

128:                                              ; preds = %124, %118
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %129 = load i32, ptr %5, align 4
  switch i32 %129, label %131 [
    i32 0, label %130
    i32 1, label %130
  ]

130:                                              ; preds = %128, %128
  ret void

131:                                              ; preds = %128
  unreachable
}

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

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 = !{!7, !7, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"netconn", !14, i64 0, !14, i64 4, !7, i64 8, !7, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !14, i64 48, !14, i64 52, !14, i64 56, !7, i64 60, !6, i64 64, !6, i64 72}
!14 = !{!"int", !7, i64 0}
!15 = !{!13, !14, i64 4}
!16 = !{!13, !6, i64 64}
!17 = !{!10, !7, i64 8}


; 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
@.str.12 = external hidden unnamed_addr constant [20 x i8], align 1

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

declare void @sys_mutex_unlock(ptr noundef) local_unnamed_addr #1

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

declare void @sys_mutex_lock(ptr noundef) local_unnamed_addr #1

declare signext i8 @netconn_err(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @lwip_netconn_do_write(ptr noundef %0) local_unnamed_addr #2 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = tail call signext i8 @netconn_err(ptr noundef %2) #3
  %4 = icmp eq i8 %3, 0
  br i1 %4, label %5, label %47

5:                                                ; preds = %1
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  %7 = load i32, ptr %6, align 8, !tbaa !10
  %8 = and i32 %7, 240
  %9 = icmp eq i32 %8, 16
  br i1 %9, label %10, label %47

10:                                               ; preds = %5
  %11 = getelementptr inbounds i8, ptr %6, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !13
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %13, label %47

13:                                               ; preds = %10
  %14 = getelementptr inbounds i8, ptr %6, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  %.not16 = icmp eq ptr %15, null
  br i1 %.not16, label %47, label %16

16:                                               ; preds = %13
  store i32 1, ptr %11, align 4, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %6, i64 64
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %19 = icmp eq ptr %18, null
  br i1 %19, label %22, label %20

20:                                               ; preds = %16
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.9, i32 noundef 1827, ptr noundef nonnull @.str.2)
  br label %22

22:                                               ; preds = %16, %20
  %23 = getelementptr inbounds i8, ptr %0, i64 40
  %24 = load i64, ptr %23, align 8, !tbaa !14
  %.not17 = icmp eq i64 %24, 0
  br i1 %.not17, label %25, label %27

25:                                               ; preds = %22
  %26 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.12, i32 noundef 1828, ptr noundef nonnull @.str.2)
  br label %27

27:                                               ; preds = %25, %22
  %28 = load ptr, ptr %0, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 64
  store ptr %0, ptr %29, align 8, !tbaa !15
  %30 = tail call signext i8 @lwip_netconn_do_writemore(ptr noundef %28, i8 noundef zeroext 0)
  %.not18 = icmp eq i8 %30, 0
  br i1 %.not18, label %49, label %31

31:                                               ; preds = %27
  %32 = load ptr, ptr %0, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 4
  %34 = load i32, ptr %33, align 4, !tbaa !13
  %35 = icmp eq i32 %34, 1
  br i1 %35, label %38, label %36

36:                                               ; preds = %31
  %37 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.10, i32 noundef 1832, ptr noundef nonnull @.str.2)
  br label %38

38:                                               ; preds = %36, %31
  tail call void @sys_mutex_unlock(ptr noundef nonnull @lock_tcpip_core) #3
  %39 = load ptr, ptr %0, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i64 24
  %41 = tail call i32 @sys_arch_sem_wait(ptr noundef nonnull %40, i32 noundef 0) #3
  tail call void @sys_mutex_lock(ptr noundef nonnull @lock_tcpip_core) #3
  %42 = load ptr, ptr %0, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i64 4
  %44 = load i32, ptr %43, align 4, !tbaa !13
  %.not19 = icmp eq i32 %44, 1
  br i1 %.not19, label %45, label %49

45:                                               ; preds = %38
  %46 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.10, i32 noundef 1836, ptr noundef nonnull @.str.2)
  br label %49

47:                                               ; preds = %5, %13, %10, %1
  %.0 = phi i8 [ %3, %1 ], [ -5, %10 ], [ -11, %13 ], [ -6, %5 ]
  %48 = getelementptr inbounds i8, ptr %0, i64 8
  store i8 %.0, ptr %48, align 8, !tbaa !16
  br label %49

49:                                               ; preds = %27, %45, %38, %47
  ret void
}

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

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 = { "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 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, !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 0}
!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 = !{!11, !12, i64 4}
!14 = !{!8, !8, i64 0}
!15 = !{!11, !7, i64 64}
!16 = !{!6, !8, i64 8}


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