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

; 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.poll_and_sock = type { ptr, ptr, i8, i32 }
%struct.sc_sock = type { %struct.sc_sock_fd, i8, i32, [128 x i8] }
%struct.sc_sock_fd = type { i32, i32, i32 }

@.str.3 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [8 x i8], align 1
@__PRETTY_FUNCTION__.client_poll_del = external hidden unnamed_addr constant [30 x i8], align 1
@.str.134 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.135 = external hidden unnamed_addr constant [23 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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

declare i32 @sc_sock_term(ptr noundef) #2

declare i32 @sc_sock_poll_add(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

declare i32 @sc_sock_poll_del(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @client_poll_del(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %7, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.poll_and_sock, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %10, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.poll_and_sock, ptr %11, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  store ptr %13, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.poll_and_sock, ptr %14, i32 0, i32 3
  %16 = load i32, ptr %15, align 4, !tbaa !14
  %17 = and i32 %16, 1
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %48

19:                                               ; preds = %1
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.sc_sock, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = call i32 @sc_sock_poll_del(ptr noundef %20, ptr noundef %22, i32 noundef 1, ptr noundef %23)
  store i32 %24, ptr %6, align 4, !tbaa !15
  %25 = load i32, ptr %6, align 4, !tbaa !15
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %19
  br label %29

28:                                               ; preds = %19
  call void @__assert_fail(ptr noundef @.str.15, ptr noundef @.str.3, i32 noundef 1728, ptr noundef @__PRETTY_FUNCTION__.client_poll_del) #6
  unreachable

29:                                               ; preds = %27
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.poll_and_sock, ptr %30, i32 0, i32 3
  %32 = load i32, ptr %31, align 4, !tbaa !14
  %33 = ashr i32 %32, 1
  %34 = and i32 %33, 1
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %47

36:                                               ; preds = %29
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.sc_sock, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = call i32 @sc_sock_poll_add(ptr noundef %37, ptr noundef %39, i32 noundef 1, ptr noundef %40)
  store i32 %41, ptr %6, align 4, !tbaa !15
  %42 = load i32, ptr %6, align 4, !tbaa !15
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %44, label %45

44:                                               ; preds = %36
  br label %46

45:                                               ; preds = %36
  call void @__assert_fail(ptr noundef @.str.15, ptr noundef @.str.3, i32 noundef 1734, ptr noundef @__PRETTY_FUNCTION__.client_poll_del) #6
  unreachable

46:                                               ; preds = %44
  br label %47

47:                                               ; preds = %46, %29
  br label %48

48:                                               ; preds = %47, %1
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.sc_sock, ptr %50, i32 0, i32 0
  %52 = call i32 @sc_sock_poll_del(ptr noundef %49, ptr noundef %51, i32 noundef 3, ptr noundef null)
  store i32 %52, ptr %6, align 4, !tbaa !15
  %53 = load i32, ptr %6, align 4, !tbaa !15
  %54 = icmp eq i32 %53, 0
  br i1 %54, label %55, label %56

55:                                               ; preds = %48
  br label %57

56:                                               ; preds = %48
  call void @__assert_fail(ptr noundef @.str.15, ptr noundef @.str.3, i32 noundef 1741, ptr noundef @__PRETTY_FUNCTION__.client_poll_del) #6
  unreachable

57:                                               ; preds = %55
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.sc_sock, ptr %58, i32 0, i32 0
  %60 = getelementptr inbounds %struct.sc_sock_fd, ptr %59, i32 0, i32 1
  %61 = load i32, ptr %60, align 4, !tbaa !16
  %62 = icmp eq i32 %61, 0
  br i1 %62, label %63, label %64

63:                                               ; preds = %57
  br label %65

64:                                               ; preds = %57
  call void @__assert_fail(ptr noundef @.str.134, ptr noundef @.str.3, i32 noundef 1743, ptr noundef @__PRETTY_FUNCTION__.client_poll_del) #6
  unreachable

65:                                               ; preds = %63
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = call i32 @sc_sock_term(ptr noundef %66)
  %68 = icmp eq i32 %67, 0
  br i1 %68, label %69, label %70

69:                                               ; preds = %65
  br label %71

70:                                               ; preds = %65
  call void @__assert_fail(ptr noundef @.str.135, ptr noundef @.str.3, i32 noundef 1744, ptr noundef @__PRETTY_FUNCTION__.client_poll_del) #6
  unreachable

71:                                               ; preds = %69
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %72) #5
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.poll_and_sock, ptr %73, i32 0, i32 1
  store ptr null, ptr %74, align 8, !tbaa !13
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret ptr %75
}

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 = { "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 "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 = { nounwind }
attributes #6 = { noreturn 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, !6, i64 0}
!10 = !{!"poll_and_sock", !6, i64 0, !6, i64 8, !11, i64 16, !12, i64 20}
!11 = !{!"_Bool", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 8}
!14 = !{!10, !12, i64 20}
!15 = !{!12, !12, i64 0}
!16 = !{!17, !12, i64 4}
!17 = !{!"sc_sock", !18, i64 0, !11, i64 12, !12, i64 16, !7, i64 20}
!18 = !{!"sc_sock_fd", !12, i64 0, !12, i64 4, !12, i64 8}


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

@.str.3 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [8 x i8], align 1
@__PRETTY_FUNCTION__.client_poll_del = external hidden unnamed_addr constant [30 x i8], align 1
@.str.134 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.135 = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

declare i32 @sc_sock_term(ptr noundef) local_unnamed_addr #1

declare i32 @sc_sock_poll_add(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare i32 @sc_sock_poll_del(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @client_poll_del(ptr noundef %0) local_unnamed_addr #2 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !12
  %5 = getelementptr inbounds i8, ptr %0, i64 20
  %6 = load i32, ptr %5, align 4, !tbaa !13
  %7 = and i32 %6, 1
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %19, label %8

8:                                                ; preds = %1
  %9 = tail call i32 @sc_sock_poll_del(ptr noundef %2, ptr noundef %4, i32 noundef 1, ptr noundef nonnull %0) #4
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  tail call void @__assert_fail(ptr noundef nonnull @.str.15, ptr noundef nonnull @.str.3, i32 noundef 1728, ptr noundef nonnull @__PRETTY_FUNCTION__.client_poll_del) #5
  unreachable

12:                                               ; preds = %8
  %13 = load i32, ptr %5, align 4, !tbaa !13
  %14 = and i32 %13, 2
  %.not20 = icmp eq i32 %14, 0
  br i1 %.not20, label %19, label %15

15:                                               ; preds = %12
  %16 = tail call i32 @sc_sock_poll_add(ptr noundef %2, ptr noundef %4, i32 noundef 1, ptr noundef nonnull %0) #4
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  tail call void @__assert_fail(ptr noundef nonnull @.str.15, ptr noundef nonnull @.str.3, i32 noundef 1734, ptr noundef nonnull @__PRETTY_FUNCTION__.client_poll_del) #5
  unreachable

19:                                               ; preds = %12, %15, %1
  %20 = tail call i32 @sc_sock_poll_del(ptr noundef %2, ptr noundef %4, i32 noundef 3, ptr noundef null) #4
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  tail call void @__assert_fail(ptr noundef nonnull @.str.15, ptr noundef nonnull @.str.3, i32 noundef 1741, ptr noundef nonnull @__PRETTY_FUNCTION__.client_poll_del) #5
  unreachable

23:                                               ; preds = %19
  %24 = getelementptr inbounds i8, ptr %4, i64 4
  %25 = load i32, ptr %24, align 4, !tbaa !14
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  tail call void @__assert_fail(ptr noundef nonnull @.str.134, ptr noundef nonnull @.str.3, i32 noundef 1743, ptr noundef nonnull @__PRETTY_FUNCTION__.client_poll_del) #5
  unreachable

28:                                               ; preds = %23
  %29 = tail call i32 @sc_sock_term(ptr noundef nonnull %4) #4
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %32, label %31

31:                                               ; preds = %28
  tail call void @__assert_fail(ptr noundef nonnull @.str.135, ptr noundef nonnull @.str.3, i32 noundef 1744, ptr noundef nonnull @__PRETTY_FUNCTION__.client_poll_del) #5
  unreachable

32:                                               ; preds = %28
  tail call void @free(ptr noundef nonnull %4) #4
  store ptr null, ptr %3, align 8, !tbaa !12
  ret ptr %2
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

attributes #0 = { noreturn 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 #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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { noreturn 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, !7, i64 0}
!6 = !{!"poll_and_sock", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 20}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_Bool", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !11, i64 20}
!14 = !{!15, !11, i64 4}
!15 = !{!"sc_sock", !16, i64 0, !10, i64 12, !11, i64 16, !8, i64 20}
!16 = !{!"sc_sock_fd", !11, i64 0, !11, i64 4, !11, i64 8}


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