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

; 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_lang_s = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %union.pthread_mutex_t }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }

@trace_lang = external hidden global ptr, align 8
@trace_ctx = external hidden global ptr, align 8
@trace_signal_fds = external hidden global [2 x i32], align 4
@trace_init_cb = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @mln_trace_init(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %14, label %8

8:                                                ; preds = %2
  %9 = load ptr, ptr @trace_lang, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %14, label %11

11:                                               ; preds = %8
  %12 = load ptr, ptr @trace_ctx, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %11, %8, %2
  br label %58

15:                                               ; preds = %11
  %16 = call i32 @socketpair(i32 noundef 1, i32 noundef 1, i32 noundef 0, ptr noundef @trace_signal_fds) #3
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %15
  br label %58

19:                                               ; preds = %15
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = call ptr @mln_lang_new(ptr noundef %20, ptr noundef @mln_trace_lang_signal, ptr noundef @mln_trace_lang_clear)
  store ptr %21, ptr @trace_lang, align 8, !tbaa !5
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %24

23:                                               ; preds = %19
  br label %53

24:                                               ; preds = %19
  %25 = load ptr, ptr @trace_lang, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.mln_lang_s, ptr %25, i32 0, i32 7
  %27 = load i64, ptr %26, align 8
  %28 = and i64 %27, 9223372036854775807
  %29 = or i64 %28, -9223372036854775808
  store i64 %29, ptr %26, align 8
  %30 = load ptr, ptr @trace_lang, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = call ptr @mln_lang_job_new(ptr noundef %30, ptr noundef null, i32 noundef 1, ptr noundef %31, ptr noundef null, ptr noundef @mln_trace_lang_ctx_return_handler)
  store ptr %32, ptr @trace_ctx, align 8, !tbaa !5
  %33 = load ptr, ptr @trace_ctx, align 8, !tbaa !5
  %34 = icmp eq ptr %33, null
  br i1 %34, label %35, label %36

35:                                               ; preds = %24
  br label %51

36:                                               ; preds = %24
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = call ptr @mln_event_timer_set(ptr noundef %37, i32 noundef 10, ptr noundef null, ptr noundef @mln_trace_lang_check)
  %39 = icmp eq ptr %38, null
  br i1 %39, label %40, label %41

40:                                               ; preds = %36
  br label %51

41:                                               ; preds = %36
  %42 = load ptr, ptr @trace_init_cb, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %50

44:                                               ; preds = %41
  %45 = load ptr, ptr @trace_init_cb, align 8, !tbaa !5
  %46 = load ptr, ptr @trace_ctx, align 8, !tbaa !5
  %47 = call i32 %45(ptr noundef %46)
  %48 = icmp slt i32 %47, 0
  br i1 %48, label %49, label %50

49:                                               ; preds = %44
  br label %51

50:                                               ; preds = %44, %41
  store i32 0, ptr %3, align 4
  br label %59

51:                                               ; preds = %49, %40, %35
  %52 = load ptr, ptr @trace_lang, align 8, !tbaa !5
  call void @mln_lang_free(ptr noundef %52)
  br label %53

53:                                               ; preds = %51, %23
  %54 = load i32, ptr @trace_signal_fds, align 4, !tbaa !9
  %55 = call i32 @close(i32 noundef %54)
  %56 = load i32, ptr getelementptr inbounds ([2 x i32], ptr @trace_signal_fds, i64 0, i64 1), align 4, !tbaa !9
  %57 = call i32 @close(i32 noundef %56)
  br label %58

58:                                               ; preds = %53, %18, %14
  store i32 -1, ptr %3, align 4
  br label %59

59:                                               ; preds = %58, %50
  %60 = load i32, ptr %3, align 4
  ret i32 %60
}

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

declare ptr @mln_lang_new(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @mln_trace_lang_signal(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @mln_trace_lang_clear(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
declare hidden void @mln_trace_lang_ctx_return_handler(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
declare hidden void @mln_trace_lang_check(ptr noundef, ptr noundef) #0

declare void @mln_lang_free(ptr noundef) #2

declare i32 @close(i32 noundef) #2

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" }
attributes #1 = { 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 }

!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}


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

@trace_lang = external hidden local_unnamed_addr global ptr, align 8
@trace_ctx = external hidden local_unnamed_addr global ptr, align 8
@trace_signal_fds = external hidden global [2 x i32], align 4
@trace_init_cb = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @mln_trace_init(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %1, null
  %4 = load ptr, ptr @trace_lang, align 8
  %5 = icmp ne ptr %4, null
  %or.cond = select i1 %3, i1 true, i1 %5
  %6 = load ptr, ptr @trace_ctx, align 8
  %7 = icmp ne ptr %6, null
  %or.cond3 = select i1 %or.cond, i1 true, i1 %7
  br i1 %or.cond3, label %36, label %8

8:                                                ; preds = %2
  %9 = tail call i32 @socketpair(i32 noundef 1, i32 noundef 1, i32 noundef 0, ptr noundef nonnull @trace_signal_fds) #3
  %10 = icmp slt i32 %9, 0
  br i1 %10, label %36, label %11

11:                                               ; preds = %8
  %12 = tail call ptr @mln_lang_new(ptr noundef %0, ptr noundef nonnull @mln_trace_lang_signal, ptr noundef nonnull @mln_trace_lang_clear) #3
  store ptr %12, ptr @trace_lang, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %31, label %14

14:                                               ; preds = %11
  %15 = getelementptr inbounds i8, ptr %12, i64 56
  %16 = load i64, ptr %15, align 8
  %17 = or i64 %16, -9223372036854775808
  store i64 %17, ptr %15, align 8
  %18 = tail call ptr @mln_lang_job_new(ptr noundef nonnull %12, ptr noundef null, i32 noundef 1, ptr noundef nonnull %1, ptr noundef null, ptr noundef nonnull @mln_trace_lang_ctx_return_handler) #3
  store ptr %18, ptr @trace_ctx, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %29, label %20

20:                                               ; preds = %14
  %21 = tail call ptr @mln_event_timer_set(ptr noundef %0, i32 noundef 10, ptr noundef null, ptr noundef nonnull @mln_trace_lang_check) #3
  %22 = icmp eq ptr %21, null
  br i1 %22, label %29, label %23

23:                                               ; preds = %20
  %24 = load ptr, ptr @trace_init_cb, align 8, !tbaa !5
  %.not = icmp eq ptr %24, null
  br i1 %.not, label %36, label %25

25:                                               ; preds = %23
  %26 = load ptr, ptr @trace_ctx, align 8, !tbaa !5
  %27 = tail call i32 %24(ptr noundef %26) #3
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %29, label %36

29:                                               ; preds = %25, %20, %14
  %30 = load ptr, ptr @trace_lang, align 8, !tbaa !5
  tail call void @mln_lang_free(ptr noundef %30) #3
  br label %31

31:                                               ; preds = %11, %29
  %32 = load i32, ptr @trace_signal_fds, align 4, !tbaa !9
  %33 = tail call i32 @close(i32 noundef %32) #3
  %34 = load i32, ptr getelementptr inbounds (i8, ptr @trace_signal_fds, i64 4), align 4, !tbaa !9
  %35 = tail call i32 @close(i32 noundef %34) #3
  br label %36

36:                                               ; preds = %31, %2, %8, %23, %25
  %.0 = phi i32 [ 0, %25 ], [ 0, %23 ], [ -1, %8 ], [ -1, %2 ], [ -1, %31 ]
  ret i32 %.0
}

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

declare ptr @mln_lang_new(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @mln_trace_lang_signal(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @mln_trace_lang_clear(ptr noundef) #0

declare ptr @mln_lang_job_new(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @mln_trace_lang_ctx_return_handler(ptr noundef) #0

declare ptr @mln_event_timer_set(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @mln_trace_lang_check(ptr noundef, ptr noundef) #0

declare void @mln_lang_free(ptr noundef) local_unnamed_addr #2

declare i32 @close(i32 noundef) local_unnamed_addr #2

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" }
attributes #1 = { 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 }

!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}


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