; LLVM IR from tezc/sc :: socket (sc_sock)

; 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.epoll_event = type <{ i32, %union.epoll_data }>
%union.epoll_data = type { ptr }
%struct.sc_sock_fd = type { i32, i32, i32 }
%struct.sc_sock_poll = type { i32, ptr }

@.str.6 = external hidden unnamed_addr constant [16 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: nounwind willreturn memory(none)
declare ptr @__errno_location() #1

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

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) #2

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

; Function Attrs: nounwind
declare i32 @epoll_ctl(i32 noundef, i32 noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @sc_sock_poll_del(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #3 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca %struct.epoll_event, align 1
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 12, ptr %12) #4
  %16 = getelementptr inbounds %struct.epoll_event, ptr %12, i32 0, i32 0
  store i32 8216, ptr %16, align 1, !tbaa !11
  %17 = getelementptr inbounds %struct.epoll_event, ptr %12, i32 0, i32 1
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %18, ptr %17, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.sc_sock_fd, ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !14
  store i32 %21, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %22 = load i32, ptr %13, align 4, !tbaa !9
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = xor i32 %23, -1
  %25 = and i32 %22, %24
  store i32 %25, ptr %14, align 4, !tbaa !9
  %26 = load i32, ptr %14, align 4, !tbaa !9
  %27 = icmp eq i32 %26, 4
  br i1 %27, label %28, label %29

28:                                               ; preds = %4
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %28, %4
  %30 = load i32, ptr %13, align 4, !tbaa !9
  %31 = load i32, ptr %14, align 4, !tbaa !9
  %32 = icmp eq i32 %30, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %29
  store i32 0, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %85

34:                                               ; preds = %29
  %35 = load i32, ptr %14, align 4, !tbaa !9
  %36 = icmp eq i32 %35, 0
  %37 = zext i1 %36 to i64
  %38 = select i1 %36, i32 2, i32 3
  store i32 %38, ptr %11, align 4, !tbaa !9
  %39 = load i32, ptr %14, align 4, !tbaa !9
  %40 = and i32 %39, 1
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %46

42:                                               ; preds = %34
  %43 = getelementptr inbounds %struct.epoll_event, ptr %12, i32 0, i32 0
  %44 = load i32, ptr %43, align 1, !tbaa !11
  %45 = or i32 %44, 1
  store i32 %45, ptr %43, align 1, !tbaa !11
  br label %46

46:                                               ; preds = %42, %34
  %47 = load i32, ptr %14, align 4, !tbaa !9
  %48 = and i32 %47, 2
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %54

50:                                               ; preds = %46
  %51 = getelementptr inbounds %struct.epoll_event, ptr %12, i32 0, i32 0
  %52 = load i32, ptr %51, align 1, !tbaa !11
  %53 = or i32 %52, 4
  store i32 %53, ptr %51, align 1, !tbaa !11
  br label %54

54:                                               ; preds = %50, %46
  %55 = load i32, ptr %14, align 4, !tbaa !9
  %56 = and i32 %55, 4
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %62

58:                                               ; preds = %54
  %59 = getelementptr inbounds %struct.epoll_event, ptr %12, i32 0, i32 0
  %60 = load i32, ptr %59, align 1, !tbaa !11
  %61 = or i32 %60, -2147483648
  store i32 %61, ptr %59, align 1, !tbaa !11
  br label %62

62:                                               ; preds = %58, %54
  %63 = load i32, ptr %14, align 4, !tbaa !9
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.sc_sock_fd, ptr %64, i32 0, i32 1
  store i32 %63, ptr %65, align 4, !tbaa !14
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.sc_sock_poll, ptr %66, i32 0, i32 0
  %68 = load i32, ptr %67, align 8, !tbaa !16
  %69 = load i32, ptr %11, align 4, !tbaa !9
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.sc_sock_fd, ptr %70, i32 0, i32 0
  %72 = load i32, ptr %71, align 4, !tbaa !18
  %73 = call i32 @epoll_ctl(i32 noundef %68, i32 noundef %69, i32 noundef %72, ptr noundef %12) #4
  store i32 %73, ptr %10, align 4, !tbaa !9
  %74 = load i32, ptr %10, align 4, !tbaa !9
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %76, label %84

76:                                               ; preds = %62
  %77 = load i32, ptr %13, align 4, !tbaa !9
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.sc_sock_fd, ptr %78, i32 0, i32 1
  store i32 %77, ptr %79, align 4, !tbaa !14
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = call ptr @__errno_location() #5
  %82 = load i32, ptr %81, align 4, !tbaa !9
  %83 = call ptr @strerror(i32 noundef %82) #4
  call void (ptr, ptr, ...) @sc_sock_poll_set_err(ptr noundef %80, ptr noundef @.str.6, ptr noundef %83)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %85

84:                                               ; preds = %62
  store i32 0, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %85

85:                                               ; preds = %84, %76, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %86 = load i32, ptr %5, align 4
  ret i32 %86
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind willreturn memory(none) "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 "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 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 }
attributes #5 = { nounwind willreturn memory(none) }

!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, !10, i64 0}
!12 = !{!"epoll_event", !10, i64 0, !7, i64 4}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !10, i64 4}
!15 = !{!"sc_sock_fd", !10, i64 0, !10, i64 4, !10, i64 8}
!16 = !{!17, !10, i64 0}
!17 = !{!"sc_sock_poll", !10, i64 0, !6, i64 8}
!18 = !{!15, !10, i64 0}


; 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.epoll_event = type <{ i32, %union.epoll_data }>
%union.epoll_data = type { ptr }

@.str.6 = external hidden unnamed_addr constant [16 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 nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #1

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

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @sc_sock_poll_set_err(ptr noundef, ptr noundef, ...) local_unnamed_addr #3

; Function Attrs: nounwind
declare i32 @epoll_ctl(i32 noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @sc_sock_poll_del(ptr noundef %0, ptr nocapture noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #3 {
  %5 = alloca %struct.epoll_event, align 4
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %5) #4
  store i32 8216, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 4
  store ptr %3, ptr %6, align 4, !tbaa !10
  %7 = getelementptr inbounds i8, ptr %1, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !11
  %9 = xor i32 %2, -1
  %10 = and i32 %8, %9
  %11 = icmp eq i32 %10, 4
  %spec.store.select = select i1 %11, i32 0, i32 %10
  %12 = icmp eq i32 %8, %spec.store.select
  br i1 %12, label %31, label %13

13:                                               ; preds = %4
  %14 = icmp eq i32 %spec.store.select, 0
  %15 = select i1 %14, i32 2, i32 3
  %16 = and i32 %spec.store.select, 7
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %23, label %17

17:                                               ; preds = %13
  %18 = and i32 %spec.store.select, 1
  %19 = and i32 %spec.store.select, 2
  %.not21.not = icmp eq i32 %19, 0
  %.v = select i1 %.not21.not, i32 8216, i32 8220
  %20 = or disjoint i32 %18, %.v
  %21 = shl i32 %spec.store.select, 29
  %22 = and i32 %21, -2147483648
  %spec.select = or disjoint i32 %20, %22
  store i32 %spec.select, ptr %5, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %13, %17
  store i32 %spec.store.select, ptr %7, align 4, !tbaa !11
  %24 = load i32, ptr %0, align 8, !tbaa !13
  %25 = load i32, ptr %1, align 4, !tbaa !16
  %26 = call i32 @epoll_ctl(i32 noundef %24, i32 noundef %15, i32 noundef %25, ptr noundef nonnull %5) #4
  %.not23 = icmp eq i32 %26, 0
  br i1 %.not23, label %31, label %27

27:                                               ; preds = %23
  store i32 %8, ptr %7, align 4, !tbaa !11
  %28 = tail call ptr @__errno_location() #5
  %29 = load i32, ptr %28, align 4, !tbaa !17
  %30 = call ptr @strerror(i32 noundef %29) #4
  call void (ptr, ptr, ...) @sc_sock_poll_set_err(ptr noundef nonnull %0, ptr noundef nonnull @.str.6, ptr noundef %30)
  br label %31

31:                                               ; preds = %23, %4, %27
  %.0 = phi i32 [ -1, %27 ], [ 0, %4 ], [ 0, %23 ]
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %5) #4
  ret i32 %.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 "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 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 }
attributes #5 = { nounwind willreturn memory(none) }

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


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