; LLVM IR from kala13x/libxutils :: tools (xtop)

; 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.XArrayData = type { ptr, ptr, i64, i32 }
%struct.xmon_args_ = type { ptr, i8, i8, i8, i8, [4096 x i8], [4096 x i8], [256 x i8], [256 x i8], [2048 x i8], [2048 x i8], i64, i16, i16, i16, i8, i32 }
%struct.XNetIface = type { i64, i64, i64, i64, i16, i64, i64, i64, i64, i64, i32, i8, [256 x i8], [64 x i8], [64 x i8], [128 x [256 x i8]] }

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(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 i32 @XTOPApp_CompareIFaces(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = 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
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %14, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.XArrayData, ptr %15, i32 0, i32 1
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  store ptr %17, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.XArrayData, ptr %18, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  store ptr %20, ptr %10, align 8, !tbaa !5
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.xmon_args_, ptr %21, i32 0, i32 15
  %23 = load i8, ptr %22, align 2, !tbaa !13
  %24 = zext i8 %23 to i32
  %25 = icmp eq i32 %24, 4
  br i1 %25, label %26, label %38

26:                                               ; preds = %3
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.XNetIface, ptr %27, i32 0, i32 12
  %29 = getelementptr inbounds [256 x i8], ptr %28, i64 0, i64 0
  %30 = call i64 @strlen(ptr noundef %29) #4
  %31 = trunc i64 %30 to i32
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.XNetIface, ptr %32, i32 0, i32 12
  %34 = getelementptr inbounds [256 x i8], ptr %33, i64 0, i64 0
  %35 = call i64 @strlen(ptr noundef %34) #4
  %36 = trunc i64 %35 to i32
  %37 = sub nsw i32 %31, %36
  store i32 %37, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %87

38:                                               ; preds = %3
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.xmon_args_, ptr %39, i32 0, i32 15
  %41 = load i8, ptr %40, align 2, !tbaa !13
  %42 = zext i8 %41 to i32
  %43 = icmp eq i32 %42, 3
  br i1 %43, label %44, label %52

44:                                               ; preds = %38
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.XNetIface, ptr %45, i32 0, i32 12
  %47 = getelementptr inbounds [256 x i8], ptr %46, i64 0, i64 0
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.XNetIface, ptr %48, i32 0, i32 12
  %50 = getelementptr inbounds [256 x i8], ptr %49, i64 0, i64 0
  %51 = call i32 @strcmp(ptr noundef %47, ptr noundef %50) #4
  store i32 %51, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %87

52:                                               ; preds = %38
  br label %53

53:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.XNetIface, ptr %54, i32 0, i32 1
  %56 = load i64, ptr %55, align 8, !tbaa !16
  %57 = trunc i64 %56 to i32
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.XNetIface, ptr %58, i32 0, i32 3
  %60 = load i64, ptr %59, align 8, !tbaa !18
  %61 = trunc i64 %60 to i32
  %62 = add nsw i32 %57, %61
  store i32 %62, ptr %12, align 4, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.XNetIface, ptr %63, i32 0, i32 1
  %65 = load i64, ptr %64, align 8, !tbaa !16
  %66 = trunc i64 %65 to i32
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.XNetIface, ptr %67, i32 0, i32 3
  %69 = load i64, ptr %68, align 8, !tbaa !18
  %70 = trunc i64 %69 to i32
  %71 = add nsw i32 %66, %70
  store i32 %71, ptr %13, align 4, !tbaa !19
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.xmon_args_, ptr %72, i32 0, i32 15
  %74 = load i8, ptr %73, align 2, !tbaa !13
  %75 = zext i8 %74 to i32
  %76 = icmp eq i32 %75, 1
  br i1 %76, label %77, label %81

77:                                               ; preds = %53
  %78 = load i32, ptr %13, align 4, !tbaa !19
  %79 = load i32, ptr %12, align 4, !tbaa !19
  %80 = sub nsw i32 %78, %79
  br label %85

81:                                               ; preds = %53
  %82 = load i32, ptr %12, align 4, !tbaa !19
  %83 = load i32, ptr %13, align 4, !tbaa !19
  %84 = sub nsw i32 %82, %83
  br label %85

85:                                               ; preds = %81, %77
  %86 = phi i32 [ %80, %77 ], [ %84, %81 ]
  store i32 %86, ptr %4, align 4
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %87

87:                                               ; preds = %85, %44, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %88 = load i32, ptr %4, align 4
  ret i32 %88
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 }
attributes #4 = { 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, !6, i64 8}
!10 = !{!"XArrayData", !6, i64 0, !6, i64 8, !11, i64 16, !12, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !7, i64 12830}
!14 = !{!"xmon_args_", !6, i64 0, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !7, i64 12, !7, i64 4108, !7, i64 8204, !7, i64 8460, !7, i64 8716, !7, i64 10764, !11, i64 12816, !15, i64 12824, !15, i64 12826, !15, i64 12828, !7, i64 12830, !12, i64 12832}
!15 = !{!"short", !7, i64 0}
!16 = !{!17, !11, i64 8}
!17 = !{!"XNetIface", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !15, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !12, i64 80, !7, i64 84, !7, i64 85, !7, i64 341, !7, i64 405, !7, i64 469}
!18 = !{!17, !11, i64 24}
!19 = !{!12, !12, 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"

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local i32 @XTOPApp_CompareIFaces(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %2, i64 12830
  %9 = load i8, ptr %8, align 2, !tbaa !12
  switch i8 %9, label %22 [
    i8 4, label %10
    i8 3, label %18
  ]

10:                                               ; preds = %3
  %11 = getelementptr inbounds i8, ptr %5, i64 85
  %12 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %11) #2
  %13 = trunc i64 %12 to i32
  %14 = getelementptr inbounds i8, ptr %7, i64 85
  %15 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %14) #2
  %16 = trunc i64 %15 to i32
  %17 = sub nsw i32 %13, %16
  br label %41

18:                                               ; preds = %3
  %19 = getelementptr inbounds i8, ptr %5, i64 85
  %20 = getelementptr inbounds i8, ptr %7, i64 85
  %21 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %19, ptr noundef nonnull dereferenceable(1) %20) #2
  br label %41

22:                                               ; preds = %3
  %23 = getelementptr inbounds i8, ptr %5, i64 8
  %24 = load i64, ptr %23, align 8, !tbaa !15
  %25 = trunc i64 %24 to i32
  %26 = getelementptr inbounds i8, ptr %5, i64 24
  %27 = load i64, ptr %26, align 8, !tbaa !17
  %28 = trunc i64 %27 to i32
  %29 = add nsw i32 %28, %25
  %30 = getelementptr inbounds i8, ptr %7, i64 8
  %31 = load i64, ptr %30, align 8, !tbaa !15
  %32 = trunc i64 %31 to i32
  %33 = getelementptr inbounds i8, ptr %7, i64 24
  %34 = load i64, ptr %33, align 8, !tbaa !17
  %35 = trunc i64 %34 to i32
  %36 = add nsw i32 %35, %32
  %37 = icmp eq i8 %9, 1
  %38 = sub nsw i32 %36, %29
  %39 = sub nsw i32 %29, %36
  %40 = select i1 %37, i32 %38, i32 %39
  br label %41

41:                                               ; preds = %22, %18, %10
  %.0 = phi i32 [ %17, %10 ], [ %21, %18 ], [ %40, %22 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #0

attributes #0 = { 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 #1 = { mustprogress nofree nounwind willreturn 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" }
attributes #2 = { 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, !7, i64 8}
!6 = !{!"XArrayData", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!13, !8, i64 12830}
!13 = !{!"xmon_args_", !7, i64 0, !8, i64 8, !8, i64 9, !8, i64 10, !8, i64 11, !8, i64 12, !8, i64 4108, !8, i64 8204, !8, i64 8460, !8, i64 8716, !8, i64 10764, !10, i64 12816, !14, i64 12824, !14, i64 12826, !14, i64 12828, !8, i64 12830, !11, i64 12832}
!14 = !{!"short", !8, i64 0}
!15 = !{!16, !10, i64 8}
!16 = !{!"XNetIface", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !14, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !11, i64 80, !8, i64 84, !8, i64 85, !8, i64 341, !8, i64 405, !8, i64 469}
!17 = !{!16, !10, i64 24}


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