; 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.3 = external hidden unnamed_addr constant [60 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.83 = external hidden unnamed_addr constant [6 x i8], align 1
@__PRETTY_FUNCTION__.client = external hidden unnamed_addr constant [21 x i8], align 1
@.str.92 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.93 = external hidden unnamed_addr constant [8 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(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
  %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 148, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %9

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

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

13:                                               ; preds = %9
  call void @sc_sock_init(ptr noundef %4, i32 noundef 0, i1 noundef zeroext true, i32 noundef 2)
  %14 = call i32 @sc_sock_connect(ptr noundef %4, ptr noundef @.str, ptr noundef @.str.83, ptr noundef null, ptr noundef null)
  store i32 %14, ptr %3, align 4, !tbaa !9
  %15 = load i32, ptr %3, align 4, !tbaa !9
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %24

17:                                               ; preds = %13
  %18 = call i32 @sc_sock_term(ptr noundef %4)
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  br label %22

21:                                               ; preds = %17
  call void @__assert_fail(ptr noundef @.str.10, ptr noundef @.str.3, i32 noundef 1399, ptr noundef @__PRETTY_FUNCTION__.client) #5
  unreachable

22:                                               ; preds = %20
  %23 = call i32 @sleep(i32 noundef 1)
  br label %46

24:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %36, %24
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = icmp slt i32 %26, 10000
  br i1 %27, label %29, label %28

28:                                               ; preds = %25
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %39

29:                                               ; preds = %25
  %30 = call i32 @sc_sock_send(ptr noundef %4, ptr noundef @.str.92, i32 noundef 1, i32 noundef 0)
  store i32 %30, ptr %3, align 4, !tbaa !9
  %31 = load i32, ptr %3, align 4, !tbaa !9
  %32 = icmp eq i32 %31, 1
  br i1 %32, label %33, label %34

33:                                               ; preds = %29
  br label %35

34:                                               ; preds = %29
  call void @__assert_fail(ptr noundef @.str.93, ptr noundef @.str.3, i32 noundef 1406, ptr noundef @__PRETTY_FUNCTION__.client) #5
  unreachable

35:                                               ; preds = %33
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %7, align 4, !tbaa !9
  br label %25, !llvm.loop !11

39:                                               ; preds = %28
  %40 = call i32 @sc_sock_term(ptr noundef %4)
  store i32 %40, ptr %3, align 4, !tbaa !9
  %41 = load i32, ptr %3, align 4, !tbaa !9
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %44

43:                                               ; preds = %39
  br label %45

44:                                               ; preds = %39
  call void @__assert_fail(ptr noundef @.str.15, ptr noundef @.str.3, i32 noundef 1410, ptr noundef @__PRETTY_FUNCTION__.client) #5
  unreachable

45:                                               ; preds = %43
  store i32 2, ptr %6, align 4
  br label %49

46:                                               ; preds = %22
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %5, align 4, !tbaa !9
  br label %9, !llvm.loop !13

49:                                               ; preds = %45, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %50

50:                                               ; preds = %49
  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"}
!13 = distinct !{!13, !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"

%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.3 = external hidden unnamed_addr constant [60 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.83 = external hidden unnamed_addr constant [6 x i8], align 1
@__PRETTY_FUNCTION__.client = external hidden unnamed_addr constant [21 x i8], align 1
@.str.92 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.93 = external hidden unnamed_addr constant [8 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(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 2) #4
  %3 = call i32 @sc_sock_connect(ptr noundef nonnull %2, ptr noundef nonnull @.str, ptr noundef nonnull @.str.83, ptr noundef null, ptr noundef null) #4
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %.preheader.preheader, label %4

.preheader.preheader:                             ; preds = %56, %50, %44, %38, %32, %26, %20, %14, %8, %1
  br label %.preheader

4:                                                ; preds = %1
  %5 = call i32 @sc_sock_term(ptr noundef nonnull %2) #4
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %8, label %7

7:                                                ; preds = %59, %53, %47, %41, %35, %29, %23, %17, %11, %4
  call void @__assert_fail(ptr noundef nonnull @.str.10, ptr noundef nonnull @.str.3, i32 noundef 1399, ptr noundef nonnull @__PRETTY_FUNCTION__.client) #5
  unreachable

8:                                                ; preds = %4
  %9 = call i32 @sleep(i32 noundef 1) #4
  call void @sc_sock_init(ptr noundef nonnull %2, i32 noundef 0, i1 noundef zeroext true, i32 noundef 2) #4
  %10 = call i32 @sc_sock_connect(ptr noundef nonnull %2, ptr noundef nonnull @.str, ptr noundef nonnull @.str.83, ptr noundef null, ptr noundef null) #4
  %.not.1 = icmp eq i32 %10, 0
  br i1 %.not.1, label %.preheader.preheader, label %11

11:                                               ; preds = %8
  %12 = call i32 @sc_sock_term(ptr noundef nonnull %2) #4
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %7

14:                                               ; preds = %11
  %15 = call i32 @sleep(i32 noundef 1) #4
  call void @sc_sock_init(ptr noundef nonnull %2, i32 noundef 0, i1 noundef zeroext true, i32 noundef 2) #4
  %16 = call i32 @sc_sock_connect(ptr noundef nonnull %2, ptr noundef nonnull @.str, ptr noundef nonnull @.str.83, ptr noundef null, ptr noundef null) #4
  %.not.2 = icmp eq i32 %16, 0
  br i1 %.not.2, label %.preheader.preheader, label %17

17:                                               ; preds = %14
  %18 = call i32 @sc_sock_term(ptr noundef nonnull %2) #4
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %7

20:                                               ; preds = %17
  %21 = call i32 @sleep(i32 noundef 1) #4
  call void @sc_sock_init(ptr noundef nonnull %2, i32 noundef 0, i1 noundef zeroext true, i32 noundef 2) #4
  %22 = call i32 @sc_sock_connect(ptr noundef nonnull %2, ptr noundef nonnull @.str, ptr noundef nonnull @.str.83, ptr noundef null, ptr noundef null) #4
  %.not.3 = icmp eq i32 %22, 0
  br i1 %.not.3, label %.preheader.preheader, label %23

23:                                               ; preds = %20
  %24 = call i32 @sc_sock_term(ptr noundef nonnull %2) #4
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %7

26:                                               ; preds = %23
  %27 = call i32 @sleep(i32 noundef 1) #4
  call void @sc_sock_init(ptr noundef nonnull %2, i32 noundef 0, i1 noundef zeroext true, i32 noundef 2) #4
  %28 = call i32 @sc_sock_connect(ptr noundef nonnull %2, ptr noundef nonnull @.str, ptr noundef nonnull @.str.83, ptr noundef null, ptr noundef null) #4
  %.not.4 = icmp eq i32 %28, 0
  br i1 %.not.4, label %.preheader.preheader, label %29

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

32:                                               ; preds = %29
  %33 = call i32 @sleep(i32 noundef 1) #4
  call void @sc_sock_init(ptr noundef nonnull %2, i32 noundef 0, i1 noundef zeroext true, i32 noundef 2) #4
  %34 = call i32 @sc_sock_connect(ptr noundef nonnull %2, ptr noundef nonnull @.str, ptr noundef nonnull @.str.83, ptr noundef null, ptr noundef null) #4
  %.not.5 = icmp eq i32 %34, 0
  br i1 %.not.5, label %.preheader.preheader, label %35

35:                                               ; preds = %32
  %36 = call i32 @sc_sock_term(ptr noundef nonnull %2) #4
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %7

38:                                               ; preds = %35
  %39 = call i32 @sleep(i32 noundef 1) #4
  call void @sc_sock_init(ptr noundef nonnull %2, i32 noundef 0, i1 noundef zeroext true, i32 noundef 2) #4
  %40 = call i32 @sc_sock_connect(ptr noundef nonnull %2, ptr noundef nonnull @.str, ptr noundef nonnull @.str.83, ptr noundef null, ptr noundef null) #4
  %.not.6 = icmp eq i32 %40, 0
  br i1 %.not.6, label %.preheader.preheader, label %41

41:                                               ; preds = %38
  %42 = call i32 @sc_sock_term(ptr noundef nonnull %2) #4
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %44, label %7

44:                                               ; preds = %41
  %45 = call i32 @sleep(i32 noundef 1) #4
  call void @sc_sock_init(ptr noundef nonnull %2, i32 noundef 0, i1 noundef zeroext true, i32 noundef 2) #4
  %46 = call i32 @sc_sock_connect(ptr noundef nonnull %2, ptr noundef nonnull @.str, ptr noundef nonnull @.str.83, ptr noundef null, ptr noundef null) #4
  %.not.7 = icmp eq i32 %46, 0
  br i1 %.not.7, label %.preheader.preheader, label %47

47:                                               ; preds = %44
  %48 = call i32 @sc_sock_term(ptr noundef nonnull %2) #4
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %50, label %7

50:                                               ; preds = %47
  %51 = call i32 @sleep(i32 noundef 1) #4
  call void @sc_sock_init(ptr noundef nonnull %2, i32 noundef 0, i1 noundef zeroext true, i32 noundef 2) #4
  %52 = call i32 @sc_sock_connect(ptr noundef nonnull %2, ptr noundef nonnull @.str, ptr noundef nonnull @.str.83, ptr noundef null, ptr noundef null) #4
  %.not.8 = icmp eq i32 %52, 0
  br i1 %.not.8, label %.preheader.preheader, label %53

53:                                               ; preds = %50
  %54 = call i32 @sc_sock_term(ptr noundef nonnull %2) #4
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %7

56:                                               ; preds = %53
  %57 = call i32 @sleep(i32 noundef 1) #4
  call void @sc_sock_init(ptr noundef nonnull %2, i32 noundef 0, i1 noundef zeroext true, i32 noundef 2) #4
  %58 = call i32 @sc_sock_connect(ptr noundef nonnull %2, ptr noundef nonnull @.str, ptr noundef nonnull @.str.83, ptr noundef null, ptr noundef null) #4
  %.not.9 = icmp eq i32 %58, 0
  br i1 %.not.9, label %.preheader.preheader, label %59

59:                                               ; preds = %56
  %60 = call i32 @sc_sock_term(ptr noundef nonnull %2) #4
  %61 = icmp eq i32 %60, 0
  br i1 %61, label %.loopexit.loopexit, label %7

.loopexit.loopexit:                               ; preds = %59
  %62 = call i32 @sleep(i32 noundef 1) #4
  br label %.loopexit

63:                                               ; preds = %.preheader
  %64 = add nuw nsw i32 %.09, 1
  %exitcond.not = icmp eq i32 %64, 10000
  br i1 %exitcond.not, label %65, label %.preheader, !llvm.loop !5

65:                                               ; preds = %63
  %66 = call i32 @sc_sock_term(ptr noundef nonnull %2) #4
  %67 = icmp eq i32 %66, 0
  br i1 %67, label %.loopexit, label %71

.preheader:                                       ; preds = %.preheader.preheader, %63
  %.09 = phi i32 [ %64, %63 ], [ 0, %.preheader.preheader ]
  %68 = call i32 @sc_sock_send(ptr noundef nonnull %2, ptr noundef nonnull @.str.92, i32 noundef 1, i32 noundef 0) #4
  %69 = icmp eq i32 %68, 1
  br i1 %69, label %63, label %70

70:                                               ; preds = %.preheader
  call void @__assert_fail(ptr noundef nonnull @.str.93, ptr noundef nonnull @.str.3, i32 noundef 1406, ptr noundef nonnull @__PRETTY_FUNCTION__.client) #5
  unreachable

71:                                               ; preds = %65
  call void @__assert_fail(ptr noundef nonnull @.str.15, ptr noundef nonnull @.str.3, i32 noundef 1410, ptr noundef nonnull @__PRETTY_FUNCTION__.client) #5
  unreachable

.loopexit:                                        ; preds = %.loopexit.loopexit, %65
  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)"}
!5 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass