; LLVM IR from uNetworking/uSockets :: src (socket)

; 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.us_socket_t = type { %struct.us_poll_t, i8, i8, i16, ptr, ptr, ptr }
%struct.us_poll_t = type { %struct.anon, [12 x i8] }
%struct.anon = type { i32 }
%struct.us_socket_context_t = type { ptr, i32, i8, i8, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, [8 x i8] }

; Function Attrs: nounwind uwtable
define dso_local void @us_socket_timeout(i32 noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !5
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %9, label %24

9:                                                ; preds = %3
  %10 = load ptr, ptr %5, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.us_socket_t, ptr %10, i32 0, i32 4
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = getelementptr inbounds %struct.us_socket_context_t, ptr %12, i32 0, i32 2
  %14 = load i8, ptr %13, align 4, !tbaa !16
  %15 = zext i8 %14 to i32
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = add i32 %16, 3
  %18 = lshr i32 %17, 2
  %19 = add i32 %15, %18
  %20 = urem i32 %19, 240
  %21 = trunc i32 %20 to i8
  %22 = load ptr, ptr %5, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.us_socket_t, ptr %22, i32 0, i32 1
  store i8 %21, ptr %23, align 16, !tbaa !18
  br label %27

24:                                               ; preds = %3
  %25 = load ptr, ptr %5, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.us_socket_t, ptr %25, i32 0, i32 1
  store i8 -1, ptr %26, align 16, !tbaa !18
  br label %27

27:                                               ; preds = %24, %9
  ret void
}

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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"us_socket_t", !13, i64 0, !7, i64 16, !7, i64 17, !15, i64 18, !10, i64 24, !10, i64 32, !10, i64 40}
!13 = !{!"us_poll_t", !14, i64 0}
!14 = !{!"", !6, i64 0, !6, i64 3}
!15 = !{!"short", !7, i64 0}
!16 = !{!17, !7, i64 12}
!17 = !{!"us_socket_context_t", !10, i64 0, !6, i64 8, !7, i64 12, !7, i64 13, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128}
!18 = !{!12, !7, i64 16}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @us_socket_timeout(i32 noundef %0, ptr nocapture noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %15, label %4

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %1, i64 24
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 12
  %8 = load i8, ptr %7, align 4, !tbaa !14
  %9 = zext i8 %8 to i32
  %10 = add i32 %2, 3
  %11 = lshr i32 %10, 2
  %12 = add nuw nsw i32 %11, %9
  %13 = urem i32 %12, 240
  %14 = trunc nuw i32 %13 to i8
  br label %15

15:                                               ; preds = %3, %4
  %.sink = phi i8 [ %14, %4 ], [ -1, %3 ]
  %16 = getelementptr inbounds i8, ptr %1, i64 16
  store i8 %.sink, ptr %16, align 16
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) 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, !13, i64 24}
!6 = !{!"us_socket_t", !7, i64 0, !10, i64 16, !10, i64 17, !12, i64 18, !13, i64 24, !13, i64 32, !13, i64 40}
!7 = !{!"us_poll_t", !8, i64 0}
!8 = !{!"", !9, i64 0, !9, i64 3}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"short", !10, i64 0}
!13 = !{!"any pointer", !10, i64 0}
!14 = !{!15, !10, i64 12}
!15 = !{!"us_socket_context_t", !13, i64 0, !9, i64 8, !10, i64 12, !10, i64 13, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !13, i64 72, !13, i64 80, !13, i64 88, !13, i64 96, !13, i64 104, !13, i64 112, !13, i64 120, !13, i64 128}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass