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

; 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_select_cb = type { ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, ptr }

@errno = external global i32, align 4
@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [181 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [12 x i8], align 1

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

; Function Attrs: nounwind uwtable
declare hidden void @lwip_link_select_cb(ptr noundef) #3

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

; Function Attrs: nounwind uwtable
declare hidden void @lwip_unlink_select_cb(ptr noundef) #3

declare void @sys_sem_free(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @lwip_poll(ptr noundef %0, i32 noundef %1, i32 noundef %2) #3 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca %struct.lwip_select_cb, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  br label %13

13:                                               ; preds = %3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %19

16:                                               ; preds = %13
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = icmp ugt i32 %17, 0
  br i1 %18, label %33, label %19

19:                                               ; preds = %16, %13
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %25

22:                                               ; preds = %19
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %33, label %25

25:                                               ; preds = %22, %19
  br label %26

26:                                               ; preds = %25
  %27 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.17, i32 noundef 2331, ptr noundef @.str.2)
  br label %28

28:                                               ; preds = %26
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  store i32 22, ptr @errno, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %112

33:                                               ; preds = %22, %16
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = call i32 @lwip_pollscan(ptr noundef %36, i32 noundef %37, i32 noundef 1)
  store i32 %38, ptr %9, align 4, !tbaa !9
  %39 = load i32, ptr %9, align 4, !tbaa !9
  %40 = icmp slt i32 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %35
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %112

42:                                               ; preds = %35
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %106, label %45

45:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 64, ptr %12) #4
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %49

48:                                               ; preds = %45
  store i32 8, ptr %11, align 4
  br label %103

49:                                               ; preds = %45
  call void @llvm.memset.p0.i64(ptr align 8 %12, i8 0, i64 64, i1 false)
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.lwip_select_cb, ptr %12, i32 0, i32 5
  store ptr %50, ptr %51, align 8, !tbaa !11
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = getelementptr inbounds %struct.lwip_select_cb, ptr %12, i32 0, i32 6
  store i32 %52, ptr %53, align 8, !tbaa !13
  %54 = getelementptr inbounds %struct.lwip_select_cb, ptr %12, i32 0, i32 8
  %55 = call signext i8 @sys_sem_new(ptr noundef %54, i8 noundef zeroext 0)
  %56 = sext i8 %55 to i32
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %62

58:                                               ; preds = %49
  br label %59

59:                                               ; preds = %58
  store i32 11, ptr @errno, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %59
  br label %61

61:                                               ; preds = %60
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %103

62:                                               ; preds = %49
  call void @lwip_link_select_cb(ptr noundef %12)
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = load i32, ptr %6, align 4, !tbaa !9
  %65 = call i32 @lwip_pollscan(ptr noundef %63, i32 noundef %64, i32 noundef 2)
  store i32 %65, ptr %9, align 4, !tbaa !9
  %66 = load i32, ptr %9, align 4, !tbaa !9
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %89, label %68

68:                                               ; preds = %62
  %69 = load i32, ptr %7, align 4, !tbaa !9
  %70 = icmp slt i32 %69, 0
  br i1 %70, label %71, label %72

71:                                               ; preds = %68
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %85

72:                                               ; preds = %68
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %7, align 4, !tbaa !9
  %75 = icmp sgt i32 %74, 0
  br i1 %75, label %81, label %76

76:                                               ; preds = %73
  br label %77

77:                                               ; preds = %76
  %78 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.18, i32 noundef 2388, ptr noundef @.str.2)
  br label %79

79:                                               ; preds = %77
  br label %80

80:                                               ; preds = %79
  br label %81

81:                                               ; preds = %80, %73
  br label %82

82:                                               ; preds = %81
  br label %83

83:                                               ; preds = %82
  %84 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %84, ptr %10, align 4, !tbaa !9
  br label %85

85:                                               ; preds = %83, %71
  %86 = getelementptr inbounds %struct.lwip_select_cb, ptr %12, i32 0, i32 8
  %87 = load i32, ptr %10, align 4, !tbaa !9
  %88 = call i32 @sys_arch_sem_wait(ptr noundef %86, i32 noundef %87)
  store i32 %88, ptr %8, align 4, !tbaa !9
  br label %89

89:                                               ; preds = %85, %62
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = load i32, ptr %6, align 4, !tbaa !9
  %92 = call i32 @lwip_pollscan(ptr noundef %90, i32 noundef %91, i32 noundef 4)
  store i32 %92, ptr %9, align 4, !tbaa !9
  call void @lwip_unlink_select_cb(ptr noundef %12)
  %93 = getelementptr inbounds %struct.lwip_select_cb, ptr %12, i32 0, i32 8
  call void @sys_sem_free(ptr noundef %93)
  %94 = load i32, ptr %9, align 4, !tbaa !9
  %95 = icmp slt i32 %94, 0
  br i1 %95, label %96, label %97

96:                                               ; preds = %89
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %103

97:                                               ; preds = %89
  %98 = load i32, ptr %8, align 4, !tbaa !9
  %99 = zext i32 %98 to i64
  %100 = icmp eq i64 %99, 4294967295
  br i1 %100, label %101, label %102

101:                                              ; preds = %97
  store i32 8, ptr %11, align 4
  br label %103

102:                                              ; preds = %97
  store i32 0, ptr %11, align 4
  br label %103

103:                                              ; preds = %102, %101, %96, %61, %48
  call void @llvm.lifetime.end.p0(i64 64, ptr %12) #4
  %104 = load i32, ptr %11, align 4
  switch i32 %104, label %112 [
    i32 0, label %105
    i32 8, label %107
  ]

105:                                              ; preds = %103
  br label %106

106:                                              ; preds = %105, %42
  br label %107

107:                                              ; preds = %106, %103
  br label %108

108:                                              ; preds = %107
  br label %109

109:                                              ; preds = %108
  br label %110

110:                                              ; preds = %109
  %111 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %111, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %112

112:                                              ; preds = %110, %103, %41, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %113 = load i32, ptr %4, align 4
  ret i32 %113
}

; Function Attrs: nounwind uwtable
declare hidden i32 @lwip_pollscan(ptr noundef, i32 noundef, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 40}
!12 = !{!"lwip_select_cb", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !10, i64 48, !10, i64 52, !6, i64 56}
!13 = !{!12, !10, i64 48}


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

%struct.lwip_select_cb = type { ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, ptr }

@errno = external local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [181 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [23 x i8], align 1

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

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare signext i8 @sys_sem_new(ptr noundef, i8 noundef zeroext) local_unnamed_addr #3

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

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

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

declare void @sys_sem_free(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local i32 @lwip_poll(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #4 {
  %4 = alloca %struct.lwip_select_cb, align 8
  %5 = icmp ne ptr %0, null
  %6 = icmp ne i32 %1, 0
  %or.cond = and i1 %5, %6
  br i1 %or.cond, label %12, label %7

7:                                                ; preds = %3
  %8 = icmp eq ptr %0, null
  %9 = icmp eq i32 %1, 0
  %or.cond3 = and i1 %8, %9
  br i1 %or.cond3, label %12, label %10

10:                                               ; preds = %7
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.17, i32 noundef 2331, ptr noundef nonnull @.str.2)
  store i32 22, ptr @errno, align 4, !tbaa !5
  br label %32

12:                                               ; preds = %7, %3
  %13 = tail call i32 @lwip_pollscan(ptr noundef %0, i32 noundef %1, i32 noundef 1)
  %14 = icmp slt i32 %13, 0
  br i1 %14, label %32, label %15

15:                                               ; preds = %12
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %16, label %32

16:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %4) #6
  %17 = icmp eq i32 %2, 0
  br i1 %17, label %select.unfold, label %18

18:                                               ; preds = %16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(64) %4, i8 0, i64 64, i1 false)
  %19 = getelementptr inbounds i8, ptr %4, i64 40
  store ptr %0, ptr %19, align 8, !tbaa !9
  %20 = getelementptr inbounds i8, ptr %4, i64 48
  store i32 %1, ptr %20, align 8, !tbaa !12
  %21 = getelementptr inbounds i8, ptr %4, i64 56
  %22 = call signext i8 @sys_sem_new(ptr noundef nonnull %21, i8 noundef zeroext 0) #6
  %.not36 = icmp eq i8 %22, 0
  br i1 %.not36, label %24, label %23

23:                                               ; preds = %18
  store i32 11, ptr @errno, align 4, !tbaa !5
  br label %31

24:                                               ; preds = %18
  call void @lwip_link_select_cb(ptr noundef nonnull %4)
  %25 = call i32 @lwip_pollscan(ptr noundef %0, i32 noundef %1, i32 noundef 2)
  %.not37 = icmp eq i32 %25, 0
  br i1 %.not37, label %26, label %28

26:                                               ; preds = %24
  %.027 = call i32 @llvm.smax.i32(i32 %2, i32 0)
  %27 = call i32 @sys_arch_sem_wait(ptr noundef nonnull %21, i32 noundef %.027) #6
  br label %28

28:                                               ; preds = %26, %24
  %29 = call i32 @lwip_pollscan(ptr noundef %0, i32 noundef %1, i32 noundef 4)
  call void @lwip_unlink_select_cb(ptr noundef nonnull %4)
  call void @sys_sem_free(ptr noundef nonnull %21) #6
  %30 = icmp slt i32 %29, 0
  br i1 %30, label %31, label %select.unfold

31:                                               ; preds = %28, %23
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %4) #6
  br label %32

select.unfold:                                    ; preds = %28, %16
  %.028.ph = phi i32 [ 0, %16 ], [ %29, %28 ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %4) #6
  br label %32

32:                                               ; preds = %31, %15, %12, %select.unfold, %10
  %.131 = phi i32 [ -1, %31 ], [ -1, %10 ], [ -1, %12 ], [ %13, %15 ], [ %.028.ph, %select.unfold ]
  ret i32 %.131
}

; Function Attrs: nounwind uwtable
declare hidden i32 @lwip_pollscan(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #5

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 #4 = { 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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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, !11, i64 40}
!10 = !{!"lwip_select_cb", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !6, i64 48, !6, i64 52, !11, i64 56}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !6, i64 48}


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