; 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.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.8 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [5 x i8], align 1
@__PRETTY_FUNCTION__.client_ip6 = external hidden unnamed_addr constant [25 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

declare void @sc_sock_init(ptr noundef, i32 noundef, i1 noundef zeroext, i32 noundef) #1

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

declare i32 @sc_sock_term(ptr noundef) #1

declare i32 @sc_sock_connect(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

declare i32 @sleep(i32 noundef) #1

declare i32 @sc_sock_send(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @client_ip6(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca %struct.sc_sock, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 148, ptr %4) #4
  call void @sc_sock_init(ptr noundef %4, i32 noundef 0, i1 noundef zeroext true, i32 noundef 10)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %19, %1
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 5
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  store i32 2, ptr %6, align 4
  br label %22

12:                                               ; preds = %8
  %13 = call i32 @sc_sock_connect(ptr noundef %4, ptr noundef @.str.23, ptr noundef @.str.24, ptr noundef null, ptr noundef null)
  store i32 %13, ptr %3, align 4, !tbaa !9
  %14 = load i32, ptr %3, align 4, !tbaa !9
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %12
  store i32 2, ptr %6, align 4
  br label %22

17:                                               ; preds = %12
  %18 = call i32 @sleep(i32 noundef 1)
  br label %19

19:                                               ; preds = %17
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %5, align 4, !tbaa !9
  br label %8, !llvm.loop !11

22:                                               ; preds = %16, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %23

23:                                               ; preds = %22
  %24 = load i32, ptr %3, align 4, !tbaa !9
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %23
  br label %28

27:                                               ; preds = %23
  call void @__assert_fail(ptr noundef @.str.15, ptr noundef @.str.3, i32 noundef 284, ptr noundef @__PRETTY_FUNCTION__.client_ip6) #5
  unreachable

28:                                               ; preds = %26
  %29 = call i32 @sc_sock_send(ptr noundef %4, ptr noundef @.str.8, i32 noundef 5, i32 noundef 0)
  %30 = icmp eq i32 %29, 5
  br i1 %30, label %31, label %32

31:                                               ; preds = %28
  br label %33

32:                                               ; preds = %28
  call void @__assert_fail(ptr noundef @.str.18, ptr noundef @.str.3, i32 noundef 285, ptr noundef @__PRETTY_FUNCTION__.client_ip6) #5
  unreachable

33:                                               ; preds = %31
  %34 = call i32 @sc_sock_term(ptr noundef %4)
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %33
  br label %38

37:                                               ; preds = %33
  call void @__assert_fail(ptr noundef @.str.10, ptr noundef @.str.3, i32 noundef 287, ptr noundef @__PRETTY_FUNCTION__.client_ip6) #5
  unreachable

38:                                               ; preds = %36
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 148, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret ptr null
}

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 = { 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 #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 }
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, !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; 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.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.8 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [5 x i8], align 1
@__PRETTY_FUNCTION__.client_ip6 = external hidden unnamed_addr constant [25 x i8], align 1

; 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 void @sc_sock_init(ptr noundef, i32 noundef, i1 noundef zeroext, i32 noundef) local_unnamed_addr #1

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

declare i32 @sc_sock_term(ptr noundef) local_unnamed_addr #1

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

declare i32 @sleep(i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @client_ip6(ptr nocapture noundef readnone %0) local_unnamed_addr #3 {
  %2 = alloca %struct.sc_sock, align 4
  call void @llvm.lifetime.start.p0(i64 148, ptr nonnull %2) #4
  call void @sc_sock_init(ptr noundef nonnull %2, i32 noundef 0, i1 noundef zeroext true, i32 noundef 10) #4
  %3 = call i32 @sc_sock_connect(ptr noundef nonnull %2, ptr noundef nonnull @.str.23, ptr noundef nonnull @.str.24, ptr noundef null, ptr noundef null) #4
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %22, label %5

5:                                                ; preds = %1
  %6 = call i32 @sleep(i32 noundef 1) #4
  %7 = call i32 @sc_sock_connect(ptr noundef nonnull %2, ptr noundef nonnull @.str.23, ptr noundef nonnull @.str.24, ptr noundef null, ptr noundef null) #4
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %22, label %9

9:                                                ; preds = %5
  %10 = call i32 @sleep(i32 noundef 1) #4
  %11 = call i32 @sc_sock_connect(ptr noundef nonnull %2, ptr noundef nonnull @.str.23, ptr noundef nonnull @.str.24, ptr noundef null, ptr noundef null) #4
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %22, label %13

13:                                               ; preds = %9
  %14 = call i32 @sleep(i32 noundef 1) #4
  %15 = call i32 @sc_sock_connect(ptr noundef nonnull %2, ptr noundef nonnull @.str.23, ptr noundef nonnull @.str.24, ptr noundef null, ptr noundef null) #4
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %22, label %17

17:                                               ; preds = %13
  %18 = call i32 @sleep(i32 noundef 1) #4
  %19 = call i32 @sc_sock_connect(ptr noundef nonnull %2, ptr noundef nonnull @.str.23, ptr noundef nonnull @.str.24, ptr noundef null, ptr noundef null) #4
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %22, label %.critedge

.critedge:                                        ; preds = %17
  %21 = call i32 @sleep(i32 noundef 1) #4
  call void @__assert_fail(ptr noundef nonnull @.str.15, ptr noundef nonnull @.str.3, i32 noundef 284, ptr noundef nonnull @__PRETTY_FUNCTION__.client_ip6) #5
  unreachable

22:                                               ; preds = %17, %13, %9, %5, %1
  %23 = call i32 @sc_sock_send(ptr noundef nonnull %2, ptr noundef nonnull @.str.8, i32 noundef 5, i32 noundef 0) #4
  %24 = icmp eq i32 %23, 5
  br i1 %24, label %26, label %25

25:                                               ; preds = %22
  call void @__assert_fail(ptr noundef nonnull @.str.18, ptr noundef nonnull @.str.3, i32 noundef 285, ptr noundef nonnull @__PRETTY_FUNCTION__.client_ip6) #5
  unreachable

26:                                               ; preds = %22
  %27 = call i32 @sc_sock_term(ptr noundef nonnull %2) #4
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  call void @__assert_fail(ptr noundef nonnull @.str.10, ptr noundef nonnull @.str.3, i32 noundef 287, ptr noundef nonnull @__PRETTY_FUNCTION__.client_ip6) #5
  unreachable

30:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 148, ptr nonnull %2) #4
  ret ptr null
}

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass