; LLVM IR from kala13x/libxutils :: examples (basic-server)

; 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.XSocket = type { i32, %union.xsock_addr_t, i32, i32, i16, i32, i32, i32, i32, ptr }
%union.xsock_addr_t = type { %struct.sockaddr_in, [96 x i8] }
%struct.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }

@.str = external hidden unnamed_addr constant [28 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca [1024 x i8], align 16
  %7 = alloca i32, align 4
  %8 = alloca %struct.XSocket, align 8
  %9 = alloca %struct.XSocket, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @XLog_Init(ptr noundef null, i16 noundef zeroext 203, i8 noundef zeroext 0)
  call void @llvm.lifetime.start.p0(i64 1024, ptr %6) #4
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = icmp sle i32 %12, 2
  br i1 %13, label %14, label %21

14:                                               ; preds = %2
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = getelementptr inbounds ptr, ptr %15, i64 0
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 1, i8 noundef zeroext 1, ptr noundef @.str, ptr noundef %17)
  %18 = load ptr, ptr %5, align 8, !tbaa !9
  %19 = getelementptr inbounds ptr, ptr %18, i64 0
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 1, i8 noundef zeroext 1, ptr noundef @.str.1, ptr noundef %20)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %74

21:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 152, ptr %8) #4
  %22 = load ptr, ptr %5, align 8, !tbaa !9
  %23 = getelementptr inbounds ptr, ptr %22, i64 1
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = load ptr, ptr %5, align 8, !tbaa !9
  %26 = getelementptr inbounds ptr, ptr %25, i64 2
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = call i32 @atoi(ptr noundef %27) #5
  %29 = trunc i32 %28 to i16
  %30 = call i32 @XSock_Create(ptr noundef %8, i32 noundef 1025, ptr noundef %24, i16 noundef zeroext %29)
  %31 = icmp eq i32 %30, -1
  br i1 %31, label %32, label %34

32:                                               ; preds = %21
  %33 = call ptr @XSock_ErrStr(ptr noundef %8)
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef @.str.2, ptr noundef %33)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %73

34:                                               ; preds = %21
  %35 = load ptr, ptr %5, align 8, !tbaa !9
  %36 = getelementptr inbounds ptr, ptr %35, i64 2
  %37 = load ptr, ptr %36, align 8, !tbaa !9
  %38 = call i32 @atoi(ptr noundef %37) #5
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 4, i8 noundef zeroext 1, ptr noundef @.str.3, i32 noundef %38)
  br label %39

39:                                               ; preds = %71, %69, %34
  %40 = getelementptr inbounds %struct.XSocket, ptr %8, i32 0, i32 5
  %41 = load i32, ptr %40, align 8, !tbaa !11
  %42 = icmp ne i32 %41, -1
  br i1 %42, label %43, label %72

43:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 152, ptr %9) #4
  %44 = getelementptr inbounds [1024 x i8], ptr %6, i64 0, i64 0
  store i8 0, ptr %44, align 16, !tbaa !14
  %45 = call i32 @XSock_Accept(ptr noundef %8, ptr noundef %9)
  %46 = icmp eq i32 %45, -1
  br i1 %46, label %47, label %49

47:                                               ; preds = %43
  %48 = call ptr @XSock_ErrStr(ptr noundef %8)
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef @.str.2, ptr noundef %48)
  store i32 2, ptr %7, align 4
  br label %69, !llvm.loop !15

49:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %50 = getelementptr inbounds [1024 x i8], ptr %6, i64 0, i64 0
  %51 = call i32 @XSock_Read(ptr noundef %9, ptr noundef %50, i64 noundef 1024)
  store i32 %51, ptr %10, align 4, !tbaa !5
  %52 = load i32, ptr %10, align 4, !tbaa !5
  %53 = icmp sgt i32 %52, 0
  br i1 %53, label %54, label %68

54:                                               ; preds = %49
  %55 = load i32, ptr %10, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1024 x i8], ptr %6, i64 0, i64 %56
  store i8 0, ptr %57, align 1, !tbaa !14
  %58 = getelementptr inbounds [1024 x i8], ptr %6, i64 0, i64 0
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 4, i8 noundef zeroext 1, ptr noundef @.str.4, ptr noundef %58)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %59 = getelementptr inbounds [1024 x i8], ptr %6, i64 0, i64 0
  %60 = load i32, ptr %10, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = call i32 @XSock_Send(ptr noundef %9, ptr noundef %59, i64 noundef %61)
  store i32 %62, ptr %11, align 4, !tbaa !5
  %63 = load i32, ptr %11, align 4, !tbaa !5
  %64 = icmp sge i32 %63, 0
  br i1 %64, label %65, label %67

65:                                               ; preds = %54
  %66 = getelementptr inbounds [1024 x i8], ptr %6, i64 0, i64 0
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 4, i8 noundef zeroext 1, ptr noundef @.str.5, ptr noundef %66)
  br label %67

67:                                               ; preds = %65, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %68

68:                                               ; preds = %67, %49
  call void @XSock_Close(ptr noundef %9)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  store i32 0, ptr %7, align 4
  br label %69

69:                                               ; preds = %68, %47
  call void @llvm.lifetime.end.p0(i64 152, ptr %9) #4
  %70 = load i32, ptr %7, align 4
  switch i32 %70, label %76 [
    i32 0, label %71
    i32 2, label %39
  ]

71:                                               ; preds = %69
  br label %39, !llvm.loop !15

72:                                               ; preds = %39
  call void @XSock_Close(ptr noundef %8)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %73

73:                                               ; preds = %72, %32
  call void @llvm.lifetime.end.p0(i64 152, ptr %8) #4
  br label %74

74:                                               ; preds = %73, %14
  call void @llvm.lifetime.end.p0(i64 1024, ptr %6) #4
  %75 = load i32, ptr %3, align 4
  ret i32 %75

76:                                               ; preds = %69
  unreachable
}

declare void @XLog_Init(ptr noundef, i16 noundef zeroext, i8 noundef zeroext) #1

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

declare void @XLog_Display(i32 noundef, i8 noundef zeroext, ptr noundef, ...) #1

declare i32 @XSock_Create(ptr noundef, i32 noundef, ptr noundef, i16 noundef zeroext) #1

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr noundef nonnull) #3

declare ptr @XSock_ErrStr(ptr noundef) #1

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

declare i32 @XSock_Read(ptr noundef, ptr noundef, i64 noundef) #1

declare i32 @XSock_Send(ptr noundef, ptr noundef, i64 noundef) #1

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

declare void @XSock_Close(ptr noundef) #1

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

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 128}
!12 = !{!"XSocket", !6, i64 0, !7, i64 4, !6, i64 116, !6, i64 120, !13, i64 124, !6, i64 128, !6, i64 132, !6, i64 136, !6, i64 140, !10, i64 144}
!13 = !{!"short", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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.XSocket = type { i32, %union.xsock_addr_t, i32, i32, i16, i32, i32, i32, i32, ptr }
%union.xsock_addr_t = type { %struct.sockaddr_in, [96 x i8] }
%struct.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }

@.str = external hidden unnamed_addr constant [28 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca [1024 x i8], align 16
  %4 = alloca %struct.XSocket, align 8
  %5 = alloca %struct.XSocket, align 8
  tail call void @XLog_Init(ptr noundef null, i16 noundef zeroext 203, i8 noundef zeroext 0) #4
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %3) #4
  %6 = icmp slt i32 %0, 3
  br i1 %6, label %7, label %10

7:                                                ; preds = %2
  %8 = load ptr, ptr %1, align 8, !tbaa !5
  tail call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 1, i8 noundef zeroext 1, ptr noundef nonnull @.str, ptr noundef %8) #4
  %9 = load ptr, ptr %1, align 8, !tbaa !5
  tail call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 1, i8 noundef zeroext 1, ptr noundef nonnull @.str.1, ptr noundef %9) #4
  br label %43

10:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 152, ptr nonnull %4) #4
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %1, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = tail call i32 @atoi(ptr nocapture noundef %14) #5
  %16 = trunc i32 %15 to i16
  %17 = call i32 @XSock_Create(ptr noundef nonnull %4, i32 noundef 1025, ptr noundef %12, i16 noundef zeroext %16) #4
  %18 = icmp eq i32 %17, -1
  br i1 %18, label %19, label %21

19:                                               ; preds = %10
  %20 = call ptr @XSock_ErrStr(ptr noundef nonnull %4) #4
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef nonnull @.str.2, ptr noundef %20) #4
  br label %42

21:                                               ; preds = %10
  %22 = load ptr, ptr %13, align 8, !tbaa !5
  %23 = call i32 @atoi(ptr nocapture noundef %22) #5
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 4, i8 noundef zeroext 1, ptr noundef nonnull @.str.3, i32 noundef %23) #4
  %24 = getelementptr inbounds i8, ptr %4, i64 128
  %25 = load i32, ptr %24, align 8, !tbaa !9
  %.not11 = icmp eq i32 %25, -1
  br i1 %.not11, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %21, %40
  call void @llvm.lifetime.start.p0(i64 152, ptr nonnull %5) #4
  store i8 0, ptr %3, align 16, !tbaa !13
  %26 = call i32 @XSock_Accept(ptr noundef nonnull %4, ptr noundef nonnull %5) #4
  %27 = icmp eq i32 %26, -1
  br i1 %27, label %28, label %30

28:                                               ; preds = %.lr.ph
  %29 = call ptr @XSock_ErrStr(ptr noundef nonnull %4) #4
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef nonnull @.str.2, ptr noundef %29) #4
  br label %40, !llvm.loop !14

30:                                               ; preds = %.lr.ph
  %31 = call i32 @XSock_Read(ptr noundef nonnull %5, ptr noundef nonnull %3, i64 noundef 1024) #4
  %32 = icmp sgt i32 %31, 0
  br i1 %32, label %33, label %39

33:                                               ; preds = %30
  %34 = zext nneg i32 %31 to i64
  %35 = getelementptr inbounds [1024 x i8], ptr %3, i64 0, i64 %34
  store i8 0, ptr %35, align 1, !tbaa !13
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 4, i8 noundef zeroext 1, ptr noundef nonnull @.str.4, ptr noundef nonnull %3) #4
  %36 = call i32 @XSock_Send(ptr noundef nonnull %5, ptr noundef nonnull %3, i64 noundef %34) #4
  %37 = icmp sgt i32 %36, -1
  br i1 %37, label %38, label %39

38:                                               ; preds = %33
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 4, i8 noundef zeroext 1, ptr noundef nonnull @.str.5, ptr noundef nonnull %3) #4
  br label %39

39:                                               ; preds = %33, %38, %30
  call void @XSock_Close(ptr noundef nonnull %5) #4
  br label %40

40:                                               ; preds = %39, %28
  call void @llvm.lifetime.end.p0(i64 152, ptr nonnull %5) #4
  %41 = load i32, ptr %24, align 8, !tbaa !9
  %.not = icmp eq i32 %41, -1
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %40, %21
  call void @XSock_Close(ptr noundef nonnull %4) #4
  br label %42

42:                                               ; preds = %._crit_edge, %19
  %.0 = phi i32 [ 1, %19 ], [ 0, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 152, ptr nonnull %4) #4
  br label %43

43:                                               ; preds = %42, %7
  %.1 = phi i32 [ 1, %7 ], [ %.0, %42 ]
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %3) #4
  ret i32 %.1
}

declare void @XLog_Init(ptr noundef, i16 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #1

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

declare void @XLog_Display(i32 noundef, i8 noundef zeroext, ptr noundef, ...) local_unnamed_addr #1

declare i32 @XSock_Create(ptr noundef, i32 noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr nocapture noundef nonnull) local_unnamed_addr #3

declare ptr @XSock_ErrStr(ptr noundef) local_unnamed_addr #1

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

declare i32 @XSock_Read(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare i32 @XSock_Send(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

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

declare void @XSock_Close(ptr noundef) local_unnamed_addr #1

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

!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, !11, i64 128}
!10 = !{!"XSocket", !11, i64 0, !7, i64 4, !11, i64 116, !11, i64 120, !12, i64 124, !11, i64 128, !11, i64 132, !11, i64 136, !11, i64 140, !6, i64 144}
!11 = !{!"int", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass