; 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 uwtable
define dso_local i32 @sc_sock_poll_add(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 i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca %struct.epoll_event, align 1
  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
  store i32 3, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.sc_sock_fd, ptr %16, i32 0, i32 1
  %18 = load i32, ptr %17, align 4, !tbaa !11
  store i32 %18, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %19 = load i32, ptr %12, align 4, !tbaa !9
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = or i32 %19, %20
  store i32 %21, ptr %13, align 4, !tbaa !9
  %22 = load i32, ptr %13, align 4, !tbaa !9
  %23 = icmp eq i32 %22, 4
  br i1 %23, label %24, label %25

24:                                               ; preds = %4
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %24, %4
  %26 = load i32, ptr %12, align 4, !tbaa !9
  %27 = load i32, ptr %13, align 4, !tbaa !9
  %28 = icmp eq i32 %26, %27
  br i1 %28, label %29, label %30

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

30:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 12, ptr %15) #4
  %31 = getelementptr inbounds %struct.epoll_event, ptr %15, i32 0, i32 0
  store i32 8216, ptr %31, align 1, !tbaa !13
  %32 = getelementptr inbounds %struct.epoll_event, ptr %15, i32 0, i32 1
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %33, ptr %32, align 1, !tbaa !15
  %34 = load i32, ptr %12, align 4, !tbaa !9
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %30
  store i32 1, ptr %11, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %36, %30
  %38 = load i32, ptr %13, align 4, !tbaa !9
  %39 = and i32 %38, 1
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %45

41:                                               ; preds = %37
  %42 = getelementptr inbounds %struct.epoll_event, ptr %15, i32 0, i32 0
  %43 = load i32, ptr %42, align 1, !tbaa !13
  %44 = or i32 %43, 1
  store i32 %44, ptr %42, align 1, !tbaa !13
  br label %45

45:                                               ; preds = %41, %37
  %46 = load i32, ptr %13, align 4, !tbaa !9
  %47 = and i32 %46, 2
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %53

49:                                               ; preds = %45
  %50 = getelementptr inbounds %struct.epoll_event, ptr %15, i32 0, i32 0
  %51 = load i32, ptr %50, align 1, !tbaa !13
  %52 = or i32 %51, 4
  store i32 %52, ptr %50, align 1, !tbaa !13
  br label %53

53:                                               ; preds = %49, %45
  %54 = load i32, ptr %13, align 4, !tbaa !9
  %55 = and i32 %54, 4
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %61

57:                                               ; preds = %53
  %58 = getelementptr inbounds %struct.epoll_event, ptr %15, i32 0, i32 0
  %59 = load i32, ptr %58, align 1, !tbaa !13
  %60 = or i32 %59, -2147483648
  store i32 %60, ptr %58, align 1, !tbaa !13
  br label %61

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

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

83:                                               ; preds = %61
  store i32 0, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %84

84:                                               ; preds = %83, %75
  call void @llvm.lifetime.end.p0(i64 12, ptr %15) #4
  br label %85

85:                                               ; preds = %84, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, 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
}

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

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 4}
!12 = !{!"sc_sock_fd", !10, i64 0, !10, i64 4, !10, i64 8}
!13 = !{!14, !10, i64 0}
!14 = !{!"epoll_event", !10, i64 0, !7, i64 4}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !10, i64 0}
!17 = !{!"sc_sock_poll", !10, i64 0, !6, i64 8}
!18 = !{!12, !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 uwtable
define dso_local range(i32 -1, 1) i32 @sc_sock_poll_add(ptr noundef %0, ptr nocapture noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #3 {
  %5 = alloca %struct.epoll_event, align 4
  %6 = getelementptr inbounds i8, ptr %1, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = or i32 %7, %2
  %9 = icmp eq i32 %8, 4
  %spec.store.select = select i1 %9, i32 0, i32 %8
  %10 = icmp eq i32 %7, %spec.store.select
  br i1 %10, label %30, label %11

11:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %5) #4
  store i32 8216, ptr %5, align 4, !tbaa !10
  %12 = getelementptr inbounds i8, ptr %5, i64 4
  store ptr %3, ptr %12, align 4, !tbaa !12
  %13 = icmp eq i32 %7, 0
  %spec.select = select i1 %13, i32 1, i32 3
  %14 = and i32 %spec.store.select, 7
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %21, label %15

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

21:                                               ; preds = %11, %15
  store i32 %spec.store.select, ptr %6, align 4, !tbaa !5
  %22 = load i32, ptr %0, align 8, !tbaa !13
  %23 = load i32, ptr %1, align 4, !tbaa !16
  %24 = call i32 @epoll_ctl(i32 noundef %22, i32 noundef %spec.select, i32 noundef %23, ptr noundef nonnull %5) #4
  %.not24 = icmp eq i32 %24, 0
  br i1 %.not24, label %29, label %25

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

29:                                               ; preds = %21, %25
  %.0 = phi i32 [ -1, %25 ], [ 0, %21 ]
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %5) #4
  br label %30

30:                                               ; preds = %4, %29
  %.1 = phi i32 [ %.0, %29 ], [ 0, %4 ]
  ret i32 %.1
}

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

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


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