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

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

@tcpip_mbox = external hidden global ptr, align 8
@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [179 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local signext i8 @tcpip_inpkt(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  br label %10

10:                                               ; preds = %3
  %11 = call i32 @sys_mbox_valid(ptr noundef @tcpip_mbox)
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %18, label %13

13:                                               ; preds = %10
  br label %14

14:                                               ; preds = %13
  %15 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 252, ptr noundef @.str.2)
  br label %16

16:                                               ; preds = %14
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17, %10
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  %21 = call ptr @memp_malloc(i32 noundef 9)
  store ptr %21, ptr %8, align 8, !tbaa !5
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %25

24:                                               ; preds = %20
  store i8 -1, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %47

25:                                               ; preds = %20
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.tcpip_msg, ptr %26, i32 0, i32 0
  store i32 0, ptr %27, align 8, !tbaa !9
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.tcpip_msg, ptr %29, i32 0, i32 1
  %31 = getelementptr inbounds %struct.anon, ptr %30, i32 0, i32 0
  store ptr %28, ptr %31, align 8, !tbaa !12
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.tcpip_msg, ptr %33, i32 0, i32 1
  %35 = getelementptr inbounds %struct.anon, ptr %34, i32 0, i32 1
  store ptr %32, ptr %35, align 8, !tbaa !12
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.tcpip_msg, ptr %37, i32 0, i32 1
  %39 = getelementptr inbounds %struct.anon, ptr %38, i32 0, i32 2
  store ptr %36, ptr %39, align 8, !tbaa !12
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = call signext i8 @sys_mbox_trypost(ptr noundef @tcpip_mbox, ptr noundef %40)
  %42 = sext i8 %41 to i32
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %46

44:                                               ; preds = %25
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  call void @memp_free(i32 noundef 9, ptr noundef %45)
  store i8 -1, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %47

46:                                               ; preds = %25
  store i8 0, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %47

47:                                               ; preds = %46, %44, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %48 = load i8, ptr %4, align 1
  ret i8 %48
}

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

declare i32 @sys_mbox_valid(ptr noundef) #2

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

declare ptr @memp_malloc(i32 noundef) #2

declare signext i8 @sys_mbox_trypost(ptr noundef, 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"tcpip_msg", !11, i64 0, !7, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}


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

@tcpip_mbox = external hidden global ptr, align 8
@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [179 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local signext range(i8 -1, 1) i8 @tcpip_inpkt(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = tail call i32 @sys_mbox_valid(ptr noundef nonnull @tcpip_mbox) #3
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %5, label %7

5:                                                ; preds = %3
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.1, i32 noundef 252, ptr noundef nonnull @.str.2)
  br label %7

7:                                                ; preds = %5, %3
  %8 = tail call ptr @memp_malloc(i32 noundef 9) #3
  %9 = icmp eq ptr %8, null
  br i1 %9, label %16, label %10

10:                                               ; preds = %7
  store i32 0, ptr %8, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %8, i64 8
  store ptr %0, ptr %11, align 8, !tbaa !10
  %12 = getelementptr inbounds i8, ptr %8, i64 16
  store ptr %1, ptr %12, align 8, !tbaa !10
  %13 = getelementptr inbounds i8, ptr %8, i64 24
  store ptr %2, ptr %13, align 8, !tbaa !10
  %14 = tail call signext i8 @sys_mbox_trypost(ptr noundef nonnull @tcpip_mbox, ptr noundef nonnull %8) #3
  %.not11 = icmp eq i8 %14, 0
  br i1 %.not11, label %16, label %15

15:                                               ; preds = %10
  tail call void @memp_free(i32 noundef 9, ptr noundef nonnull %8) #3
  br label %16

16:                                               ; preds = %10, %7, %15
  %.0 = phi i8 [ -1, %15 ], [ -1, %7 ], [ 0, %10 ]
  ret i8 %.0
}

declare i32 @sys_mbox_valid(ptr noundef) local_unnamed_addr #1

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

declare ptr @memp_malloc(i32 noundef) local_unnamed_addr #1

declare signext i8 @sys_mbox_trypost(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @memp_free(i32 noundef, ptr noundef) local_unnamed_addr #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 = { "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 = { 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 = { 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 = !{!"tcpip_msg", !7, i64 0, !8, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}


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