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

; 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.tcp_pcb = type { %struct.ip4_addr, %struct.ip4_addr, i8, i8, i8, i8, ptr, ptr, i32, i8, i16, i16, i16, i8, i8, i8, i32, i32, i16, i16, i32, i16, i16, i32, i32, i16, i16, i16, i8, i8, i32, i16, i16, i32, i32, i32, i32, i32, i16, i16, i16, i16, i16, i16, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i8, i8, i8, i8 }
%struct.ip4_addr = type { i32 }

@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [178 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [26 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare hidden signext i8 @tcp_close_shutdown(ptr noundef, i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local signext i8 @tcp_shutdown(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %3
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %15, label %11

11:                                               ; preds = %8
  br label %12

12:                                               ; preds = %11
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.4, i32 noundef 519, ptr noundef @.str.2)
  br label %14

14:                                               ; preds = %12
  store i8 -16, ptr %4, align 1
  br label %68

15:                                               ; preds = %8
  br label %16

16:                                               ; preds = %15
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.tcp_pcb, ptr %17, i32 0, i32 8
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = icmp eq i32 %19, 1
  br i1 %20, label %21, label %22

21:                                               ; preds = %16
  store i8 -11, ptr %4, align 1
  br label %68

22:                                               ; preds = %16
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %54

25:                                               ; preds = %22
  br label %26

26:                                               ; preds = %25
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.tcp_pcb, ptr %27, i32 0, i32 12
  %29 = load i16, ptr %28, align 2, !tbaa !15
  %30 = zext i16 %29 to i32
  %31 = or i32 %30, 16
  %32 = trunc i32 %31 to i16
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.tcp_pcb, ptr %33, i32 0, i32 12
  store i16 %32, ptr %34, align 2, !tbaa !15
  br label %35

35:                                               ; preds = %26
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %41

38:                                               ; preds = %35
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = call signext i8 @tcp_close_shutdown(ptr noundef %39, i8 noundef zeroext 1)
  store i8 %40, ptr %4, align 1
  br label %68

41:                                               ; preds = %35
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.tcp_pcb, ptr %42, i32 0, i32 46
  %44 = load ptr, ptr %43, align 8, !tbaa !16
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %53

46:                                               ; preds = %41
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.tcp_pcb, ptr %47, i32 0, i32 46
  %49 = load ptr, ptr %48, align 8, !tbaa !16
  %50 = call zeroext i8 @pbuf_free(ptr noundef %49)
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.tcp_pcb, ptr %51, i32 0, i32 46
  store ptr null, ptr %52, align 8, !tbaa !16
  br label %53

53:                                               ; preds = %46, %41
  br label %54

54:                                               ; preds = %53, %22
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %67

57:                                               ; preds = %54
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.tcp_pcb, ptr %58, i32 0, i32 8
  %60 = load i32, ptr %59, align 8, !tbaa !11
  switch i32 %60, label %66 [
    i32 3, label %61
    i32 4, label %61
    i32 7, label %61
  ]

61:                                               ; preds = %57, %57, %57
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = trunc i32 %63 to i8
  %65 = call signext i8 @tcp_close_shutdown(ptr noundef %62, i8 noundef zeroext %64)
  store i8 %65, ptr %4, align 1
  br label %68

66:                                               ; preds = %57
  store i8 -11, ptr %4, align 1
  br label %68

67:                                               ; preds = %54
  store i8 0, ptr %4, align 1
  br label %68

68:                                               ; preds = %67, %66, %61, %38, %21, %14
  %69 = load i8, ptr %4, align 1
  ret i8 %69
}

declare zeroext i8 @pbuf_free(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 = { 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" }

!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 32}
!12 = !{!"tcp_pcb", !13, i64 0, !13, i64 4, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !6, i64 16, !6, i64 24, !10, i64 32, !7, i64 36, !14, i64 38, !14, i64 40, !14, i64 42, !7, i64 44, !7, i64 45, !7, i64 46, !10, i64 48, !10, i64 52, !14, i64 56, !14, i64 58, !10, i64 60, !14, i64 64, !14, i64 66, !10, i64 68, !10, i64 72, !14, i64 76, !14, i64 78, !14, i64 80, !7, i64 82, !7, i64 83, !10, i64 84, !14, i64 88, !14, i64 90, !10, i64 92, !10, i64 96, !10, i64 100, !10, i64 104, !10, i64 108, !14, i64 112, !14, i64 114, !14, i64 116, !14, i64 118, !14, i64 120, !14, i64 122, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !10, i64 200, !7, i64 204, !7, i64 205, !7, i64 206, !7, i64 207}
!13 = !{!"ip4_addr", !10, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!12, !14, i64 42}
!16 = !{!12, !6, i64 144}


; 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 [178 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [26 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare hidden signext i8 @tcp_close_shutdown(ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local signext i8 @tcp_shutdown(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %4, label %6

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

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %9 = icmp eq i32 %8, 1
  br i1 %9, label %.thread, label %10

10:                                               ; preds = %6
  %.not16 = icmp eq i32 %1, 0
  br i1 %.not16, label %22, label %11

11:                                               ; preds = %10
  %12 = getelementptr inbounds i8, ptr %0, i64 42
  %13 = load i16, ptr %12, align 2, !tbaa !13
  %14 = or i16 %13, 16
  store i16 %14, ptr %12, align 2, !tbaa !13
  %.not17 = icmp eq i32 %2, 0
  br i1 %.not17, label %17, label %15

15:                                               ; preds = %11
  %16 = tail call signext i8 @tcp_close_shutdown(ptr noundef nonnull %0, i8 noundef zeroext 1)
  br label %.thread

17:                                               ; preds = %11
  %18 = getelementptr inbounds i8, ptr %0, i64 144
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  %.not18 = icmp eq ptr %19, null
  br i1 %.not18, label %.thread, label %20

20:                                               ; preds = %17
  %21 = tail call zeroext i8 @pbuf_free(ptr noundef nonnull %19) #3
  store ptr null, ptr %18, align 8, !tbaa !14
  br label %.thread

22:                                               ; preds = %10
  %.not19 = icmp eq i32 %2, 0
  br i1 %.not19, label %.thread, label %23

23:                                               ; preds = %22
  switch i32 %8, label %.thread [
    i32 3, label %24
    i32 4, label %24
    i32 7, label %24
  ]

24:                                               ; preds = %23, %23, %23
  %25 = tail call signext i8 @tcp_close_shutdown(ptr noundef nonnull %0, i8 noundef zeroext 0)
  br label %.thread

.thread:                                          ; preds = %20, %17, %22, %23, %6, %24, %15, %4
  %.0 = phi i8 [ %16, %15 ], [ %25, %24 ], [ -16, %4 ], [ -11, %6 ], [ -11, %23 ], [ 0, %22 ], [ 0, %17 ], [ 0, %20 ]
  ret i8 %.0
}

declare zeroext i8 @pbuf_free(ptr noundef) local_unnamed_addr #2

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 = { 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 32}
!6 = !{!"tcp_pcb", !7, i64 0, !7, i64 4, !9, i64 8, !9, i64 9, !9, i64 10, !9, i64 11, !11, i64 16, !11, i64 24, !8, i64 32, !9, i64 36, !12, i64 38, !12, i64 40, !12, i64 42, !9, i64 44, !9, i64 45, !9, i64 46, !8, i64 48, !8, i64 52, !12, i64 56, !12, i64 58, !8, i64 60, !12, i64 64, !12, i64 66, !8, i64 68, !8, i64 72, !12, i64 76, !12, i64 78, !12, i64 80, !9, i64 82, !9, i64 83, !8, i64 84, !12, i64 88, !12, i64 90, !8, i64 92, !8, i64 96, !8, i64 100, !8, i64 104, !8, i64 108, !12, i64 112, !12, i64 114, !12, i64 116, !12, i64 118, !12, i64 120, !12, i64 122, !11, i64 128, !11, i64 136, !11, i64 144, !11, i64 152, !11, i64 160, !11, i64 168, !11, i64 176, !11, i64 184, !11, i64 192, !8, i64 200, !9, i64 204, !9, i64 205, !9, i64 206, !9, i64 207}
!7 = !{!"ip4_addr", !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"short", !9, i64 0}
!13 = !{!6, !12, i64 42}
!14 = !{!6, !11, i64 144}


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