; LLVM IR from thomasfla/Linux-ESPNOW :: wifiRawSender (main)

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

@.str.4 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [16 x i8], align 1
@stdout = external global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [47 x i8], align 1
@__const.main.data = external hidden unnamed_addr constant [331 x i8], align 16
@.str.7 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [28 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @create_raw_socket(ptr noundef) #0

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca [331 x i8], align 16
  %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 @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %12 = load ptr, ptr %5, align 8, !tbaa !9
  %13 = getelementptr inbounds ptr, ptr %12, i64 1
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %14, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 -1, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 -1, ptr %8, align 4, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !9
  %16 = call i32 @create_raw_socket(ptr noundef %15)
  store i32 %16, ptr %7, align 4, !tbaa !5
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = icmp eq i32 -1, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %2
  call void @perror(ptr noundef @.str.4)
  br label %56

20:                                               ; preds = %2
  %21 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  %22 = load ptr, ptr @stdout, align 8, !tbaa !9
  %23 = call i32 @fflush(ptr noundef %22)
  %24 = call i32 @sleep(i32 noundef 1)
  %25 = load ptr, ptr %6, align 8, !tbaa !9
  %26 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, ptr noundef %25)
  br label %27

27:                                               ; preds = %55, %20
  br label %28

28:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 331, ptr %9) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %9, ptr align 16 @__const.main.data, i64 331, i1 false)
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = getelementptr inbounds [331 x i8], ptr %9, i64 0, i64 0
  %31 = call i64 @sendto(i32 noundef %29, ptr noundef %30, i64 noundef 331, i32 noundef 0, ptr noundef null, i32 noundef 0)
  %32 = trunc i64 %31 to i32
  store i32 %32, ptr %8, align 4, !tbaa !5
  %33 = load i32, ptr %8, align 4, !tbaa !5
  %34 = icmp eq i32 -1, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %28
  call void @perror(ptr noundef @.str.7)
  store i32 2, ptr %11, align 4
  br label %53

36:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !5
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %47, %36
  %38 = load i32, ptr %10, align 4, !tbaa !5
  %39 = icmp slt i32 %38, 331
  br i1 %39, label %40, label %50

40:                                               ; preds = %37
  %41 = load i32, ptr %10, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [331 x i8], ptr %9, i64 0, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !11
  %45 = zext i8 %44 to i32
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, i32 noundef %45)
  br label %47

47:                                               ; preds = %40
  %48 = load i32, ptr %10, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %10, align 4, !tbaa !5
  br label %37, !llvm.loop !12

50:                                               ; preds = %37
  %51 = call i32 (ptr, ...) @printf(ptr noundef @.str.9)
  %52 = call i32 @usleep(i32 noundef 100)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  store i32 0, ptr %11, align 4
  br label %53

53:                                               ; preds = %50, %35
  call void @llvm.lifetime.end.p0(i64 331, ptr %9) #4
  %54 = load i32, ptr %11, align 4
  switch i32 %54, label %64 [
    i32 0, label %55
    i32 2, label %56
  ]

55:                                               ; preds = %53
  br label %27

56:                                               ; preds = %53, %19
  %57 = load i32, ptr %7, align 4, !tbaa !5
  %58 = icmp sgt i32 %57, 0
  br i1 %58, label %59, label %62

59:                                               ; preds = %56
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = call i32 @close(i32 noundef %60)
  br label %62

62:                                               ; preds = %59, %56
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.10)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %64

64:                                               ; preds = %62, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %65 = load i32, ptr %3, align 4
  ret i32 %65
}

declare void @perror(ptr noundef) #2

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

declare i32 @fflush(ptr noundef) #2

declare i32 @sleep(i32 noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

declare i64 @sendto(i32 noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i32 noundef) #2

declare i32 @usleep(i32 noundef) #2

declare i32 @close(i32 noundef) #2

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{!"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 = !{!7, !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"

@.str.4 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [16 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [47 x i8], align 1
@__const.main.data = external hidden unnamed_addr constant [331 x i8], align 16
@.str.7 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [28 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @create_raw_socket(ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca [331 x i8], align 16
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = tail call i32 @create_raw_socket(ptr noundef %5)
  %7 = icmp eq i32 %6, -1
  br i1 %7, label %.thread18, label %8

.thread18:                                        ; preds = %2
  tail call void @perror(ptr noundef nonnull @.str.4) #5
  br label %30

8:                                                ; preds = %2
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %10 = load ptr, ptr @stdout, align 8, !tbaa !5
  %11 = tail call i32 @fflush(ptr noundef %10)
  %12 = tail call i32 @sleep(i32 noundef 1) #6
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, ptr noundef %5)
  call void @llvm.lifetime.start.p0(i64 331, ptr nonnull %3) #6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(331) %3, ptr noundef nonnull align 16 dereferenceable(331) @__const.main.data, i64 331, i1 false)
  %14 = call i64 @sendto(i32 noundef %6, ptr noundef nonnull %3, i64 noundef 331, i32 noundef 0, ptr noundef null, i32 noundef 0) #6
  %15 = and i64 %14, 4294967295
  %16 = icmp eq i64 %15, 4294967295
  br i1 %16, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %8, %.preheader.backedge
  %indvars.iv = phi i64 [ %indvars.iv.be, %.preheader.backedge ], [ 0, %8 ]
  %17 = getelementptr inbounds [331 x i8], ptr %3, i64 0, i64 %indvars.iv
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %19 = zext i8 %18 to i32
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, i32 noundef %19)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 331
  br i1 %exitcond.not, label %21, label %.preheader.backedge

.preheader.backedge:                              ; preds = %.preheader, %21
  %indvars.iv.be = phi i64 [ %indvars.iv.next, %.preheader ], [ 0, %21 ]
  br label %.preheader, !llvm.loop !10

21:                                               ; preds = %.preheader
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9)
  %23 = call i32 @usleep(i32 noundef 100) #6
  call void @llvm.lifetime.end.p0(i64 331, ptr nonnull %3) #6
  call void @llvm.lifetime.start.p0(i64 331, ptr nonnull %3) #6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(331) %3, ptr noundef nonnull align 16 dereferenceable(331) @__const.main.data, i64 331, i1 false)
  %24 = call i64 @sendto(i32 noundef %6, ptr noundef nonnull %3, i64 noundef 331, i32 noundef 0, ptr noundef null, i32 noundef 0) #6
  %25 = and i64 %24, 4294967295
  %26 = icmp eq i64 %25, 4294967295
  br i1 %26, label %._crit_edge, label %.preheader.backedge

._crit_edge:                                      ; preds = %21, %8
  call void @perror(ptr noundef nonnull @.str.7) #5
  call void @llvm.lifetime.end.p0(i64 331, ptr nonnull %3) #6
  %27 = icmp sgt i32 %6, 0
  br i1 %27, label %28, label %30

28:                                               ; preds = %._crit_edge
  %29 = call i32 @close(i32 noundef %6) #6
  br label %30

30:                                               ; preds = %.thread18, %28, %._crit_edge
  %31 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10)
  ret i32 0
}

; Function Attrs: nofree nounwind
declare void @perror(ptr nocapture noundef readonly) local_unnamed_addr #2

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

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #2

declare i32 @sleep(i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

declare i64 @sendto(i32 noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

declare i32 @usleep(i32 noundef) local_unnamed_addr #3

declare i32 @close(i32 noundef) local_unnamed_addr #3

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 = { 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 #3 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { cold }
attributes #6 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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