; LLVM IR from whoiswelliton/Computer_Engineering_UTFPR-PB :: Embedded_Systems/TIVA Connected TM4C1294XL Projects/01 - lwIP_HTTPServer_on_TIVA (alloc)

; 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.netconn = type { i32, i32, %union.anon.5, i8, ptr, ptr, ptr, i32, i32, i32, i8, ptr, ptr }
%union.anon.5 = type { ptr }

@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [181 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [38 x i8], align 1

declare i32 @printf(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 ptr @netconn_alloc(i32 noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  %9 = alloca i32, 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) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  store i8 0, ptr %8, align 1, !tbaa !11
  %10 = call ptr @memp_malloc(i32 noundef 7)
  store ptr %10, ptr %6, align 8, !tbaa !9
  %11 = load ptr, ptr %6, align 8, !tbaa !9
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %73

14:                                               ; preds = %2
  %15 = load ptr, ptr %6, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.netconn, ptr %15, i32 0, i32 3
  store i8 0, ptr %16, align 8, !tbaa !12
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = load ptr, ptr %6, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.netconn, ptr %18, i32 0, i32 0
  store i32 %17, ptr %19, align 8, !tbaa !14
  %20 = load ptr, ptr %6, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.netconn, ptr %20, i32 0, i32 2
  store ptr null, ptr %21, align 8, !tbaa !11
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = and i32 %22, 240
  switch i32 %23, label %26 [
    i32 32, label %24
    i32 16, label %25
  ]

24:                                               ; preds = %14
  store i32 6, ptr %7, align 4, !tbaa !5
  br label %34

25:                                               ; preds = %14
  store i32 6, ptr %7, align 4, !tbaa !5
  br label %34

26:                                               ; preds = %14
  br label %27

27:                                               ; preds = %26
  br label %28

28:                                               ; preds = %27
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.3, i32 noundef 741, ptr noundef @.str.2)
  br label %30

30:                                               ; preds = %28
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32
  br label %71

34:                                               ; preds = %25, %24
  %35 = load ptr, ptr %6, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.netconn, ptr %35, i32 0, i32 5
  %37 = load i32, ptr %7, align 4, !tbaa !5
  %38 = call signext i8 @sys_mbox_new(ptr noundef %36, i32 noundef %37)
  %39 = sext i8 %38 to i32
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %34
  br label %71

42:                                               ; preds = %34
  %43 = load ptr, ptr %6, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.netconn, ptr %43, i32 0, i32 4
  %45 = call signext i8 @sys_sem_new(ptr noundef %44, i8 noundef zeroext 0)
  %46 = sext i8 %45 to i32
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %51

48:                                               ; preds = %42
  %49 = load ptr, ptr %6, align 8, !tbaa !9
  %50 = getelementptr inbounds %struct.netconn, ptr %49, i32 0, i32 5
  call void @sys_mbox_free(ptr noundef %50)
  br label %71

51:                                               ; preds = %42
  %52 = load ptr, ptr %6, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.netconn, ptr %52, i32 0, i32 6
  call void @sys_mbox_set_invalid(ptr noundef %53)
  %54 = load ptr, ptr %6, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.netconn, ptr %54, i32 0, i32 1
  store i32 0, ptr %55, align 4, !tbaa !15
  %56 = load ptr, ptr %6, align 8, !tbaa !9
  %57 = getelementptr inbounds %struct.netconn, ptr %56, i32 0, i32 7
  store i32 -1, ptr %57, align 8, !tbaa !16
  %58 = load ptr, ptr %5, align 8, !tbaa !9
  %59 = load ptr, ptr %6, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.netconn, ptr %59, i32 0, i32 12
  store ptr %58, ptr %60, align 8, !tbaa !17
  %61 = load ptr, ptr %6, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.netconn, ptr %61, i32 0, i32 11
  store ptr null, ptr %62, align 8, !tbaa !18
  %63 = load ptr, ptr %6, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.netconn, ptr %63, i32 0, i32 8
  store i32 0, ptr %64, align 4, !tbaa !19
  %65 = load ptr, ptr %6, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.netconn, ptr %65, i32 0, i32 9
  store i32 0, ptr %66, align 8, !tbaa !20
  %67 = load i8, ptr %8, align 1, !tbaa !11
  %68 = load ptr, ptr %6, align 8, !tbaa !9
  %69 = getelementptr inbounds %struct.netconn, ptr %68, i32 0, i32 10
  store i8 %67, ptr %69, align 4, !tbaa !21
  %70 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %70, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %73

71:                                               ; preds = %48, %41, %33
  %72 = load ptr, ptr %6, align 8, !tbaa !9
  call void @memp_free(i32 noundef 7, ptr noundef %72)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %73

73:                                               ; preds = %71, %51, %13
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %74 = load ptr, ptr %3, align 8
  ret ptr %74
}

declare ptr @memp_malloc(i32 noundef) #0

declare signext i8 @sys_mbox_new(ptr noundef, i32 noundef) #0

declare signext i8 @sys_sem_new(ptr noundef, i8 noundef zeroext) #0

declare void @sys_mbox_free(ptr noundef) #0

declare void @sys_mbox_set_invalid(ptr noundef) #0

declare void @memp_free(i32 noundef, ptr noundef) #0

attributes #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 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 #3 = { 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 = !{!13, !7, i64 16}
!13 = !{!"netconn", !6, i64 0, !6, i64 4, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !6, i64 48, !6, i64 52, !6, i64 56, !7, i64 60, !10, i64 64, !10, i64 72}
!14 = !{!13, !6, i64 0}
!15 = !{!13, !6, i64 4}
!16 = !{!13, !6, i64 48}
!17 = !{!13, !10, i64 72}
!18 = !{!13, !10, i64 64}
!19 = !{!13, !6, i64 52}
!20 = !{!13, !6, i64 56}
!21 = !{!13, !7, i64 60}


; 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 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [181 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [38 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local ptr @netconn_alloc(i32 noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call ptr @memp_malloc(i32 noundef 7) #4
  %4 = icmp eq ptr %3, null
  br i1 %4, label %26, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %3, i64 16
  store i8 0, ptr %6, align 8, !tbaa !5
  store i32 %0, ptr %3, align 8, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr null, ptr %7, align 8, !tbaa !12
  %8 = trunc i32 %0 to i8
  %trunc = and i8 %8, -16
  switch i8 %trunc, label %9 [
    i8 32, label %11
    i8 16, label %11
  ]

9:                                                ; preds = %5
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.3, i32 noundef 741, ptr noundef nonnull @.str.2)
  br label %25

11:                                               ; preds = %5, %5
  %12 = getelementptr inbounds i8, ptr %3, i64 32
  %13 = tail call signext i8 @sys_mbox_new(ptr noundef nonnull %12, i32 noundef 6) #4
  %.not = icmp eq i8 %13, 0
  br i1 %.not, label %14, label %25

14:                                               ; preds = %11
  %15 = getelementptr inbounds i8, ptr %3, i64 24
  %16 = tail call signext i8 @sys_sem_new(ptr noundef nonnull %15, i8 noundef zeroext 0) #4
  %.not24 = icmp eq i8 %16, 0
  br i1 %.not24, label %18, label %17

17:                                               ; preds = %14
  tail call void @sys_mbox_free(ptr noundef nonnull %12) #4
  br label %25

18:                                               ; preds = %14
  %19 = getelementptr inbounds i8, ptr %3, i64 40
  tail call void @sys_mbox_set_invalid(ptr noundef nonnull %19) #4
  %20 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 0, ptr %20, align 4, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %3, i64 48
  store i32 -1, ptr %21, align 8, !tbaa !14
  %22 = getelementptr inbounds i8, ptr %3, i64 72
  store ptr %1, ptr %22, align 8, !tbaa !15
  %23 = getelementptr inbounds i8, ptr %3, i64 64
  store ptr null, ptr %23, align 8, !tbaa !16
  %24 = getelementptr inbounds i8, ptr %3, i64 52
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(9) %24, i8 0, i64 9, i1 false)
  br label %26

25:                                               ; preds = %11, %17, %9
  tail call void @memp_free(i32 noundef 7, ptr noundef nonnull %3) #4
  br label %26

26:                                               ; preds = %2, %25, %18
  %.0 = phi ptr [ null, %25 ], [ %3, %18 ], [ null, %2 ]
  ret ptr %.0
}

declare ptr @memp_malloc(i32 noundef) local_unnamed_addr #2

declare signext i8 @sys_mbox_new(ptr noundef, i32 noundef) local_unnamed_addr #2

declare signext i8 @sys_sem_new(ptr noundef, i8 noundef zeroext) local_unnamed_addr #2

declare void @sys_mbox_free(ptr noundef) local_unnamed_addr #2

declare void @sys_mbox_set_invalid(ptr noundef) local_unnamed_addr #2

declare void @memp_free(i32 noundef, ptr noundef) local_unnamed_addr #2

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

attributes #0 = { 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 #1 = { 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 #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: write) }
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, !8, i64 16}
!6 = !{!"netconn", !7, i64 0, !7, i64 4, !8, i64 8, !8, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !7, i64 48, !7, i64 52, !7, i64 56, !8, i64 60, !10, i64 64, !10, i64 72}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!8, !8, i64 0}
!13 = !{!6, !7, i64 4}
!14 = !{!6, !7, i64 48}
!15 = !{!6, !10, i64 72}
!16 = !{!6, !10, i64 64}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass