; LLVM IR from rantala/string-sorting :: src (sortstring)

; 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.anon = type { ptr, ptr, i8, i32 }
%struct.routine = type { ptr, ptr, ptr, i8 }

@.str = external hidden unnamed_addr constant [11 x i8], align 1
@opts = external hidden global %struct.anon, align 8
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @run(ptr noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !11
  %8 = call i32 @puts(ptr noundef @.str)
  %9 = load i8, ptr getelementptr inbounds (%struct.anon, ptr @opts, i32 0, i32 2), align 8
  %10 = lshr i8 %9, 2
  %11 = and i8 %10, 1
  %12 = zext i8 %11 to i32
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  call void @opcontrol_start()
  br label %15

15:                                               ; preds = %14, %3
  %16 = load i32, ptr getelementptr inbounds (%struct.anon, ptr @opts, i32 0, i32 3), align 4, !tbaa !13
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %18, label %20

18:                                               ; preds = %15
  %19 = load i32, ptr getelementptr inbounds (%struct.anon, ptr @opts, i32 0, i32 3), align 4, !tbaa !13
  call void @perf_control_enable(i32 noundef %19)
  br label %20

20:                                               ; preds = %18, %15
  call void @timing_start()
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.routine, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load i64, ptr %6, align 8, !tbaa !9
  call void %23(ptr noundef %24, i64 noundef %25)
  call void @timing_stop()
  %26 = load i8, ptr getelementptr inbounds (%struct.anon, ptr @opts, i32 0, i32 2), align 8
  %27 = lshr i8 %26, 2
  %28 = and i8 %27, 1
  %29 = zext i8 %28 to i32
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %20
  call void @opcontrol_stop()
  br label %32

32:                                               ; preds = %31, %20
  %33 = load i32, ptr getelementptr inbounds (%struct.anon, ptr @opts, i32 0, i32 3), align 4, !tbaa !13
  %34 = icmp sgt i32 %33, 0
  br i1 %34, label %35, label %37

35:                                               ; preds = %32
  %36 = load i32, ptr getelementptr inbounds (%struct.anon, ptr @opts, i32 0, i32 3), align 4, !tbaa !13
  call void @perf_control_disable(i32 noundef %36)
  br label %37

37:                                               ; preds = %35, %32
  call void @print_timing_results()
  %38 = load i8, ptr getelementptr inbounds (%struct.anon, ptr @opts, i32 0, i32 2), align 8
  %39 = lshr i8 %38, 1
  %40 = and i8 %39, 1
  %41 = zext i8 %40 to i32
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %53

43:                                               ; preds = %37
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load i64, ptr %6, align 8, !tbaa !9
  %46 = call i32 @check_result(ptr noundef %44, i64 noundef %45)
  store i32 %46, ptr %7, align 4, !tbaa !11
  %47 = load i32, ptr %7, align 4, !tbaa !11
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %52

49:                                               ; preds = %43
  %50 = load ptr, ptr @stderr, align 8, !tbaa !5
  %51 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %50, ptr noundef @.str.1) #5
  br label %52

52:                                               ; preds = %49, %43
  br label %53

53:                                               ; preds = %52, %37
  %54 = load i8, ptr getelementptr inbounds (%struct.anon, ptr @opts, i32 0, i32 2), align 8
  %55 = lshr i8 %54, 3
  %56 = and i8 %55, 1
  %57 = zext i8 %56 to i32
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %62

59:                                               ; preds = %53
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = load i64, ptr %6, align 8, !tbaa !9
  call void @write_result(ptr noundef %60, i64 noundef %61)
  br label %62

62:                                               ; preds = %59, %53
  %63 = load i32, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  ret i32 %63
}

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

declare i32 @puts(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @opcontrol_start() #0

; Function Attrs: nounwind uwtable
declare hidden void @perf_control_enable(i32 noundef) #0

declare void @timing_start() #2

declare void @timing_stop() #2

; Function Attrs: nounwind uwtable
declare hidden void @opcontrol_stop() #0

; Function Attrs: nounwind uwtable
declare hidden void @perf_control_disable(i32 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @print_timing_results() #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @check_result(ptr noundef, i64 noundef) #3

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #4

; Function Attrs: nounwind uwtable
declare hidden void @write_result(ptr noundef, i64 noundef) #0

; 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 = { "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 = { inlinehint 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 "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 #5 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 20}
!14 = !{!"", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 16, !12, i64 16, !12, i64 16, !12, i64 16, !12, i64 16, !12, i64 16, !12, i64 16, !12, i64 20}
!15 = !{!16, !6, i64 0}
!16 = !{!"routine", !6, i64 0, !6, i64 8, !6, i64 16, !12, i64 24}


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

@.str = external hidden unnamed_addr constant [11 x i8], align 1
@opts = external hidden local_unnamed_addr global %struct.anon, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @run(ptr nocapture noundef readonly %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str)
  %5 = load i8, ptr getelementptr inbounds (i8, ptr @opts, i64 16), align 8
  %6 = and i8 %5, 4
  %.not = icmp eq i8 %6, 0
  br i1 %.not, label %8, label %7

7:                                                ; preds = %3
  tail call void @opcontrol_start()
  br label %8

8:                                                ; preds = %7, %3
  %9 = load i32, ptr getelementptr inbounds (i8, ptr @opts, i64 20), align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %8
  tail call void @perf_control_enable(i32 noundef %9)
  br label %12

12:                                               ; preds = %11, %8
  tail call void @timing_start() #4
  %13 = load ptr, ptr %0, align 8, !tbaa !11
  tail call void %13(ptr noundef %1, i64 noundef %2) #4
  tail call void @timing_stop() #4
  %14 = load i8, ptr getelementptr inbounds (i8, ptr @opts, i64 16), align 8
  %15 = and i8 %14, 4
  %.not11 = icmp eq i8 %15, 0
  br i1 %.not11, label %17, label %16

16:                                               ; preds = %12
  tail call void @opcontrol_stop()
  br label %17

17:                                               ; preds = %16, %12
  %18 = load i32, ptr getelementptr inbounds (i8, ptr @opts, i64 20), align 4, !tbaa !5
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  tail call void @perf_control_disable(i32 noundef %18)
  br label %21

21:                                               ; preds = %20, %17
  tail call void @print_timing_results()
  %22 = load i8, ptr getelementptr inbounds (i8, ptr @opts, i64 16), align 8
  %23 = and i8 %22, 2
  %.not12 = icmp eq i8 %23, 0
  br i1 %.not12, label %30, label %24

24:                                               ; preds = %21
  %25 = tail call i32 @check_result(ptr noundef %1, i64 noundef %2)
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %30

27:                                               ; preds = %24
  %28 = load ptr, ptr @stderr, align 8, !tbaa !13
  %29 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull @.str.1) #5
  br label %30

30:                                               ; preds = %24, %27, %21
  %.0 = phi i32 [ 0, %27 ], [ %25, %24 ], [ 0, %21 ]
  %31 = load i8, ptr getelementptr inbounds (i8, ptr @opts, i64 16), align 8
  %32 = and i8 %31, 8
  %.not13 = icmp eq i8 %32, 0
  br i1 %.not13, label %34, label %33

33:                                               ; preds = %30
  tail call void @write_result(ptr noundef %1, i64 noundef %2)
  br label %34

34:                                               ; preds = %33, %30
  ret i32 %.0
}

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

; Function Attrs: nounwind uwtable
declare hidden void @opcontrol_start() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @perf_control_enable(i32 noundef) local_unnamed_addr #0

declare void @timing_start() local_unnamed_addr #2

declare void @timing_stop() local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @opcontrol_stop() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @perf_control_disable(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @print_timing_results() local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @check_result(ptr noundef, i64 noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
declare hidden void @write_result(ptr noundef, i64 noundef) local_unnamed_addr #0

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 = { 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 = { inlinehint 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 }
attributes #5 = { cold 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, !10, i64 20}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 16, !10, i64 16, !10, i64 16, !10, i64 16, !10, i64 16, !10, i64 16, !10, i64 16, !10, i64 20}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"routine", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24}
!13 = !{!7, !7, i64 0}


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