; 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 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.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.12 = external hidden unnamed_addr constant [40 x i8], align 1
@__PRETTY_FUNCTION__.client_ip4 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [39 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 void @sc_sock_print(ptr noundef, ptr noundef, i64 noundef) #1

declare i32 @sc_sock_term(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @client_ip4(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca [128 x i8], align 16
  %5 = alloca %struct.sc_sock, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %8 = 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 128, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 148, ptr %5) #4
  call void @sc_sock_init(ptr noundef %5, i32 noundef 0, i1 noundef zeroext true, i32 noundef 2)
  %9 = call i32 @sc_sock_set_sndtimeo(ptr noundef %5, i32 noundef 10000)
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  br label %13

12:                                               ; preds = %1
  call void @__assert_fail(ptr noundef @.str.12, ptr noundef @.str.3, i32 noundef 208, ptr noundef @__PRETTY_FUNCTION__.client_ip4) #5
  unreachable

13:                                               ; preds = %11
  %14 = call ptr @sc_sock_error(ptr noundef %5)
  %15 = call i32 (ptr, ...) @printf(ptr noundef @.str.13, ptr noundef %14)
  %16 = call i32 @sc_sock_set_rcvtimeo(ptr noundef %5, i32 noundef 10000)
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %13
  br label %20

19:                                               ; preds = %13
  call void @__assert_fail(ptr noundef @.str.14, ptr noundef @.str.3, i32 noundef 210, ptr noundef @__PRETTY_FUNCTION__.client_ip4) #5
  unreachable

20:                                               ; preds = %18
  %21 = call ptr @sc_sock_error(ptr noundef %5)
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.13, ptr noundef %21)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %34, %20
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = icmp slt i32 %24, 5
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  store i32 2, ptr %7, align 4
  br label %37

27:                                               ; preds = %23
  %28 = call i32 @sc_sock_connect(ptr noundef %5, ptr noundef @.str, ptr noundef @.str.1, ptr noundef null, ptr noundef null)
  store i32 %28, ptr %3, align 4, !tbaa !9
  %29 = load i32, ptr %3, align 4, !tbaa !9
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %27
  store i32 2, ptr %7, align 4
  br label %37

32:                                               ; preds = %27
  %33 = call i32 @sleep(i32 noundef 1)
  br label %34

34:                                               ; preds = %32
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %6, align 4, !tbaa !9
  br label %23, !llvm.loop !11

37:                                               ; preds = %31, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %3, align 4, !tbaa !9
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %38
  br label %43

42:                                               ; preds = %38
  call void @__assert_fail(ptr noundef @.str.15, ptr noundef @.str.3, i32 noundef 222, ptr noundef @__PRETTY_FUNCTION__.client_ip4) #5
  unreachable

43:                                               ; preds = %41
  %44 = getelementptr inbounds [128 x i8], ptr %4, i64 0, i64 0
  call void @sc_sock_print(ptr noundef %5, ptr noundef %44, i64 noundef 128)
  %45 = call i32 @sc_sock_set_sndtimeo(ptr noundef %5, i32 noundef 10000)
  %46 = icmp eq i32 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %43
  br label %49

48:                                               ; preds = %43
  call void @__assert_fail(ptr noundef @.str.16, ptr noundef @.str.3, i32 noundef 224, ptr noundef @__PRETTY_FUNCTION__.client_ip4) #5
  unreachable

49:                                               ; preds = %47
  %50 = call i32 @sc_sock_set_rcvtimeo(ptr noundef %5, i32 noundef 10000)
  %51 = icmp eq i32 %50, 0
  br i1 %51, label %52, label %53

52:                                               ; preds = %49
  br label %54

53:                                               ; preds = %49
  call void @__assert_fail(ptr noundef @.str.17, ptr noundef @.str.3, i32 noundef 225, ptr noundef @__PRETTY_FUNCTION__.client_ip4) #5
  unreachable

54:                                               ; preds = %52
  %55 = call i32 @sc_sock_send(ptr noundef %5, ptr noundef @.str.8, i32 noundef 5, i32 noundef 0)
  %56 = icmp eq i32 %55, 5
  br i1 %56, label %57, label %58

57:                                               ; preds = %54
  br label %59

58:                                               ; preds = %54
  call void @__assert_fail(ptr noundef @.str.18, ptr noundef @.str.3, i32 noundef 226, ptr noundef @__PRETTY_FUNCTION__.client_ip4) #5
  unreachable

59:                                               ; preds = %57
  %60 = call i32 @sc_sock_term(ptr noundef %5)
  %61 = icmp eq i32 %60, 0
  br i1 %61, label %62, label %63

62:                                               ; preds = %59
  br label %64

63:                                               ; preds = %59
  call void @__assert_fail(ptr noundef @.str.10, ptr noundef @.str.3, i32 noundef 227, ptr noundef @__PRETTY_FUNCTION__.client_ip4) #5
  unreachable

64:                                               ; preds = %62
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 148, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 128, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret ptr null
}

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

declare i32 @printf(ptr noundef, ...) #1

declare ptr @sc_sock_error(ptr noundef) #1

declare i32 @sc_sock_set_rcvtimeo(ptr noundef, i32 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

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 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.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.12 = external hidden unnamed_addr constant [40 x i8], align 1
@__PRETTY_FUNCTION__.client_ip4 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [39 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 void @sc_sock_print(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare i32 @sc_sock_term(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @client_ip4(ptr nocapture noundef readnone %0) local_unnamed_addr #3 {
  %2 = alloca [128 x i8], align 16
  %3 = alloca %struct.sc_sock, align 4
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 148, ptr nonnull %3) #5
  call void @sc_sock_init(ptr noundef nonnull %3, i32 noundef 0, i1 noundef zeroext true, i32 noundef 2) #5
  %4 = call i32 @sc_sock_set_sndtimeo(ptr noundef nonnull %3, i32 noundef 10000) #5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %5, label %6

5:                                                ; preds = %1
  call void @__assert_fail(ptr noundef nonnull @.str.12, ptr noundef nonnull @.str.3, i32 noundef 208, ptr noundef nonnull @__PRETTY_FUNCTION__.client_ip4) #6
  unreachable

6:                                                ; preds = %1
  %7 = call ptr @sc_sock_error(ptr noundef nonnull %3) #5
  %8 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13, ptr noundef %7)
  %9 = call i32 @sc_sock_set_rcvtimeo(ptr noundef nonnull %3, i32 noundef 10000) #5
  %.not7 = icmp eq i32 %9, 0
  br i1 %.not7, label %10, label %11

10:                                               ; preds = %6
  call void @__assert_fail(ptr noundef nonnull @.str.14, ptr noundef nonnull @.str.3, i32 noundef 210, ptr noundef nonnull @__PRETTY_FUNCTION__.client_ip4) #6
  unreachable

11:                                               ; preds = %6
  %12 = call ptr @sc_sock_error(ptr noundef nonnull %3) #5
  %13 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13, ptr noundef %12)
  %14 = call i32 @sc_sock_connect(ptr noundef nonnull %3, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef null, ptr noundef null) #5
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %33, label %16

16:                                               ; preds = %11
  %17 = call i32 @sleep(i32 noundef 1) #5
  %18 = call i32 @sc_sock_connect(ptr noundef nonnull %3, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef null, ptr noundef null) #5
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %33, label %20

20:                                               ; preds = %16
  %21 = call i32 @sleep(i32 noundef 1) #5
  %22 = call i32 @sc_sock_connect(ptr noundef nonnull %3, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef null, ptr noundef null) #5
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %33, label %24

24:                                               ; preds = %20
  %25 = call i32 @sleep(i32 noundef 1) #5
  %26 = call i32 @sc_sock_connect(ptr noundef nonnull %3, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef null, ptr noundef null) #5
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %33, label %28

28:                                               ; preds = %24
  %29 = call i32 @sleep(i32 noundef 1) #5
  %30 = call i32 @sc_sock_connect(ptr noundef nonnull %3, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef null, ptr noundef null) #5
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %33, label %.critedge

.critedge:                                        ; preds = %28
  %32 = call i32 @sleep(i32 noundef 1) #5
  call void @__assert_fail(ptr noundef nonnull @.str.15, ptr noundef nonnull @.str.3, i32 noundef 222, ptr noundef nonnull @__PRETTY_FUNCTION__.client_ip4) #6
  unreachable

33:                                               ; preds = %28, %24, %20, %16, %11
  call void @sc_sock_print(ptr noundef nonnull %3, ptr noundef nonnull %2, i64 noundef 128) #5
  %34 = call i32 @sc_sock_set_sndtimeo(ptr noundef nonnull %3, i32 noundef 10000) #5
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %37, label %36

36:                                               ; preds = %33
  call void @__assert_fail(ptr noundef nonnull @.str.16, ptr noundef nonnull @.str.3, i32 noundef 224, ptr noundef nonnull @__PRETTY_FUNCTION__.client_ip4) #6
  unreachable

37:                                               ; preds = %33
  %38 = call i32 @sc_sock_set_rcvtimeo(ptr noundef nonnull %3, i32 noundef 10000) #5
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %41, label %40

40:                                               ; preds = %37
  call void @__assert_fail(ptr noundef nonnull @.str.17, ptr noundef nonnull @.str.3, i32 noundef 225, ptr noundef nonnull @__PRETTY_FUNCTION__.client_ip4) #6
  unreachable

41:                                               ; preds = %37
  %42 = call i32 @sc_sock_send(ptr noundef nonnull %3, ptr noundef nonnull @.str.8, i32 noundef 5, i32 noundef 0) #5
  %43 = icmp eq i32 %42, 5
  br i1 %43, label %45, label %44

44:                                               ; preds = %41
  call void @__assert_fail(ptr noundef nonnull @.str.18, ptr noundef nonnull @.str.3, i32 noundef 226, ptr noundef nonnull @__PRETTY_FUNCTION__.client_ip4) #6
  unreachable

45:                                               ; preds = %41
  %46 = call i32 @sc_sock_term(ptr noundef nonnull %3) #5
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %49, label %48

48:                                               ; preds = %45
  call void @__assert_fail(ptr noundef nonnull @.str.10, ptr noundef nonnull @.str.3, i32 noundef 227, ptr noundef nonnull @__PRETTY_FUNCTION__.client_ip4) #6
  unreachable

49:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 148, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %2) #5
  ret ptr null
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #4

declare ptr @sc_sock_error(ptr noundef) local_unnamed_addr #1

declare i32 @sc_sock_set_rcvtimeo(ptr noundef, i32 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

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 = { nofree 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 #5 = { nounwind }
attributes #6 = { 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