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

; 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.gethostbyname_r_helper = type { [2 x ptr], %struct.ip4_addr, ptr }
%struct.ip4_addr = type { i32 }
%struct.hostent = type { ptr, ptr, i32, i32, ptr }

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

declare signext i8 @netconn_gethostbyname(ptr noundef, ptr noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @lwip_gethostbyname_r(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5) #3 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i8, align 1
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i64 %3, ptr %11, align 8, !tbaa !9
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #5
  %20 = load ptr, ptr %13, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %23

22:                                               ; preds = %6
  store ptr %18, ptr %13, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %22, %6
  %24 = load ptr, ptr %12, align 8, !tbaa !5
  %25 = icmp eq ptr %24, null
  br i1 %25, label %26, label %28

26:                                               ; preds = %23
  %27 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 22, ptr %27, align 4, !tbaa !11
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %19, align 4
  br label %104

28:                                               ; preds = %23
  %29 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr null, ptr %29, align 8, !tbaa !5
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = icmp eq ptr %30, null
  br i1 %31, label %38, label %32

32:                                               ; preds = %28
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = icmp eq ptr %33, null
  br i1 %34, label %38, label %35

35:                                               ; preds = %32
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %40

38:                                               ; preds = %35, %32, %28
  %39 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 22, ptr %39, align 4, !tbaa !11
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %19, align 4
  br label %104

40:                                               ; preds = %35
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = call i64 @strlen(ptr noundef %41) #6
  store i64 %42, ptr %17, align 8, !tbaa !9
  %43 = load i64, ptr %11, align 8, !tbaa !9
  %44 = load i64, ptr %17, align 8, !tbaa !9
  %45 = add i64 %44, 1
  %46 = add i64 %45, 4
  %47 = sub i64 %46, 1
  %48 = add i64 32, %47
  %49 = icmp ult i64 %43, %48
  br i1 %49, label %50, label %52

50:                                               ; preds = %40
  %51 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 34, ptr %51, align 4, !tbaa !11
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %19, align 4
  br label %104

52:                                               ; preds = %40
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = ptrtoint ptr %53 to i64
  %55 = add i64 %54, 4
  %56 = sub i64 %55, 1
  %57 = and i64 %56, -4
  %58 = inttoptr i64 %57 to ptr
  store ptr %58, ptr %15, align 8, !tbaa !5
  %59 = load ptr, ptr %15, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %59, i64 32
  store ptr %60, ptr %16, align 8, !tbaa !5
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = load ptr, ptr %15, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.gethostbyname_r_helper, ptr %62, i32 0, i32 1
  %64 = call signext i8 @netconn_gethostbyname(ptr noundef %61, ptr noundef %63)
  store i8 %64, ptr %14, align 1, !tbaa !13
  %65 = load i8, ptr %14, align 1, !tbaa !13
  %66 = sext i8 %65 to i32
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %68, label %70

68:                                               ; preds = %52
  %69 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 210, ptr %69, align 4, !tbaa !11
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %19, align 4
  br label %104

70:                                               ; preds = %52
  %71 = load ptr, ptr %16, align 8, !tbaa !5
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = load i64, ptr %17, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %71, ptr align 1 %72, i64 %73, i1 false)
  %74 = load ptr, ptr %16, align 8, !tbaa !5
  %75 = load i64, ptr %17, align 8, !tbaa !9
  %76 = getelementptr inbounds i8, ptr %74, i64 %75
  store i8 0, ptr %76, align 1, !tbaa !13
  %77 = load ptr, ptr %15, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.gethostbyname_r_helper, ptr %77, i32 0, i32 1
  %79 = load ptr, ptr %15, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.gethostbyname_r_helper, ptr %79, i32 0, i32 0
  %81 = getelementptr inbounds [2 x ptr], ptr %80, i64 0, i64 0
  store ptr %78, ptr %81, align 8, !tbaa !5
  %82 = load ptr, ptr %15, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.gethostbyname_r_helper, ptr %82, i32 0, i32 0
  %84 = getelementptr inbounds [2 x ptr], ptr %83, i64 0, i64 1
  store ptr null, ptr %84, align 8, !tbaa !5
  %85 = load ptr, ptr %15, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.gethostbyname_r_helper, ptr %85, i32 0, i32 2
  store ptr null, ptr %86, align 8, !tbaa !14
  %87 = load ptr, ptr %16, align 8, !tbaa !5
  %88 = load ptr, ptr %9, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.hostent, ptr %88, i32 0, i32 0
  store ptr %87, ptr %89, align 8, !tbaa !17
  %90 = load ptr, ptr %15, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.gethostbyname_r_helper, ptr %90, i32 0, i32 2
  %92 = load ptr, ptr %9, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.hostent, ptr %92, i32 0, i32 1
  store ptr %91, ptr %93, align 8, !tbaa !19
  %94 = load ptr, ptr %9, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.hostent, ptr %94, i32 0, i32 2
  store i32 2, ptr %95, align 8, !tbaa !20
  %96 = load ptr, ptr %9, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.hostent, ptr %96, i32 0, i32 3
  store i32 4, ptr %97, align 4, !tbaa !21
  %98 = load ptr, ptr %15, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.gethostbyname_r_helper, ptr %98, i32 0, i32 0
  %100 = load ptr, ptr %9, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.hostent, ptr %100, i32 0, i32 4
  store ptr %99, ptr %101, align 8, !tbaa !22
  %102 = load ptr, ptr %9, align 8, !tbaa !5
  %103 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %102, ptr %103, align 8, !tbaa !5
  store i32 0, ptr %7, align 4
  store i32 1, ptr %19, align 4
  br label %104

104:                                              ; preds = %70, %68, %50, %38, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #5
  %105 = load i32, ptr %7, align 4
  ret i32 %105
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { nounwind willreturn memory(read) "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 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !6, i64 24}
!15 = !{!"gethostbyname_r_helper", !7, i64 0, !16, i64 16, !6, i64 24}
!16 = !{!"ip4_addr", !12, i64 0}
!17 = !{!18, !6, i64 0}
!18 = !{!"hostent", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 20, !6, i64 24}
!19 = !{!18, !6, i64 8}
!20 = !{!18, !12, i64 16}
!21 = !{!18, !12, i64 20}
!22 = !{!18, !6, i64 24}


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

declare signext i8 @netconn_gethostbyname(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @lwip_gethostbyname_r(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef writeonly %4, ptr noundef writeonly %5) local_unnamed_addr #2 {
  %7 = icmp eq ptr %5, null
  %8 = icmp eq ptr %4, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %6
  br i1 %7, label %.cont50, label %.else52

.else52:                                          ; preds = %9
  store i32 22, ptr %5, align 4, !tbaa !5
  br label %.cont50

10:                                               ; preds = %6
  store ptr null, ptr %4, align 8, !tbaa !9
  %11 = icmp eq ptr %0, null
  %12 = icmp eq ptr %1, null
  %or.cond = or i1 %11, %12
  %13 = icmp eq ptr %2, null
  %or.cond3 = or i1 %or.cond, %13
  br i1 %or.cond3, label %14, label %15

14:                                               ; preds = %10
  br i1 %7, label %.cont50, label %.else49

.else49:                                          ; preds = %14
  store i32 22, ptr %5, align 4, !tbaa !5
  br label %.cont50

15:                                               ; preds = %10
  %16 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #4
  %17 = add i64 %16, 36
  %18 = icmp ugt i64 %17, %3
  br i1 %18, label %19, label %20

19:                                               ; preds = %15
  br i1 %7, label %.cont50, label %.else46

.else46:                                          ; preds = %19
  store i32 34, ptr %5, align 4, !tbaa !5
  br label %.cont50

20:                                               ; preds = %15
  %21 = ptrtoint ptr %2 to i64
  %22 = add i64 %21, 3
  %23 = and i64 %22, -4
  %24 = inttoptr i64 %23 to ptr
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  %26 = tail call signext i8 @netconn_gethostbyname(ptr noundef nonnull %0, ptr noundef nonnull %25) #5
  %.not = icmp eq i8 %26, 0
  br i1 %.not, label %28, label %27

27:                                               ; preds = %20
  br i1 %7, label %.cont50, label %.else

.else:                                            ; preds = %27
  store i32 210, ptr %5, align 4, !tbaa !5
  br label %.cont50

28:                                               ; preds = %20
  %29 = getelementptr inbounds i8, ptr %24, i64 32
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 %29, ptr nonnull align 1 %0, i64 %16, i1 false)
  %30 = getelementptr inbounds i8, ptr %29, i64 %16
  store i8 0, ptr %30, align 1, !tbaa !11
  store ptr %25, ptr %24, align 8, !tbaa !9
  %31 = getelementptr inbounds i8, ptr %24, i64 8
  store ptr null, ptr %31, align 8, !tbaa !9
  %32 = getelementptr inbounds i8, ptr %24, i64 24
  store ptr null, ptr %32, align 8, !tbaa !12
  store ptr %29, ptr %1, align 8, !tbaa !15
  %33 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr %32, ptr %33, align 8, !tbaa !17
  %34 = getelementptr inbounds i8, ptr %1, i64 16
  store i32 2, ptr %34, align 8, !tbaa !18
  %35 = getelementptr inbounds i8, ptr %1, i64 20
  store i32 4, ptr %35, align 4, !tbaa !19
  %36 = getelementptr inbounds i8, ptr %1, i64 24
  store ptr %24, ptr %36, align 8, !tbaa !20
  store ptr %1, ptr %4, align 8, !tbaa !9
  br label %.cont50

.cont50:                                          ; preds = %.else, %27, %.else46, %19, %.else49, %14, %.else52, %9, %28
  %.0 = phi i32 [ 0, %28 ], [ -1, %9 ], [ -1, %.else52 ], [ -1, %14 ], [ -1, %.else49 ], [ -1, %19 ], [ -1, %.else46 ], [ -1, %27 ], [ -1, %.else ]
  ret i32 %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #3

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 = { mustprogress nocallback nofree 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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 willreturn memory(read) }
attributes #5 = { 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, !10, i64 24}
!13 = !{!"gethostbyname_r_helper", !7, i64 0, !14, i64 16, !10, i64 24}
!14 = !{!"ip4_addr", !6, i64 0}
!15 = !{!16, !10, i64 0}
!16 = !{!"hostent", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 20, !10, i64 24}
!17 = !{!16, !10, i64 8}
!18 = !{!16, !6, i64 16}
!19 = !{!16, !6, i64 20}
!20 = !{!16, !10, i64 24}


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