; LLVM IR from monolith-network/nettle :: lib/Socket.ll (ZN6nettle6Socket11setupSocketEi11sockaddr_in)

; 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.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }
%"class.nettle::Socket" = type { i8, i32, %struct.sockaddr_in, %struct.timeval, %struct.timeval, %"class.std::function" }
%struct.timeval = type { i64, i64 }
%"class.std::function" = type { %"class.std::_Function_base", ptr }
%"class.std::_Function_base" = type { %"union.std::_Any_data", ptr }
%"union.std::_Any_data" = type { %"union.std::_Nocopy_types" }
%"union.std::_Nocopy_types" = type { { i64, i64 } }

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN6nettle6Socket11setupSocketEi11sockaddr_in(ptr noundef nonnull align 8 dereferenceable(88) %0, i32 noundef %1, i64 %2, i64 %3) #0 align 2 {
  %5 = alloca i1, align 1
  %6 = alloca %struct.sockaddr_in, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 0
  store i64 %2, ptr %11, align 4
  %12 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 1
  store i64 %3, ptr %12, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  %13 = load ptr, ptr %7, align 8
  %14 = getelementptr inbounds %"class.nettle::Socket", ptr %13, i32 0, i32 0
  %15 = load i8, ptr %14, align 8, !tbaa !11, !range !21, !noundef !22
  %16 = trunc i8 %15 to i1
  br i1 %16, label %48, label %17

17:                                               ; preds = %4
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = getelementptr inbounds %"class.nettle::Socket", ptr %13, i32 0, i32 1
  store i32 %18, ptr %19, align 4, !tbaa !23
  %20 = getelementptr inbounds %"class.nettle::Socket", ptr %13, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %20, ptr align 4 %6, i64 16, i1 false), !tbaa.struct !24
  %21 = getelementptr inbounds %"class.nettle::Socket", ptr %13, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !23
  %23 = getelementptr inbounds %"class.nettle::Socket", ptr %13, i32 0, i32 3
  %24 = call i32 @setsockopt(i32 noundef %22, i32 noundef 1, i32 noundef 20, ptr noundef %23, i32 noundef 16) #4
  %25 = icmp slt i32 %24, 0
  br i1 %25, label %26, label %28

26:                                               ; preds = %17
  %27 = getelementptr inbounds %"class.nettle::Socket", ptr %13, i32 0, i32 5
  call void @_ZNKSt8functionIFvN6nettle11SocketErrorEEEclES1_(ptr noundef nonnull align 8 dereferenceable(32) %27, i32 noundef 0)
  store i1 false, ptr %5, align 1
  br label %51

28:                                               ; preds = %17
  %29 = getelementptr inbounds %"class.nettle::Socket", ptr %13, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !23
  %31 = getelementptr inbounds %"class.nettle::Socket", ptr %13, i32 0, i32 4
  %32 = call i32 @setsockopt(i32 noundef %30, i32 noundef 1, i32 noundef 21, ptr noundef %31, i32 noundef 16) #4
  %33 = icmp slt i32 %32, 0
  br i1 %33, label %34, label %36

34:                                               ; preds = %28
  %35 = getelementptr inbounds %"class.nettle::Socket", ptr %13, i32 0, i32 5
  call void @_ZNKSt8functionIFvN6nettle11SocketErrorEEEclES1_(ptr noundef nonnull align 8 dereferenceable(32) %35, i32 noundef 1)
  store i1 false, ptr %5, align 1
  br label %51

36:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 1, ptr %9, align 4, !tbaa !9
  %37 = getelementptr inbounds %"class.nettle::Socket", ptr %13, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !23
  %39 = call i32 @setsockopt(i32 noundef %38, i32 noundef 1, i32 noundef 2, ptr noundef %9, i32 noundef 4) #4
  %40 = icmp slt i32 %39, 0
  br i1 %40, label %41, label %43

41:                                               ; preds = %36
  %42 = getelementptr inbounds %"class.nettle::Socket", ptr %13, i32 0, i32 5
  call void @_ZNKSt8functionIFvN6nettle11SocketErrorEEEclES1_(ptr noundef nonnull align 8 dereferenceable(32) %42, i32 noundef 7)
  store i1 false, ptr %5, align 1
  store i32 1, ptr %10, align 4
  br label %45

43:                                               ; preds = %36
  %44 = getelementptr inbounds %"class.nettle::Socket", ptr %13, i32 0, i32 0
  store i8 1, ptr %44, align 8, !tbaa !11
  store i32 0, ptr %10, align 4
  br label %45

45:                                               ; preds = %43, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %46 = load i32, ptr %10, align 4
  switch i32 %46, label %53 [
    i32 0, label %47
    i32 1, label %51
  ]

47:                                               ; preds = %45
  br label %50

48:                                               ; preds = %4
  %49 = getelementptr inbounds %"class.nettle::Socket", ptr %13, i32 0, i32 5
  call void @_ZNKSt8functionIFvN6nettle11SocketErrorEEEclES1_(ptr noundef nonnull align 8 dereferenceable(32) %49, i32 noundef 3)
  store i1 false, ptr %5, align 1
  br label %51

50:                                               ; preds = %47
  store i1 true, ptr %5, align 1
  br label %51

51:                                               ; preds = %50, %48, %45, %34, %26
  %52 = load i1, ptr %5, align 1
  ret i1 %52

53:                                               ; preds = %45
  unreachable
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNKSt8functionIFvN6nettle11SocketErrorEEEclES1_(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) #0 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3

attributes #0 = { 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 #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTSN6nettle6SocketE", !13, i64 0, !10, i64 4, !14, i64 8, !17, i64 24, !17, i64 40, !19, i64 56}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTS11sockaddr_in", !15, i64 0, !15, i64 2, !16, i64 4, !7, i64 8}
!15 = !{!"short", !7, i64 0}
!16 = !{!"_ZTS7in_addr", !10, i64 0}
!17 = !{!"_ZTS7timeval", !18, i64 0, !18, i64 8}
!18 = !{!"long", !7, i64 0}
!19 = !{!"_ZTSSt8functionIFvN6nettle11SocketErrorEEE", !20, i64 0, !6, i64 24}
!20 = !{!"_ZTSSt14_Function_base", !7, i64 0, !6, i64 16}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!12, !10, i64 4}
!24 = !{i64 0, i64 2, !25, i64 2, i64 2, !25, i64 4, i64 4, !9, i64 8, i64 8, !26}
!25 = !{!15, !15, i64 0}
!26 = !{!7, !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"

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN6nettle6Socket11setupSocketEi11sockaddr_in(ptr noundef nonnull align 8 dereferenceable(88) %0, i32 noundef %1, i64 %2, i64 %3) local_unnamed_addr #0 align 2 {
  %5 = alloca i32, align 4
  %6 = load i8, ptr %0, align 8, !tbaa !5, !range !19, !noundef !20
  %7 = trunc nuw i8 %6 to i1
  br i1 %7, label %31, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %1, ptr %9, align 4, !tbaa !21
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %2, ptr %10, align 8
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %3, ptr %.sroa.2.0..sroa_idx, align 8, !tbaa !22
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  %12 = tail call i32 @setsockopt(i32 noundef %1, i32 noundef 1, i32 noundef 20, ptr noundef nonnull %11, i32 noundef 16) #3
  %13 = icmp slt i32 %12, 0
  br i1 %13, label %14, label %16

14:                                               ; preds = %8
  %15 = getelementptr inbounds i8, ptr %0, i64 56
  tail call void @_ZNKSt8functionIFvN6nettle11SocketErrorEEEclES1_(ptr noundef nonnull align 8 dereferenceable(32) %15, i32 noundef 0)
  br label %33

16:                                               ; preds = %8
  %17 = load i32, ptr %9, align 4, !tbaa !21
  %18 = getelementptr inbounds i8, ptr %0, i64 40
  %19 = tail call i32 @setsockopt(i32 noundef %17, i32 noundef 1, i32 noundef 21, ptr noundef nonnull %18, i32 noundef 16) #3
  %20 = icmp slt i32 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %16
  %22 = getelementptr inbounds i8, ptr %0, i64 56
  tail call void @_ZNKSt8functionIFvN6nettle11SocketErrorEEEclES1_(ptr noundef nonnull align 8 dereferenceable(32) %22, i32 noundef 1)
  br label %33

23:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  store i32 1, ptr %5, align 4, !tbaa !23
  %24 = load i32, ptr %9, align 4, !tbaa !21
  %25 = call i32 @setsockopt(i32 noundef %24, i32 noundef 1, i32 noundef 2, ptr noundef nonnull %5, i32 noundef 4) #3
  %26 = icmp sgt i32 %25, -1
  br i1 %26, label %29, label %27

27:                                               ; preds = %23
  %28 = getelementptr inbounds i8, ptr %0, i64 56
  call void @_ZNKSt8functionIFvN6nettle11SocketErrorEEEclES1_(ptr noundef nonnull align 8 dereferenceable(32) %28, i32 noundef 7)
  br label %30

29:                                               ; preds = %23
  store i8 1, ptr %0, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %29, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  br label %33

31:                                               ; preds = %4
  %32 = getelementptr inbounds i8, ptr %0, i64 56
  tail call void @_ZNKSt8functionIFvN6nettle11SocketErrorEEEclES1_(ptr noundef nonnull align 8 dereferenceable(32) %32, i32 noundef 3)
  br label %33

33:                                               ; preds = %30, %31, %21, %14
  %.1 = phi i1 [ false, %31 ], [ false, %14 ], [ false, %21 ], [ %26, %30 ]
  ret i1 %.1
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNKSt8functionIFvN6nettle11SocketErrorEEEclES1_(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

attributes #0 = { 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 #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !7, i64 0}
!6 = !{!"_ZTSN6nettle6SocketE", !7, i64 0, !10, i64 4, !11, i64 8, !14, i64 24, !14, i64 40, !16, i64 56}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTS11sockaddr_in", !12, i64 0, !12, i64 2, !13, i64 4, !8, i64 8}
!12 = !{!"short", !8, i64 0}
!13 = !{!"_ZTS7in_addr", !10, i64 0}
!14 = !{!"_ZTS7timeval", !15, i64 0, !15, i64 8}
!15 = !{!"long", !8, i64 0}
!16 = !{!"_ZTSSt8functionIFvN6nettle11SocketErrorEEE", !17, i64 0, !18, i64 24}
!17 = !{!"_ZTSSt14_Function_base", !8, i64 0, !18, i64 16}
!18 = !{!"any pointer", !8, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!6, !10, i64 4}
!22 = !{!8, !8, i64 0}
!23 = !{!10, !10, i64 0}


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