; LLVM IR from upupming/algorithm :: AdvancedLevel_C++/1028. List Sorting (25).ll (Z4cmp14NODES_)

; 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.NODE = type { i32, i32, [10 x i8] }

@c = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z4cmp14NODES_(ptr noundef byval(%struct.NODE) align 8 %0, ptr noundef byval(%struct.NODE) align 8 %1) #0 {
  %3 = alloca i32, align 4
  %4 = load i32, ptr @c, align 4, !tbaa !5
  %5 = icmp eq i32 %4, 1
  br i1 %5, label %6, label %13

6:                                                ; preds = %2
  %7 = getelementptr inbounds %struct.NODE, ptr %0, i32 0, i32 0
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds %struct.NODE, ptr %1, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = icmp slt i32 %8, %10
  %12 = zext i1 %11 to i32
  store i32 %12, ptr %3, align 4
  br label %58

13:                                               ; preds = %2
  %14 = load i32, ptr @c, align 4, !tbaa !5
  %15 = icmp eq i32 %14, 2
  br i1 %15, label %16, label %38

16:                                               ; preds = %13
  %17 = getelementptr inbounds %struct.NODE, ptr %0, i32 0, i32 2
  %18 = getelementptr inbounds [10 x i8], ptr %17, i64 0, i64 0
  %19 = getelementptr inbounds %struct.NODE, ptr %1, i32 0, i32 2
  %20 = getelementptr inbounds [10 x i8], ptr %19, i64 0, i64 0
  %21 = call i32 @strcmp(ptr noundef %18, ptr noundef %20) #2
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %30

23:                                               ; preds = %16
  %24 = getelementptr inbounds %struct.NODE, ptr %0, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.NODE, ptr %1, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !9
  %28 = icmp slt i32 %25, %27
  %29 = zext i1 %28 to i32
  store i32 %29, ptr %3, align 4
  br label %58

30:                                               ; preds = %16
  %31 = getelementptr inbounds %struct.NODE, ptr %0, i32 0, i32 2
  %32 = getelementptr inbounds [10 x i8], ptr %31, i64 0, i64 0
  %33 = getelementptr inbounds %struct.NODE, ptr %1, i32 0, i32 2
  %34 = getelementptr inbounds [10 x i8], ptr %33, i64 0, i64 0
  %35 = call i32 @strcmp(ptr noundef %32, ptr noundef %34) #2
  %36 = icmp sle i32 %35, 0
  %37 = zext i1 %36 to i32
  store i32 %37, ptr %3, align 4
  br label %58

38:                                               ; preds = %13
  %39 = getelementptr inbounds %struct.NODE, ptr %0, i32 0, i32 1
  %40 = load i32, ptr %39, align 4, !tbaa !11
  %41 = getelementptr inbounds %struct.NODE, ptr %1, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !11
  %43 = icmp eq i32 %40, %42
  br i1 %43, label %44, label %51

44:                                               ; preds = %38
  %45 = getelementptr inbounds %struct.NODE, ptr %0, i32 0, i32 0
  %46 = load i32, ptr %45, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.NODE, ptr %1, i32 0, i32 0
  %48 = load i32, ptr %47, align 8, !tbaa !9
  %49 = icmp slt i32 %46, %48
  %50 = zext i1 %49 to i32
  store i32 %50, ptr %3, align 4
  br label %58

51:                                               ; preds = %38
  %52 = getelementptr inbounds %struct.NODE, ptr %0, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !11
  %54 = getelementptr inbounds %struct.NODE, ptr %1, i32 0, i32 1
  %55 = load i32, ptr %54, align 4, !tbaa !11
  %56 = icmp sle i32 %53, %55
  %57 = zext i1 %56 to i32
  store i32 %57, ptr %3, align 4
  br label %58

58:                                               ; preds = %51, %44, %30, %23, %6
  %59 = load i32, ptr %3, align 4
  ret i32 %59
}

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

attributes #0 = { mustprogress 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 #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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS4NODE", !6, i64 0, !6, i64 4, !7, i64 8}
!11 = !{!10, !6, i64 4}


; 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.NODE = type { i32, i32, [10 x i8] }

@c = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef range(i32 0, 2) i32 @_Z4cmp14NODES_(ptr nocapture noundef readonly byval(%struct.NODE) align 8 %0, ptr nocapture noundef readonly byval(%struct.NODE) align 8 %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @c, align 4, !tbaa !5
  switch i32 %3, label %19 [
    i32 1, label %4
    i32 2, label %8
  ]

4:                                                ; preds = %2
  %5 = load i32, ptr %0, align 8, !tbaa !9
  %6 = load i32, ptr %1, align 8, !tbaa !9
  %7 = icmp slt i32 %5, %6
  br label %31

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %9, ptr noundef nonnull dereferenceable(1) %10) #2
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %17

13:                                               ; preds = %8
  %14 = load i32, ptr %0, align 8, !tbaa !9
  %15 = load i32, ptr %1, align 8, !tbaa !9
  %16 = icmp slt i32 %14, %15
  br label %31

17:                                               ; preds = %8
  %18 = icmp slt i32 %11, 1
  br label %31

19:                                               ; preds = %2
  %20 = getelementptr inbounds i8, ptr %0, i64 4
  %21 = load i32, ptr %20, align 4, !tbaa !11
  %22 = getelementptr inbounds i8, ptr %1, i64 4
  %23 = load i32, ptr %22, align 4, !tbaa !11
  %24 = icmp eq i32 %21, %23
  br i1 %24, label %25, label %29

25:                                               ; preds = %19
  %26 = load i32, ptr %0, align 8, !tbaa !9
  %27 = load i32, ptr %1, align 8, !tbaa !9
  %28 = icmp slt i32 %26, %27
  br label %31

29:                                               ; preds = %19
  %30 = icmp sle i32 %21, %23
  br label %31

31:                                               ; preds = %29, %25, %17, %13, %4
  %.0.in = phi i1 [ %7, %4 ], [ %16, %13 ], [ %18, %17 ], [ %28, %25 ], [ %30, %29 ]
  %.0 = zext i1 %.0.in to i32
  ret i32 %.0
}

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

attributes #0 = { 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 #1 = { 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 #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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS4NODE", !6, i64 0, !6, i64 4, !7, i64 8}
!11 = !{!10, !6, i64 4}


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