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

; 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.api_msg = type { ptr, i8, %union.anon }
%union.anon = type { %struct.anon.2 }
%struct.anon.2 = type { ptr, i16, i64, i64, i64, i8, i32 }
%struct.anon = type { i8 }
%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.1 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [181 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @netconn_new_with_proto_and_callback(i32 noundef %0, i8 noundef zeroext %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca %struct.api_msg, align 8
  %10 = alloca i8, align 1
  %11 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i8 %1, ptr %6, align 1, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 64, ptr %9) #3
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = load ptr, ptr %7, align 8, !tbaa !10
  %14 = call ptr @netconn_alloc(i32 noundef %12, ptr noundef %13)
  store ptr %14, ptr %8, align 8, !tbaa !10
  %15 = load ptr, ptr %8, align 8, !tbaa !10
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %89

17:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #3
  %18 = load i8, ptr %6, align 1, !tbaa !9
  %19 = getelementptr inbounds %struct.api_msg, ptr %9, i32 0, i32 2
  %20 = getelementptr inbounds %struct.anon, ptr %19, i32 0, i32 0
  store i8 %18, ptr %20, align 8, !tbaa !9
  %21 = load ptr, ptr %8, align 8, !tbaa !10
  %22 = getelementptr inbounds %struct.api_msg, ptr %9, i32 0, i32 0
  store ptr %21, ptr %22, align 8, !tbaa !12
  %23 = call signext i8 @netconn_apimsg(ptr noundef @lwip_netconn_do_newconn, ptr noundef %9)
  store i8 %23, ptr %10, align 1, !tbaa !9
  %24 = load i8, ptr %10, align 1, !tbaa !9
  %25 = sext i8 %24 to i32
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %85

27:                                               ; preds = %17
  br label %28

28:                                               ; preds = %27
  %29 = load ptr, ptr %8, align 8, !tbaa !10
  %30 = getelementptr inbounds %struct.netconn, ptr %29, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = icmp eq ptr %31, null
  br i1 %32, label %38, label %33

33:                                               ; preds = %28
  br label %34

34:                                               ; preds = %33
  %35 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 163, ptr noundef @.str.2)
  br label %36

36:                                               ; preds = %34
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37, %28
  br label %39

39:                                               ; preds = %38
  br label %40

40:                                               ; preds = %39
  br label %41

41:                                               ; preds = %40
  %42 = load ptr, ptr %8, align 8, !tbaa !10
  %43 = getelementptr inbounds %struct.netconn, ptr %42, i32 0, i32 5
  %44 = call i32 @sys_mbox_valid(ptr noundef %43)
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %51, label %46

46:                                               ; preds = %41
  br label %47

47:                                               ; preds = %46
  %48 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.3, i32 noundef 164, ptr noundef @.str.2)
  br label %49

49:                                               ; preds = %47
  br label %50

50:                                               ; preds = %49
  br label %51

51:                                               ; preds = %50, %41
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52
  br label %54

54:                                               ; preds = %53
  %55 = load ptr, ptr %8, align 8, !tbaa !10
  %56 = getelementptr inbounds %struct.netconn, ptr %55, i32 0, i32 6
  %57 = call i32 @sys_mbox_valid(ptr noundef %56)
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %64

59:                                               ; preds = %54
  br label %60

60:                                               ; preds = %59
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.4, i32 noundef 166, ptr noundef @.str.2)
  br label %62

62:                                               ; preds = %60
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63, %54
  br label %65

65:                                               ; preds = %64
  br label %66

66:                                               ; preds = %65
  br label %67

67:                                               ; preds = %66
  %68 = load ptr, ptr %8, align 8, !tbaa !10
  %69 = getelementptr inbounds %struct.netconn, ptr %68, i32 0, i32 4
  %70 = call i32 @sys_sem_valid(ptr noundef %69)
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %77, label %72

72:                                               ; preds = %67
  br label %73

73:                                               ; preds = %72
  %74 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.5, i32 noundef 169, ptr noundef @.str.2)
  br label %75

75:                                               ; preds = %73
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76, %67
  br label %78

78:                                               ; preds = %77
  br label %79

79:                                               ; preds = %78
  %80 = load ptr, ptr %8, align 8, !tbaa !10
  %81 = getelementptr inbounds %struct.netconn, ptr %80, i32 0, i32 4
  call void @sys_sem_free(ptr noundef %81)
  %82 = load ptr, ptr %8, align 8, !tbaa !10
  %83 = getelementptr inbounds %struct.netconn, ptr %82, i32 0, i32 5
  call void @sys_mbox_free(ptr noundef %83)
  %84 = load ptr, ptr %8, align 8, !tbaa !10
  call void @memp_free(i32 noundef 7, ptr noundef %84)
  store ptr null, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %86

85:                                               ; preds = %17
  store i32 0, ptr %11, align 4
  br label %86

86:                                               ; preds = %85, %79
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  %87 = load i32, ptr %11, align 4
  switch i32 %87, label %91 [
    i32 0, label %88
  ]

88:                                               ; preds = %86
  br label %89

89:                                               ; preds = %88, %3
  %90 = load ptr, ptr %8, align 8, !tbaa !10
  store ptr %90, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %91

91:                                               ; preds = %89, %86
  call void @llvm.lifetime.end.p0(i64 64, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %92 = load ptr, ptr %4, align 8
  ret ptr %92
}

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

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

; Function Attrs: nounwind uwtable
declare hidden signext i8 @netconn_apimsg(ptr noundef, ptr noundef) #0

declare void @lwip_netconn_do_newconn(ptr noundef) #2

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

declare i32 @sys_mbox_valid(ptr noundef) #2

declare i32 @sys_sem_valid(ptr noundef) #2

declare void @sys_sem_free(ptr noundef) #2

declare void @sys_mbox_free(ptr noundef) #2

declare void @memp_free(i32 noundef, ptr 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 }

!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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"api_msg", !11, i64 0, !7, i64 8, !7, i64 16}


; 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.api_msg = type { ptr, i8, %union.anon }
%union.anon = type { %struct.anon.2 }
%struct.anon.2 = type { ptr, i16, i64, i64, i64, i8, i32 }

@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [181 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @netconn_new_with_proto_and_callback(i32 noundef %0, i8 noundef zeroext %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.api_msg, align 8
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %4) #4
  %5 = tail call ptr @netconn_alloc(i32 noundef %0, ptr noundef %2) #4
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %.critedge, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %4, i64 16
  store i8 %1, ptr %7, align 8, !tbaa !5
  store ptr %5, ptr %4, align 8, !tbaa !8
  %8 = call signext i8 @netconn_apimsg(ptr noundef nonnull @lwip_netconn_do_newconn, ptr noundef nonnull %4)
  %.not17 = icmp eq i8 %8, 0
  br i1 %.not17, label %.critedge, label %9

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %5, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %15, label %13

13:                                               ; preds = %9
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.1, i32 noundef 163, ptr noundef nonnull @.str.2)
  br label %15

15:                                               ; preds = %9, %13
  %16 = getelementptr inbounds i8, ptr %5, i64 32
  %17 = call i32 @sys_mbox_valid(ptr noundef nonnull %16) #4
  %.not18 = icmp eq i32 %17, 0
  br i1 %.not18, label %18, label %20

18:                                               ; preds = %15
  %19 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.3, i32 noundef 164, ptr noundef nonnull @.str.2)
  br label %20

20:                                               ; preds = %15, %18
  %21 = getelementptr inbounds i8, ptr %5, i64 40
  %22 = call i32 @sys_mbox_valid(ptr noundef nonnull %21) #4
  %.not19 = icmp eq i32 %22, 0
  br i1 %.not19, label %25, label %23

23:                                               ; preds = %20
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.4, i32 noundef 166, ptr noundef nonnull @.str.2)
  br label %25

25:                                               ; preds = %20, %23
  %26 = getelementptr inbounds i8, ptr %5, i64 24
  %27 = call i32 @sys_sem_valid(ptr noundef nonnull %26) #4
  %.not20 = icmp eq i32 %27, 0
  br i1 %.not20, label %28, label %30

28:                                               ; preds = %25
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.5, i32 noundef 169, ptr noundef nonnull @.str.2)
  br label %30

30:                                               ; preds = %28, %25
  call void @sys_sem_free(ptr noundef nonnull %26) #4
  call void @sys_mbox_free(ptr noundef nonnull %16) #4
  call void @memp_free(i32 noundef 7, ptr noundef nonnull %5) #4
  br label %.critedge

.critedge:                                        ; preds = %3, %6, %30
  %.1 = phi ptr [ null, %30 ], [ %5, %6 ], [ null, %3 ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %4) #4
  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

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

; Function Attrs: nounwind uwtable
declare hidden signext i8 @netconn_apimsg(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @lwip_netconn_do_newconn(ptr noundef) #2

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

declare i32 @sys_mbox_valid(ptr noundef) local_unnamed_addr #2

declare i32 @sys_sem_valid(ptr noundef) local_unnamed_addr #2

declare void @sys_sem_free(ptr noundef) local_unnamed_addr #2

declare void @sys_mbox_free(ptr noundef) local_unnamed_addr #2

declare void @memp_free(i32 noundef, ptr 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 }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 0}
!9 = !{!"api_msg", !10, i64 0, !6, i64 8, !6, i64 16}
!10 = !{!"any pointer", !6, i64 0}


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