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

; 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.dns_api_msg = type { ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [181 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [36 x i8], align 1

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

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

declare void @sys_sem_free(ptr noundef) #1

; 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 signext i8 @netconn_gethostbyname(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.dns_api_msg, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  br label %11

11:                                               ; preds = %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %19, label %14

14:                                               ; preds = %11
  br label %15

15:                                               ; preds = %14
  %16 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.25, i32 noundef 1284, ptr noundef @.str.2)
  br label %17

17:                                               ; preds = %15
  br label %18

18:                                               ; preds = %17
  store i8 -16, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %60

19:                                               ; preds = %11
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %30, label %25

25:                                               ; preds = %22
  br label %26

26:                                               ; preds = %25
  %27 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.26, i32 noundef 1285, ptr noundef @.str.2)
  br label %28

28:                                               ; preds = %26
  br label %29

29:                                               ; preds = %28
  store i8 -16, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %60

30:                                               ; preds = %22
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  %33 = getelementptr inbounds %struct.dns_api_msg, ptr %6, i32 0, i32 3
  store ptr %8, ptr %33, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.dns_api_msg, ptr %6, i32 0, i32 2
  store ptr %7, ptr %34, align 8, !tbaa !11
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.dns_api_msg, ptr %6, i32 0, i32 1
  store ptr %35, ptr %36, align 8, !tbaa !12
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.dns_api_msg, ptr %6, i32 0, i32 0
  store ptr %37, ptr %38, align 8, !tbaa !13
  %39 = getelementptr inbounds %struct.dns_api_msg, ptr %6, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  %41 = call signext i8 @sys_sem_new(ptr noundef %40, i8 noundef zeroext 0)
  store i8 %41, ptr %8, align 1, !tbaa !14
  %42 = load i8, ptr %8, align 1, !tbaa !14
  %43 = sext i8 %42 to i32
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %47

45:                                               ; preds = %32
  %46 = load i8, ptr %8, align 1, !tbaa !14
  store i8 %46, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %60

47:                                               ; preds = %32
  %48 = getelementptr inbounds %struct.dns_api_msg, ptr %6, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !11
  %50 = call signext i8 @tcpip_send_msg_wait_sem(ptr noundef @lwip_netconn_do_gethostbyname, ptr noundef %6, ptr noundef %49)
  store i8 %50, ptr %9, align 1, !tbaa !14
  %51 = getelementptr inbounds %struct.dns_api_msg, ptr %6, i32 0, i32 2
  %52 = load ptr, ptr %51, align 8, !tbaa !11
  call void @sys_sem_free(ptr noundef %52)
  %53 = load i8, ptr %9, align 1, !tbaa !14
  %54 = sext i8 %53 to i32
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %58

56:                                               ; preds = %47
  %57 = load i8, ptr %9, align 1, !tbaa !14
  store i8 %57, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %60

58:                                               ; preds = %47
  %59 = load i8, ptr %8, align 1, !tbaa !14
  store i8 %59, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %60

60:                                               ; preds = %58, %56, %45, %29, %18
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %6) #3
  %61 = load i8, ptr %3, align 1
  ret i8 %61
}

declare signext i8 @sys_sem_new(ptr noundef, i8 noundef zeroext) #1

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

declare void @lwip_netconn_do_gethostbyname(ptr noundef) #1

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 = { 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 = { 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, !6, i64 24}
!10 = !{!"dns_api_msg", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!10, !6, i64 16}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !6, i64 0}
!14 = !{!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"

%struct.dns_api_msg = type { ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [181 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [36 x i8], align 1

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

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

declare void @sys_sem_free(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) #0

; Function Attrs: nounwind uwtable
define dso_local signext i8 @netconn_gethostbyname(ptr noundef %0, ptr noundef %1) local_unnamed_addr #3 {
  %3 = alloca %struct.dns_api_msg, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %5) #4
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %6, label %8

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

8:                                                ; preds = %2
  %.not8 = icmp eq ptr %1, null
  br i1 %.not8, label %9, label %11

9:                                                ; preds = %8
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.26, i32 noundef 1285, ptr noundef nonnull @.str.2)
  br label %20

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %3, i64 24
  store ptr %5, ptr %12, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %3, i64 16
  store ptr %4, ptr %13, align 8, !tbaa !10
  %14 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %1, ptr %14, align 8, !tbaa !11
  store ptr %0, ptr %3, align 8, !tbaa !12
  %15 = call signext i8 @sys_sem_new(ptr noundef nonnull %4, i8 noundef zeroext 0) #4
  store i8 %15, ptr %5, align 1, !tbaa !13
  %.not9 = icmp eq i8 %15, 0
  br i1 %.not9, label %16, label %20

16:                                               ; preds = %11
  %17 = call signext i8 @tcpip_send_msg_wait_sem(ptr noundef nonnull @lwip_netconn_do_gethostbyname, ptr noundef nonnull %3, ptr noundef nonnull %4) #4
  %18 = load ptr, ptr %13, align 8, !tbaa !10
  call void @sys_sem_free(ptr noundef %18) #4
  %.not10 = icmp eq i8 %17, 0
  %19 = load i8, ptr %5, align 1
  %spec.select = select i1 %.not10, i8 %19, i8 %17
  br label %20

20:                                               ; preds = %16, %11, %9, %6
  %.0 = phi i8 [ -16, %9 ], [ -16, %6 ], [ %15, %11 ], [ %spec.select, %16 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #4
  ret i8 %.0
}

declare signext i8 @sys_sem_new(ptr noundef, i8 noundef zeroext) local_unnamed_addr #2

declare signext i8 @tcpip_send_msg_wait_sem(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @lwip_netconn_do_gethostbyname(ptr noundef) #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 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 }

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


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