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

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

@next_timeout = external hidden global ptr, align 8
@current_timeout_due_time = external hidden 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare i32 @sys_now() #1

declare void @memp_free(i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @sys_check_timeouts() #2 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  %6 = call i32 @sys_now()
  store i32 %6, ptr %1, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %45, %0
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %8 = load ptr, ptr @next_timeout, align 8, !tbaa !9
  store ptr %8, ptr %2, align 8, !tbaa !9
  %9 = load ptr, ptr %2, align 8, !tbaa !9
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %7
  store i32 1, ptr %5, align 4
  br label %42

12:                                               ; preds = %7
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = load ptr, ptr %2, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.sys_timeo, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = sub i32 %13, %16
  %18 = icmp ugt i32 %17, 2147483647
  br i1 %18, label %19, label %20

19:                                               ; preds = %12
  br i1 true, label %21, label %22

20:                                               ; preds = %12
  br i1 false, label %21, label %22

21:                                               ; preds = %20, %19
  store i32 1, ptr %5, align 4
  br label %42

22:                                               ; preds = %20, %19
  %23 = load ptr, ptr %2, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.sys_timeo, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  store ptr %25, ptr @next_timeout, align 8, !tbaa !9
  %26 = load ptr, ptr %2, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.sys_timeo, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  store ptr %28, ptr %3, align 8, !tbaa !9
  %29 = load ptr, ptr %2, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.sys_timeo, ptr %29, i32 0, i32 3
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  store ptr %31, ptr %4, align 8, !tbaa !9
  %32 = load ptr, ptr %2, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.sys_timeo, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 8, !tbaa !11
  store i32 %34, ptr @current_timeout_due_time, align 4, !tbaa !5
  %35 = load ptr, ptr %2, align 8, !tbaa !9
  call void @memp_free(i32 noundef 10, ptr noundef %35)
  %36 = load ptr, ptr %3, align 8, !tbaa !9
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %41

38:                                               ; preds = %22
  %39 = load ptr, ptr %3, align 8, !tbaa !9
  %40 = load ptr, ptr %4, align 8, !tbaa !9
  call void %39(ptr noundef %40)
  br label %41

41:                                               ; preds = %38, %22
  store i32 0, ptr %5, align 4
  br label %42

42:                                               ; preds = %41, %21, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %43 = load i32, ptr %5, align 4
  switch i32 %43, label %47 [
    i32 0, label %44
  ]

44:                                               ; preds = %42
  br label %45

45:                                               ; preds = %44
  br i1 true, label %7, label %46

46:                                               ; preds = %45
  store i32 0, ptr %5, align 4
  br label %47

47:                                               ; preds = %46, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  %48 = load i32, ptr %5, align 4
  switch i32 %48, label %50 [
    i32 0, label %49
    i32 1, label %49
  ]

49:                                               ; preds = %47, %47
  ret void

50:                                               ; preds = %47
  unreachable
}

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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"sys_timeo", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 24}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !10, i64 16}
!15 = !{!12, !10, i64 24}


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

@next_timeout = external hidden local_unnamed_addr global ptr, align 8
@current_timeout_due_time = external hidden local_unnamed_addr global i32, align 4

declare i32 @sys_now() local_unnamed_addr #0

declare void @memp_free(i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @sys_check_timeouts() local_unnamed_addr #1 {
  %1 = tail call i32 @sys_now() #2
  %2 = load ptr, ptr @next_timeout, align 8, !tbaa !5
  %3 = icmp eq ptr %2, null
  br i1 %3, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %16
  %4 = phi ptr [ %17, %16 ], [ %2, %0 ]
  %5 = getelementptr inbounds i8, ptr %4, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = sub i32 %1, %6
  %8 = icmp slt i32 %7, 0
  br i1 %8, label %.critedge, label %9

9:                                                ; preds = %.lr.ph
  %10 = load ptr, ptr %4, align 8, !tbaa !12
  store ptr %10, ptr @next_timeout, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %4, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %4, i64 24
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  store i32 %6, ptr @current_timeout_due_time, align 4, !tbaa !15
  tail call void @memp_free(i32 noundef 10, ptr noundef nonnull %4) #2
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %16, label %15

15:                                               ; preds = %9
  tail call void %12(ptr noundef %14) #2
  br label %16

16:                                               ; preds = %9, %15
  %17 = load ptr, ptr @next_timeout, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %.critedge, label %.lr.ph

.critedge:                                        ; preds = %16, %.lr.ph, %0
  ret void
}

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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"sys_timeo", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = !{!10, !6, i64 16}
!14 = !{!10, !6, i64 24}
!15 = !{!11, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass