; LLVM IR from Water-Melon/Melon :: src (mln_thread)

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

; 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: nounwind uwtable
define dso_local i32 @mln_thread_create(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %2, ptr noundef nonnull %3, i32 noundef %4, ptr noundef nonnull %5) #1 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca [2 x i32], align 4
  %16 = alloca %struct.mln_thread_attr, align 8
  %17 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store i32 %2, ptr %10, align 4, !tbaa !9
  store ptr %3, ptr %11, align 8, !tbaa !5
  store i32 %4, ptr %12, align 4, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.start.p0(i64 48, ptr %16) #5
  %18 = getelementptr inbounds [2 x i32], ptr %15, i64 0, i64 0
  %19 = call i32 @socketpair(i32 noundef 1, i32 noundef 1, i32 noundef 0, ptr noundef %18) #5
  %20 = icmp slt i32 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %6
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %59

22:                                               ; preds = %6
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.mln_thread_attr, ptr %16, i32 0, i32 0
  store ptr %23, ptr %24, align 8, !tbaa !11
  %25 = load i32, ptr %10, align 4, !tbaa !9
  %26 = getelementptr inbounds %struct.mln_thread_attr, ptr %16, i32 0, i32 7
  store i32 %25, ptr %26, align 4, !tbaa !13
  %27 = load ptr, ptr %13, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.mln_thread_attr, ptr %16, i32 0, i32 3
  store ptr %27, ptr %28, align 8, !tbaa !14
  %29 = load i32, ptr %12, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  %31 = getelementptr inbounds %struct.mln_thread_attr, ptr %16, i32 0, i32 4
  store i32 %30, ptr %31, align 8, !tbaa !15
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.mln_thread_attr, ptr %16, i32 0, i32 2
  store ptr %32, ptr %33, align 8, !tbaa !16
  %34 = load ptr, ptr %11, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.mln_thread_attr, ptr %16, i32 0, i32 1
  store ptr %34, ptr %35, align 8, !tbaa !17
  %36 = getelementptr inbounds [2 x i32], ptr %15, i64 0, i64 0
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = getelementptr inbounds %struct.mln_thread_attr, ptr %16, i32 0, i32 6
  store i32 %37, ptr %38, align 8, !tbaa !18
  %39 = getelementptr inbounds [2 x i32], ptr %15, i64 0, i64 1
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = getelementptr inbounds %struct.mln_thread_attr, ptr %16, i32 0, i32 5
  store i32 %40, ptr %41, align 4, !tbaa !19
  %42 = call ptr @mln_thread_init(ptr noundef %16)
  store ptr %42, ptr %14, align 8, !tbaa !5
  %43 = load ptr, ptr %14, align 8, !tbaa !5
  %44 = icmp eq ptr %43, null
  br i1 %44, label %45, label %52

45:                                               ; preds = %22
  %46 = getelementptr inbounds [2 x i32], ptr %15, i64 0, i64 0
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = call i32 @close(i32 noundef %47)
  %49 = getelementptr inbounds [2 x i32], ptr %15, i64 0, i64 1
  %50 = load i32, ptr %49, align 4, !tbaa !9
  %51 = call i32 @close(i32 noundef %50)
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %59

52:                                               ; preds = %22
  %53 = load ptr, ptr %14, align 8, !tbaa !5
  %54 = call i32 @__mln_thread_create(ptr noundef %53)
  %55 = icmp slt i32 %54, 0
  br i1 %55, label %56, label %58

56:                                               ; preds = %52
  %57 = load ptr, ptr %14, align 8, !tbaa !5
  call void @mln_thread_destroy(ptr noundef %57)
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %59

58:                                               ; preds = %52
  store i32 0, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %59

59:                                               ; preds = %58, %56, %45, %21
  call void @llvm.lifetime.end.p0(i64 48, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  %60 = load i32, ptr %7, align 4
  ret i32 %60
}

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

; Function Attrs: nounwind uwtable
declare hidden ptr @mln_thread_init(ptr noundef nonnull) #1

declare i32 @close(i32 noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @__mln_thread_create(ptr noundef) #4

; Function Attrs: nounwind uwtable
declare hidden void @mln_thread_destroy(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 = { "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 = { inlinehint 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 #5 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"mln_thread_attr", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44}
!13 = !{!12, !10, i64 44}
!14 = !{!12, !6, i64 24}
!15 = !{!12, !10, i64 32}
!16 = !{!12, !6, i64 16}
!17 = !{!12, !6, i64 8}
!18 = !{!12, !10, i64 40}
!19 = !{!12, !10, i64 36}


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

; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @mln_thread_create(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %2, ptr noundef nonnull %3, i32 noundef %4, ptr noundef nonnull %5) local_unnamed_addr #1 {
  %7 = alloca [2 x i32], align 8
  %8 = alloca %struct.mln_thread_attr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #5
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %8) #5
  %9 = call i32 @socketpair(i32 noundef 1, i32 noundef 1, i32 noundef 0, ptr noundef nonnull %7) #5
  %10 = icmp slt i32 %9, 0
  br i1 %10, label %33, label %11

11:                                               ; preds = %6
  store ptr %0, ptr %8, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %8, i64 44
  store i32 %2, ptr %12, align 4, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %8, i64 24
  store ptr %5, ptr %13, align 8, !tbaa !12
  %14 = add nsw i32 %4, 1
  %15 = getelementptr inbounds i8, ptr %8, i64 32
  store i32 %14, ptr %15, align 8, !tbaa !13
  %16 = getelementptr inbounds i8, ptr %8, i64 16
  store ptr %1, ptr %16, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %8, i64 8
  store ptr %3, ptr %17, align 8, !tbaa !15
  %18 = getelementptr inbounds i8, ptr %8, i64 36
  %19 = load <2 x i32>, ptr %7, align 8, !tbaa !16
  %20 = shufflevector <2 x i32> %19, <2 x i32> poison, <2 x i32> <i32 1, i32 0>
  store <2 x i32> %20, ptr %18, align 4, !tbaa !16
  %21 = call ptr @mln_thread_init(ptr noundef %8)
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %29

23:                                               ; preds = %11
  %24 = getelementptr inbounds i8, ptr %7, i64 4
  %25 = load i32, ptr %7, align 8, !tbaa !16
  %26 = call i32 @close(i32 noundef %25) #5
  %27 = load i32, ptr %24, align 4, !tbaa !16
  %28 = call i32 @close(i32 noundef %27) #5
  br label %33

29:                                               ; preds = %11
  %30 = call i32 @__mln_thread_create(ptr noundef nonnull %21)
  %31 = icmp slt i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %29
  call void @mln_thread_destroy(ptr noundef nonnull %21)
  br label %33

33:                                               ; preds = %29, %6, %32, %23
  %.0 = phi i32 [ -1, %23 ], [ -1, %32 ], [ -1, %6 ], [ 0, %29 ]
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #5
  ret i32 %.0
}

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

; Function Attrs: nounwind uwtable
declare hidden ptr @mln_thread_init(ptr noundef nonnull) local_unnamed_addr #1

declare i32 @close(i32 noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @__mln_thread_create(ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare hidden void @mln_thread_destroy(ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 = { "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 = { inlinehint 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 #5 = { 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 = !{!"mln_thread_attr", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 44}
!12 = !{!6, !7, i64 24}
!13 = !{!6, !10, i64 32}
!14 = !{!6, !7, i64 16}
!15 = !{!6, !7, i64 8}
!16 = !{!10, !10, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass