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

; 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.netif = type { ptr, %struct.ip4_addr, %struct.ip4_addr, %struct.ip4_addr, ptr, ptr, ptr, ptr, ptr, [1 x ptr], i16, [6 x i8], i8, i8, [2 x i8], i8, i8 }
%struct.ip4_addr = type { i32 }

@netif_list = external dso_local global ptr, align 8

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

; 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 ptr @netif_get_by_index(i8 noundef zeroext %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store i8 %0, ptr %3, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %6 = load i8, ptr %3, align 1, !tbaa !5
  %7 = zext i8 %6 to i32
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %9, label %33

9:                                                ; preds = %1
  %10 = load ptr, ptr @netif_list, align 8, !tbaa !8
  store ptr %10, ptr %4, align 8, !tbaa !8
  br label %11

11:                                               ; preds = %28, %9
  %12 = load ptr, ptr %4, align 8, !tbaa !8
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %32

14:                                               ; preds = %11
  %15 = load i8, ptr %3, align 1, !tbaa !5
  %16 = zext i8 %15 to i32
  %17 = load ptr, ptr %4, align 8, !tbaa !8
  %18 = getelementptr inbounds %struct.netif, ptr %17, i32 0, i32 15
  %19 = load i8, ptr %18, align 4, !tbaa !10
  %20 = zext i8 %19 to i32
  %21 = add nsw i32 %20, 1
  %22 = trunc i32 %21 to i8
  %23 = zext i8 %22 to i32
  %24 = icmp eq i32 %16, %23
  br i1 %24, label %25, label %27

25:                                               ; preds = %14
  %26 = load ptr, ptr %4, align 8, !tbaa !8
  store ptr %26, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %34

27:                                               ; preds = %14
  br label %28

28:                                               ; preds = %27
  %29 = load ptr, ptr %4, align 8, !tbaa !8
  %30 = getelementptr inbounds %struct.netif, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  store ptr %31, ptr %4, align 8, !tbaa !8
  br label %11, !llvm.loop !16

32:                                               ; preds = %11
  br label %33

33:                                               ; preds = %32, %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %34

34:                                               ; preds = %33, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %35 = load ptr, ptr %2, align 8
  ret ptr %35
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !6, i64 84}
!11 = !{!"netif", !9, i64 0, !12, i64 8, !12, i64 12, !12, i64 16, !9, i64 24, !9, i64 32, !9, i64 40, !9, i64 48, !9, i64 56, !6, i64 64, !14, i64 72, !6, i64 74, !6, i64 80, !6, i64 81, !6, i64 82, !6, i64 84, !6, i64 85}
!12 = !{!"ip4_addr", !13, i64 0}
!13 = !{!"int", !6, i64 0}
!14 = !{!"short", !6, i64 0}
!15 = !{!11, !9, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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

@netif_list = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local ptr @netif_get_by_index(i8 noundef zeroext %0) local_unnamed_addr #0 {
  %.not = icmp eq i8 %0, 0
  br i1 %.not, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %1, %2
  %.0.in = phi ptr [ %.0, %2 ], [ @netif_list, %1 ]
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !5
  %.not8 = icmp eq ptr %.0, null
  br i1 %.not8, label %.loopexit, label %2

2:                                                ; preds = %.preheader
  %3 = getelementptr inbounds i8, ptr %.0, i64 84
  %4 = load i8, ptr %3, align 4, !tbaa !9
  %5 = add i8 %4, 1
  %6 = icmp eq i8 %5, %0
  br i1 %6, label %.loopexit, label %.preheader, !llvm.loop !14

.loopexit:                                        ; preds = %.preheader, %2, %1
  %.06 = phi ptr [ null, %1 ], [ null, %.preheader ], [ %.0, %2 ]
  ret ptr %.06
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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, !7, i64 84}
!10 = !{!"netif", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !7, i64 64, !13, i64 72, !7, i64 74, !7, i64 80, !7, i64 81, !7, i64 82, !7, i64 84, !7, i64 85}
!11 = !{!"ip4_addr", !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass