; LLVM IR from wichue/nethello :: src/net/SocketBase.ll (ZN3chw8SockUtil10setCloExecEib)

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

%"class.chw::LogContextCapture" = type { %"class.std::shared_ptr", ptr }
%"class.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }

@.str = external hidden unnamed_addr constant [1 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@__FUNCTION__._ZN3chw8SockUtil10setCloExecEib = external hidden unnamed_addr constant [11 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [21 x i8], align 1

declare i32 @__gxx_personality_v0(...)

; 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

declare noundef nonnull align 8 dereferenceable(144) ptr @_ZN3chw9getLoggerEv() #1

declare void @_ZN3chw17LogContextCaptureC1ERNS_6LoggerENS_8LogLevelEPKcS5_iS5_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(144), i32 noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef) unnamed_addr #1

; Function Attrs: nounwind
declare void @_ZN3chw17LogContextCaptureD1Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN3chw8SockUtil10setCloExecEib(i32 noundef %0, i1 noundef zeroext %1) #3 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca %"class.chw::LogContextCapture", align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca %"class.chw::LogContextCapture", align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  %14 = zext i1 %1 to i8
  store i8 %14, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = call i32 (i32, i32, ...) @fcntl(i32 noundef %15, i32 noundef 1)
  store i32 %16, ptr %6, align 4, !tbaa !5
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = icmp eq i32 %17, -1
  br i1 %18, label %19, label %27

19:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #4
  %20 = call noundef nonnull align 8 dereferenceable(144) ptr @_ZN3chw9getLoggerEv()
  call void @_ZN3chw17LogContextCaptureC1ERNS_6LoggerENS_8LogLevelEPKcS5_iS5_(ptr noundef nonnull align 8 dereferenceable(24) %7, ptr noundef nonnull align 8 dereferenceable(144) %20, i32 noundef 0, ptr noundef @.str.1, ptr noundef @__FUNCTION__._ZN3chw8SockUtil10setCloExecEib, i32 noundef 231, ptr noundef @.str)
  %21 = invoke noundef nonnull align 8 dereferenceable(24) ptr @_ZN3chw17LogContextCapturelsIRA21_KcEERS0_OT_(ptr noundef nonnull align 8 dereferenceable(24) %7, ptr noundef nonnull align 1 dereferenceable(21) @.str.11)
          to label %22 unwind label %23

22:                                               ; preds = %19
  call void @_ZN3chw17LogContextCaptureD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %7) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #4
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %55

23:                                               ; preds = %19
  %24 = landingpad { ptr, i32 }
          cleanup
  %25 = extractvalue { ptr, i32 } %24, 0
  store ptr %25, ptr %8, align 8
  %26 = extractvalue { ptr, i32 } %24, 1
  store i32 %26, ptr %9, align 4
  call void @_ZN3chw17LogContextCaptureD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %7) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #4
  br label %57

27:                                               ; preds = %2
  %28 = load i8, ptr %5, align 1, !tbaa !9, !range !11, !noundef !12
  %29 = trunc i8 %28 to i1
  br i1 %29, label %30, label %33

30:                                               ; preds = %27
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = or i32 %31, 1
  store i32 %32, ptr %6, align 4, !tbaa !5
  br label %38

33:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 1, ptr %11, align 4, !tbaa !5
  %34 = load i32, ptr %11, align 4, !tbaa !5
  %35 = xor i32 %34, -1
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = and i32 %36, %35
  store i32 %37, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %38

38:                                               ; preds = %33, %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = call i32 (i32, i32, ...) @fcntl(i32 noundef %39, i32 noundef 2, i32 noundef %40)
  store i32 %41, ptr %12, align 4, !tbaa !5
  %42 = load i32, ptr %12, align 4, !tbaa !5
  %43 = icmp eq i32 %42, -1
  br i1 %43, label %44, label %52

44:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 24, ptr %13) #4
  %45 = call noundef nonnull align 8 dereferenceable(144) ptr @_ZN3chw9getLoggerEv()
  call void @_ZN3chw17LogContextCaptureC1ERNS_6LoggerENS_8LogLevelEPKcS5_iS5_(ptr noundef nonnull align 8 dereferenceable(24) %13, ptr noundef nonnull align 8 dereferenceable(144) %45, i32 noundef 0, ptr noundef @.str.1, ptr noundef @__FUNCTION__._ZN3chw8SockUtil10setCloExecEib, i32 noundef 242, ptr noundef @.str)
  %46 = invoke noundef nonnull align 8 dereferenceable(24) ptr @_ZN3chw17LogContextCapturelsIRA21_KcEERS0_OT_(ptr noundef nonnull align 8 dereferenceable(24) %13, ptr noundef nonnull align 1 dereferenceable(21) @.str.12)
          to label %47 unwind label %48

47:                                               ; preds = %44
  call void @_ZN3chw17LogContextCaptureD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %13) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %13) #4
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %54

48:                                               ; preds = %44
  %49 = landingpad { ptr, i32 }
          cleanup
  %50 = extractvalue { ptr, i32 } %49, 0
  store ptr %50, ptr %8, align 8
  %51 = extractvalue { ptr, i32 } %49, 1
  store i32 %51, ptr %9, align 4
  call void @_ZN3chw17LogContextCaptureD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %13) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %57

52:                                               ; preds = %38
  %53 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %53, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %54

54:                                               ; preds = %52, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %55

55:                                               ; preds = %54, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %56 = load i32, ptr %3, align 4
  ret i32 %56

57:                                               ; preds = %48, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %58

58:                                               ; preds = %57
  %59 = load ptr, ptr %8, align 8
  %60 = load i32, ptr %9, align 4
  %61 = insertvalue { ptr, i32 } poison, ptr %59, 0
  %62 = insertvalue { ptr, i32 } %61, i32 %60, 1
  resume { ptr, i32 } %62
}

declare i32 @fcntl(i32 noundef, i32 noundef, ...) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZN3chw17LogContextCapturelsIRA21_KcEERS0_OT_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 1 dereferenceable(21)) #3 align 2

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

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}


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

%"class.chw::LogContextCapture" = type { %"class.std::shared_ptr", ptr }
%"class.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }

@.str = external hidden unnamed_addr constant [1 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@__FUNCTION__._ZN3chw8SockUtil10setCloExecEib = external hidden unnamed_addr constant [11 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [21 x i8], align 1

declare i32 @__gxx_personality_v0(...)

; 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

declare noundef nonnull align 8 dereferenceable(144) ptr @_ZN3chw9getLoggerEv() local_unnamed_addr #1

declare void @_ZN3chw17LogContextCaptureC1ERNS_6LoggerENS_8LogLevelEPKcS5_iS5_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(144), i32 noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef) unnamed_addr #1

; Function Attrs: nounwind
declare void @_ZN3chw17LogContextCaptureD1Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN3chw8SockUtil10setCloExecEib(i32 noundef %0, i1 noundef zeroext %1) local_unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca %"class.chw::LogContextCapture", align 8
  %4 = alloca %"class.chw::LogContextCapture", align 8
  %5 = tail call i32 (i32, i32, ...) @fcntl(i32 noundef %0, i32 noundef 1)
  %6 = icmp eq i32 %5, -1
  br i1 %6, label %7, label %13

7:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #4
  %8 = tail call noundef nonnull align 8 dereferenceable(144) ptr @_ZN3chw9getLoggerEv()
  call void @_ZN3chw17LogContextCaptureC1ERNS_6LoggerENS_8LogLevelEPKcS5_iS5_(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(144) %8, i32 noundef 0, ptr noundef nonnull @.str.1, ptr noundef nonnull @__FUNCTION__._ZN3chw8SockUtil10setCloExecEib, i32 noundef 231, ptr noundef nonnull @.str)
  %9 = invoke noundef nonnull align 8 dereferenceable(24) ptr @_ZN3chw17LogContextCapturelsIRA21_KcEERS0_OT_(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 1 dereferenceable(21) @.str.11)
          to label %10 unwind label %11

10:                                               ; preds = %7
  call void @_ZN3chw17LogContextCaptureD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %3) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #4
  br label %23

11:                                               ; preds = %7
  %12 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN3chw17LogContextCaptureD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %3) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #4
  br label %24

13:                                               ; preds = %2
  %14 = and i32 %5, -2
  %masksel = zext i1 %1 to i32
  %.012 = or disjoint i32 %14, %masksel
  %15 = tail call i32 (i32, i32, ...) @fcntl(i32 noundef %0, i32 noundef 2, i32 noundef %.012)
  %16 = icmp eq i32 %15, -1
  br i1 %16, label %17, label %23

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #4
  %18 = tail call noundef nonnull align 8 dereferenceable(144) ptr @_ZN3chw9getLoggerEv()
  call void @_ZN3chw17LogContextCaptureC1ERNS_6LoggerENS_8LogLevelEPKcS5_iS5_(ptr noundef nonnull align 8 dereferenceable(24) %4, ptr noundef nonnull align 8 dereferenceable(144) %18, i32 noundef 0, ptr noundef nonnull @.str.1, ptr noundef nonnull @__FUNCTION__._ZN3chw8SockUtil10setCloExecEib, i32 noundef 242, ptr noundef nonnull @.str)
  %19 = invoke noundef nonnull align 8 dereferenceable(24) ptr @_ZN3chw17LogContextCapturelsIRA21_KcEERS0_OT_(ptr noundef nonnull align 8 dereferenceable(24) %4, ptr noundef nonnull align 1 dereferenceable(21) @.str.12)
          to label %20 unwind label %21

20:                                               ; preds = %17
  call void @_ZN3chw17LogContextCaptureD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %4) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #4
  br label %23

21:                                               ; preds = %17
  %22 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN3chw17LogContextCaptureD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %4) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #4
  br label %24

23:                                               ; preds = %20, %13, %10
  %.1 = phi i32 [ -1, %10 ], [ -1, %20 ], [ %15, %13 ]
  ret i32 %.1

24:                                               ; preds = %21, %11
  %.pn = phi { ptr, i32 } [ %12, %11 ], [ %22, %21 ]
  resume { ptr, i32 } %.pn
}

declare i32 @fcntl(i32 noundef, i32 noundef, ...) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZN3chw17LogContextCapturelsIRA21_KcEERS0_OT_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 1 dereferenceable(21)) local_unnamed_addr #3 align 2

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

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


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