; LLVM IR from AlgoGenesis/C :: Divide and Conquer/maximum-minimum (program)

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

; Function Attrs: nounwind uwtable
define dso_local i64 @DAC_Min_Max(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca %struct.data, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca %struct.data, align 4
  %10 = alloca %struct.data, align 4
  %11 = alloca i32, align 4
  %12 = alloca %struct.data, align 4
  %13 = alloca %struct.data, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = icmp eq i32 %14, %15
  br i1 %16, label %17, label %30

17:                                               ; preds = %3
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds i32, ptr %18, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = getelementptr inbounds %struct.data, ptr %4, i32 0, i32 1
  store i32 %22, ptr %23, align 4, !tbaa !11
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i32, ptr %24, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = getelementptr inbounds %struct.data, ptr %4, i32 0, i32 0
  store i32 %28, ptr %29, align 4, !tbaa !13
  store i32 1, ptr %11, align 4
  br label %117

30:                                               ; preds = %3
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = sub nsw i32 %32, 1
  %34 = icmp eq i32 %31, %33
  br i1 %34, label %35, label %74

35:                                               ; preds = %30
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i32, ptr %36, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i32, ptr %41, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = icmp slt i32 %40, %45
  br i1 %46, label %47, label %60

47:                                               ; preds = %35
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i32, ptr %48, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !9
  %53 = getelementptr inbounds %struct.data, ptr %4, i32 0, i32 1
  store i32 %52, ptr %53, align 4, !tbaa !11
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load i32, ptr %6, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i32, ptr %54, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !9
  %59 = getelementptr inbounds %struct.data, ptr %4, i32 0, i32 0
  store i32 %58, ptr %59, align 4, !tbaa !13
  br label %73

60:                                               ; preds = %35
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = load i32, ptr %6, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i32, ptr %61, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !9
  %66 = getelementptr inbounds %struct.data, ptr %4, i32 0, i32 1
  store i32 %65, ptr %66, align 4, !tbaa !11
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = load i32, ptr %7, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds i32, ptr %67, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !9
  %72 = getelementptr inbounds %struct.data, ptr %4, i32 0, i32 0
  store i32 %71, ptr %72, align 4, !tbaa !13
  br label %73

73:                                               ; preds = %60, %47
  store i32 1, ptr %11, align 4
  br label %117

74:                                               ; preds = %30
  br label %75

75:                                               ; preds = %74
  %76 = load i32, ptr %6, align 4, !tbaa !9
  %77 = load i32, ptr %7, align 4, !tbaa !9
  %78 = add nsw i32 %76, %77
  %79 = sdiv i32 %78, 2
  store i32 %79, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = load i32, ptr %6, align 4, !tbaa !9
  %82 = load i32, ptr %8, align 4, !tbaa !9
  %83 = call i64 @DAC_Min_Max(ptr noundef %80, i32 noundef %81, i32 noundef %82)
  store i64 %83, ptr %12, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %12, i64 8, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = load i32, ptr %8, align 4, !tbaa !9
  %86 = add nsw i32 %85, 1
  %87 = load i32, ptr %7, align 4, !tbaa !9
  %88 = call i64 @DAC_Min_Max(ptr noundef %84, i32 noundef %86, i32 noundef %87)
  store i64 %88, ptr %13, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %13, i64 8, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  %89 = getelementptr inbounds %struct.data, ptr %9, i32 0, i32 1
  %90 = load i32, ptr %89, align 4, !tbaa !11
  %91 = getelementptr inbounds %struct.data, ptr %10, i32 0, i32 1
  %92 = load i32, ptr %91, align 4, !tbaa !11
  %93 = icmp slt i32 %90, %92
  br i1 %93, label %94, label %98

94:                                               ; preds = %75
  %95 = getelementptr inbounds %struct.data, ptr %10, i32 0, i32 1
  %96 = load i32, ptr %95, align 4, !tbaa !11
  %97 = getelementptr inbounds %struct.data, ptr %4, i32 0, i32 1
  store i32 %96, ptr %97, align 4, !tbaa !11
  br label %102

98:                                               ; preds = %75
  %99 = getelementptr inbounds %struct.data, ptr %9, i32 0, i32 1
  %100 = load i32, ptr %99, align 4, !tbaa !11
  %101 = getelementptr inbounds %struct.data, ptr %4, i32 0, i32 1
  store i32 %100, ptr %101, align 4, !tbaa !11
  br label %102

102:                                              ; preds = %98, %94
  %103 = getelementptr inbounds %struct.data, ptr %9, i32 0, i32 0
  %104 = load i32, ptr %103, align 4, !tbaa !13
  %105 = getelementptr inbounds %struct.data, ptr %10, i32 0, i32 0
  %106 = load i32, ptr %105, align 4, !tbaa !13
  %107 = icmp slt i32 %104, %106
  br i1 %107, label %108, label %112

108:                                              ; preds = %102
  %109 = getelementptr inbounds %struct.data, ptr %9, i32 0, i32 0
  %110 = load i32, ptr %109, align 4, !tbaa !13
  %111 = getelementptr inbounds %struct.data, ptr %4, i32 0, i32 0
  store i32 %110, ptr %111, align 4, !tbaa !13
  br label %116

112:                                              ; preds = %102
  %113 = getelementptr inbounds %struct.data, ptr %10, i32 0, i32 0
  %114 = load i32, ptr %113, align 4, !tbaa !13
  %115 = getelementptr inbounds %struct.data, ptr %4, i32 0, i32 0
  store i32 %114, ptr %115, align 4, !tbaa !13
  br label %116

116:                                              ; preds = %112, %108
  store i32 1, ptr %11, align 4
  br label %117

117:                                              ; preds = %116, %73, %17
  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 4, ptr %8) #3
  %118 = load i64, ptr %4, align 4
  ret i64 %118
}

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"data", !10, i64 0, !10, i64 4}
!13 = !{!12, !10, i64 0}
!14 = !{i64 0, i64 4, !9, i64 4, i64 4, !9}


; 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: nofree nosync nounwind memory(argmem: read) uwtable
define dso_local i64 @DAC_Min_Max(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i32 %1, %2
  br i1 %4, label %5, label %9

5:                                                ; preds = %3
  %6 = sext i32 %1 to i64
  %7 = getelementptr inbounds i32, ptr %0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  br label %25

9:                                                ; preds = %3
  %10 = add nsw i32 %2, -1
  %11 = icmp eq i32 %10, %1
  br i1 %11, label %12, label %19

12:                                               ; preds = %9
  %13 = sext i32 %1 to i64
  %14 = getelementptr inbounds i32, ptr %0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = sext i32 %2 to i64
  %17 = getelementptr inbounds i32, ptr %0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %. = tail call i32 @llvm.smin.i32(i32 %15, i32 %18)
  %.41 = tail call i32 @llvm.smax.i32(i32 %15, i32 %18)
  br label %25

19:                                               ; preds = %9
  %20 = add nsw i32 %2, %1
  %21 = sdiv i32 %20, 2
  %22 = tail call i64 @DAC_Min_Max(ptr noundef %0, i32 noundef %1, i32 noundef %21)
  %.sroa.05.0.extract.trunc = trunc i64 %22 to i32
  %.sroa.57.0.extract.shift = lshr i64 %22, 32
  %.sroa.57.0.extract.trunc = trunc nuw i64 %.sroa.57.0.extract.shift to i32
  %23 = add nsw i32 %21, 1
  %24 = tail call i64 @DAC_Min_Max(ptr noundef %0, i32 noundef %23, i32 noundef %2)
  %.sroa.02.0.extract.trunc = trunc i64 %24 to i32
  %.sroa.5.0.extract.shift = lshr i64 %24, 32
  %.sroa.5.0.extract.trunc = trunc nuw i64 %.sroa.5.0.extract.shift to i32
  %.sroa.5.0.extract.trunc..sroa.57.0.extract.trunc = tail call i32 @llvm.smax.i32(i32 %.sroa.57.0.extract.trunc, i32 %.sroa.5.0.extract.trunc)
  %.sroa.035.1 = tail call i32 @llvm.smin.i32(i32 %.sroa.05.0.extract.trunc, i32 %.sroa.02.0.extract.trunc)
  br label %25

25:                                               ; preds = %19, %12, %5
  %.sroa.035.2 = phi i32 [ %8, %5 ], [ %., %12 ], [ %.sroa.035.1, %19 ]
  %.sroa.6.2 = phi i32 [ %8, %5 ], [ %.41, %12 ], [ %.sroa.5.0.extract.trunc..sroa.57.0.extract.trunc, %19 ]
  %.sroa.6.0.insert.ext = zext i32 %.sroa.6.2 to i64
  %.sroa.6.0.insert.shift = shl nuw i64 %.sroa.6.0.insert.ext, 32
  %.sroa.035.0.insert.ext = zext i32 %.sroa.035.2 to i64
  %.sroa.035.0.insert.insert = or disjoint i64 %.sroa.6.0.insert.shift, %.sroa.035.0.insert.ext
  ret i64 %.sroa.035.0.insert.insert
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #1

attributes #0 = { nofree nosync nounwind memory(argmem: read) 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 speculatable willreturn memory(none) }

!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/C++ TBAA"}


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