; LLVM IR from AlgoGenesis/C :: Divide and Conquer/convex hull (convexhull)

; 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.Pair = type { i32, i32 }

@mid = external dso_local global %struct.Pair, align 4

; Function Attrs: nounwind uwtable
declare dso_local i32 @quad(i64) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @compare(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %struct.Pair, align 4
  %9 = alloca %struct.Pair, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = 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 8, ptr %6) #2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %13, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %14, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %15 = getelementptr inbounds %struct.Pair, ptr %8, i32 0, i32 0
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.Pair, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = load i32, ptr @mid, align 4, !tbaa !9
  %20 = sub nsw i32 %18, %19
  store i32 %20, ptr %15, align 4, !tbaa !9
  %21 = getelementptr inbounds %struct.Pair, ptr %8, i32 0, i32 1
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Pair, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !12
  %25 = load i32, ptr getelementptr inbounds (%struct.Pair, ptr @mid, i32 0, i32 1), align 4, !tbaa !12
  %26 = sub nsw i32 %24, %25
  store i32 %26, ptr %21, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %27 = getelementptr inbounds %struct.Pair, ptr %9, i32 0, i32 0
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Pair, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = load i32, ptr @mid, align 4, !tbaa !9
  %32 = sub nsw i32 %30, %31
  store i32 %32, ptr %27, align 4, !tbaa !9
  %33 = getelementptr inbounds %struct.Pair, ptr %9, i32 0, i32 1
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.Pair, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !12
  %37 = load i32, ptr getelementptr inbounds (%struct.Pair, ptr @mid, i32 0, i32 1), align 4, !tbaa !12
  %38 = sub nsw i32 %36, %37
  store i32 %38, ptr %33, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %39 = load i64, ptr %8, align 4
  %40 = call i32 @quad(i64 %39)
  store i32 %40, ptr %10, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %41 = load i64, ptr %9, align 4
  %42 = call i32 @quad(i64 %41)
  store i32 %42, ptr %11, align 4, !tbaa !13
  %43 = load i32, ptr %10, align 4, !tbaa !13
  %44 = load i32, ptr %11, align 4, !tbaa !13
  %45 = icmp ne i32 %43, %44
  br i1 %45, label %46, label %52

46:                                               ; preds = %2
  %47 = load i32, ptr %10, align 4, !tbaa !13
  %48 = load i32, ptr %11, align 4, !tbaa !13
  %49 = icmp slt i32 %47, %48
  %50 = zext i1 %49 to i64
  %51 = select i1 %49, i32 -1, i32 1
  store i32 %51, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %66

52:                                               ; preds = %2
  %53 = getelementptr inbounds %struct.Pair, ptr %8, i32 0, i32 1
  %54 = load i32, ptr %53, align 4, !tbaa !12
  %55 = getelementptr inbounds %struct.Pair, ptr %9, i32 0, i32 0
  %56 = load i32, ptr %55, align 4, !tbaa !9
  %57 = mul nsw i32 %54, %56
  %58 = getelementptr inbounds %struct.Pair, ptr %9, i32 0, i32 1
  %59 = load i32, ptr %58, align 4, !tbaa !12
  %60 = getelementptr inbounds %struct.Pair, ptr %8, i32 0, i32 0
  %61 = load i32, ptr %60, align 4, !tbaa !9
  %62 = mul nsw i32 %59, %61
  %63 = icmp slt i32 %57, %62
  %64 = zext i1 %63 to i64
  %65 = select i1 %63, i32 -1, i32 1
  store i32 %65, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %66

66:                                               ; preds = %52, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %67 = load i32, ptr %3, align 4
  ret i32 %67
}

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!11, !11, 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.Pair = type { i32, i32 }

@mid = external dso_local local_unnamed_addr global %struct.Pair, align 4

; Function Attrs: nounwind uwtable
declare dso_local i32 @quad(i64) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @compare(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = load i32, ptr %0, align 4, !tbaa !5
  %4 = load i32, ptr @mid, align 4, !tbaa !5
  %5 = sub nsw i32 %3, %4
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !10
  %8 = load i32, ptr getelementptr inbounds (i8, ptr @mid, i64 4), align 4, !tbaa !10
  %9 = sub nsw i32 %7, %8
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = sub nsw i32 %10, %4
  %12 = getelementptr inbounds i8, ptr %1, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !10
  %14 = sub nsw i32 %13, %8
  %.sroa.57.0.insert.ext = zext i32 %9 to i64
  %.sroa.57.0.insert.shift = shl nuw i64 %.sroa.57.0.insert.ext, 32
  %.sroa.05.0.insert.ext = zext i32 %5 to i64
  %.sroa.05.0.insert.insert = or disjoint i64 %.sroa.57.0.insert.shift, %.sroa.05.0.insert.ext
  %15 = tail call i32 @quad(i64 %.sroa.05.0.insert.insert)
  %.sroa.5.0.insert.ext = zext i32 %14 to i64
  %.sroa.5.0.insert.shift = shl nuw i64 %.sroa.5.0.insert.ext, 32
  %.sroa.0.0.insert.ext = zext i32 %11 to i64
  %.sroa.0.0.insert.insert = or disjoint i64 %.sroa.5.0.insert.shift, %.sroa.0.0.insert.ext
  %16 = tail call i32 @quad(i64 %.sroa.0.0.insert.insert)
  %.not = icmp eq i32 %15, %16
  %17 = mul nsw i32 %11, %9
  %18 = mul nsw i32 %14, %5
  %19 = icmp slt i32 %17, %18
  %20 = icmp slt i32 %15, %16
  %.sink = select i1 %.not, i1 %19, i1 %20
  %21 = select i1 %.sink, i32 -1, i32 1
  ret i32 %21
}

attributes #0 = { 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" }

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


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