; LLVM IR from jovanlanik/wip :: flipdot.d/src/external (wfdd)

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

; Function Attrs: nounwind uwtable
define dso_local ptr @wfdd_initDisplay(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  %9 = call noalias ptr @malloc(i64 noundef 20) #8
  store ptr %9, ptr %6, align 8, !tbaa !5
  %10 = call i32 @socket(i32 noundef 2, i32 noundef 2, i32 noundef 0) #7
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.wfdd_display_t, ptr %11, i32 0, i32 0
  store i32 %10, ptr %12, align 4, !tbaa !11
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.wfdd_display_t, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = icmp eq i32 %15, -1
  br i1 %16, label %17, label %19

17:                                               ; preds = %2
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %18) #7
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %58

19:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #7
  store i8 1, ptr %8, align 1, !tbaa !16
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.wfdd_display_t, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = call i32 @setsockopt(i32 noundef %22, i32 noundef 0, i32 noundef 33, ptr noundef %8, i32 noundef 1) #7
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %31

25:                                               ; preds = %19
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.wfdd_display_t, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = call i32 @close(i32 noundef %28)
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %30) #7
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %57

31:                                               ; preds = %19
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.wfdd_display_t, ptr %32, i32 0, i32 1
  call void @llvm.memset.p0.i64(ptr align 4 %33, i8 0, i64 16, i1 false)
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = trunc i32 %34 to i16
  %36 = call zeroext i16 @__bswap_16(i16 noundef zeroext %35)
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.wfdd_display_t, ptr %37, i32 0, i32 1
  %39 = getelementptr inbounds %struct.sockaddr_in, ptr %38, i32 0, i32 1
  store i16 %36, ptr %39, align 2, !tbaa !17
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.wfdd_display_t, ptr %40, i32 0, i32 1
  %42 = getelementptr inbounds %struct.sockaddr_in, ptr %41, i32 0, i32 0
  store i16 2, ptr %42, align 4, !tbaa !18
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.wfdd_display_t, ptr %44, i32 0, i32 1
  %46 = getelementptr inbounds %struct.sockaddr_in, ptr %45, i32 0, i32 2
  %47 = call i32 @inet_pton(i32 noundef 2, ptr noundef %43, ptr noundef %46) #7
  %48 = icmp ne i32 %47, 1
  br i1 %48, label %49, label %55

49:                                               ; preds = %31
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.wfdd_display_t, ptr %50, i32 0, i32 0
  %52 = load i32, ptr %51, align 4, !tbaa !11
  %53 = call i32 @close(i32 noundef %52)
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %54) #7
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %57

55:                                               ; preds = %31
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %56, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %57

57:                                               ; preds = %55, %49, %25
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #7
  br label %58

58:                                               ; preds = %57, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  %59 = load ptr, ptr %3, align 8
  ret ptr %59
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind
declare i32 @socket(i32 noundef, i32 noundef, i32 noundef) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

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

declare i32 @close(i32 noundef) #4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @__bswap_16(i16 noundef zeroext) #6

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

; 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 = { nounwind allocsize(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 #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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { inlinehint 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 #7 = { nounwind }
attributes #8 = { nounwind allocsize(0) }

!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 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0, !13, i64 4}
!13 = !{!"sockaddr_in", !14, i64 0, !14, i64 2, !15, i64 4, !7, i64 8}
!14 = !{!"short", !7, i64 0}
!15 = !{!"in_addr", !10, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!12, !14, i64 6}
!18 = !{!12, !14, i64 4}


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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @wfdd_initDisplay(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i8, align 1
  %4 = tail call noalias dereferenceable_or_null(20) ptr @malloc(i64 noundef 20) #8
  %5 = tail call i32 @socket(i32 noundef 2, i32 noundef 2, i32 noundef 0) #9
  store i32 %5, ptr %4, align 4, !tbaa !5
  %6 = icmp eq i32 %5, -1
  br i1 %6, label %7, label %8

7:                                                ; preds = %2
  tail call void @free(ptr noundef nonnull %4) #9
  br label %22

8:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #9
  store i8 1, ptr %3, align 1, !tbaa !13
  %9 = call i32 @setsockopt(i32 noundef %5, i32 noundef 0, i32 noundef 33, ptr noundef nonnull %3, i32 noundef 1) #9
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %10, label %.sink.split

10:                                               ; preds = %8
  %11 = getelementptr inbounds i8, ptr %4, i64 4
  %12 = getelementptr inbounds i8, ptr %4, i64 8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %12, i8 0, i64 12, i1 false)
  %13 = trunc i32 %1 to i16
  %14 = call zeroext i16 @__bswap_16(i16 noundef zeroext %13)
  %15 = getelementptr inbounds i8, ptr %4, i64 6
  store i16 %14, ptr %15, align 2, !tbaa !14
  store i16 2, ptr %11, align 4, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %4, i64 8
  %17 = call i32 @inet_pton(i32 noundef 2, ptr noundef %0, ptr noundef nonnull %16) #9
  %.not15 = icmp eq i32 %17, 1
  br i1 %.not15, label %21, label %18

18:                                               ; preds = %10
  %19 = load i32, ptr %4, align 4, !tbaa !5
  br label %.sink.split

.sink.split:                                      ; preds = %8, %18
  %.sink = phi i32 [ %19, %18 ], [ %5, %8 ]
  %20 = call i32 @close(i32 noundef %.sink) #9
  call void @free(ptr noundef nonnull %4) #9
  br label %21

21:                                               ; preds = %.sink.split, %10
  %.0 = phi ptr [ %4, %10 ], [ null, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #9
  br label %22

22:                                               ; preds = %21, %7
  %.1 = phi ptr [ null, %7 ], [ %.0, %21 ]
  ret ptr %.1
}

; 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare i32 @socket(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: nounwind
declare i32 @setsockopt(i32 noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

declare i32 @close(i32 noundef) local_unnamed_addr #5

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #6

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @__bswap_16(i16 noundef zeroext) local_unnamed_addr #7

; Function Attrs: nounwind
declare i32 @inet_pton(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #7 = { inlinehint 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 #8 = { nounwind allocsize(0) }
attributes #9 = { 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"sockaddr_in", !11, i64 0, !11, i64 2, !12, i64 4, !8, i64 8}
!11 = !{!"short", !8, i64 0}
!12 = !{!"in_addr", !7, i64 0}
!13 = !{!8, !8, i64 0}
!14 = !{!6, !11, i64 6}
!15 = !{!6, !11, i64 4}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass