; LLVM IR from jingweizhanghuai/Morn :: test (test_UDP)

; 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"

@IP = external dso_local global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @test_send() #0 {
  %1 = alloca [32 x i8], align 16
  %2 = alloca [64 x i8], align 16
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr %1) #5
  %5 = load ptr, ptr @IP, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 0
  %7 = load i8, ptr %6, align 1, !tbaa !9
  %8 = sext i8 %7 to i32
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %0
  store ptr @.str.1, ptr @IP, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %10, %0
  call void @llvm.lifetime.start.p0(i64 64, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !10
  br label %12

12:                                               ; preds = %34, %11
  %13 = load i32, ptr %3, align 4, !tbaa !10
  %14 = icmp slt i32 %13, 100
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %12
  %17 = getelementptr inbounds [64 x i8], ptr %2, i64 0, i64 0
  %18 = call i32 @m_RandString(ptr noundef %17, i32 noundef 32, i32 noundef 64)
  %19 = getelementptr inbounds [32 x i8], ptr %1, i64 0, i64 0
  %20 = load ptr, ptr @IP, align 8, !tbaa !5
  %21 = call i32 @rand() #5
  %22 = srem i32 %21, 4
  %23 = add nsw i32 %22, 1000
  %24 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %19, ptr noundef @.str.2, ptr noundef %20, i32 noundef %23) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %25 = getelementptr inbounds [32 x i8], ptr %1, i64 0, i64 0
  %26 = getelementptr inbounds [64 x i8], ptr %2, i64 0, i64 0
  %27 = call ptr @mUDPWrite(ptr noundef %25, ptr noundef %26, i32 noundef -1)
  store ptr %27, ptr %4, align 8, !tbaa !5
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds [64 x i8], ptr %2, i64 0, i64 0
  %30 = call i64 @strlen(ptr noundef %29) #6
  %31 = getelementptr inbounds [64 x i8], ptr %2, i64 0, i64 0
  %32 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, ptr noundef %28, i64 noundef %30, ptr noundef %31)
  %33 = call i32 @usleep(i32 noundef 10000)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %34

34:                                               ; preds = %16
  %35 = load i32, ptr %3, align 4, !tbaa !10
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %3, align 4, !tbaa !10
  br label %12, !llvm.loop !12

37:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 64, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %1) #5
  ret void
}

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

declare i32 @m_RandString(ptr noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #3

; Function Attrs: nounwind
declare i32 @rand() #3

declare ptr @mUDPWrite(ptr noundef, ptr noundef, i32 noundef) #2

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

declare i32 @usleep(i32 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 "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 willreturn memory(read) "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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@IP = external dso_local local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @test_send() local_unnamed_addr #0 {
  %1 = alloca [32 x i8], align 16
  %2 = alloca [64 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %1) #6
  %3 = load ptr, ptr @IP, align 8, !tbaa !5
  %4 = load i8, ptr %3, align 1, !tbaa !9
  %5 = icmp eq i8 %4, 0
  br i1 %5, label %6, label %7

6:                                                ; preds = %0
  store ptr @.str.1, ptr @IP, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %6, %0
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %2) #6
  br label %9

8:                                                ; preds = %9
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %1) #6
  ret void

9:                                                ; preds = %7, %9
  %.02 = phi i32 [ 0, %7 ], [ %20, %9 ]
  %10 = call i32 @m_RandString(ptr noundef nonnull %2, i32 noundef 32, i32 noundef 64) #6
  %11 = load ptr, ptr @IP, align 8, !tbaa !5
  %12 = call i32 @rand() #6
  %13 = srem i32 %12, 4
  %14 = add nsw i32 %13, 1000
  %15 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef %11, i32 noundef %14) #6
  %16 = call ptr @mUDPWrite(ptr noundef nonnull %1, ptr noundef nonnull %2, i32 noundef -1) #6
  %17 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #7
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef %16, i64 noundef %17, ptr noundef nonnull %2)
  %19 = call i32 @usleep(i32 noundef 10000) #6
  %20 = add nuw nsw i32 %.02, 1
  %exitcond.not = icmp eq i32 %20, 100
  br i1 %exitcond.not, label %8, label %9, !llvm.loop !10
}

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

declare i32 @m_RandString(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #4

declare ptr @mUDPWrite(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #5

declare i32 @usleep(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { 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 #4 = { 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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 #6 = { nounwind }
attributes #7 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass