; LLVM IR from fcimeson/cbTSP :: cbLKH/SRC (Random)

; 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"

@initialized = external hidden global i32, align 4
@a = external hidden global i32, align 4
@b = external hidden global i32, align 4
@arr = external hidden global [55 x i32], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @Random() #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  %2 = load i32, ptr @initialized, align 4, !tbaa !5
  %3 = icmp ne i32 %2, 0
  br i1 %3, label %5, label %4

4:                                                ; preds = %0
  call void @SRandom(i32 noundef 7913)
  br label %5

5:                                                ; preds = %4, %0
  %6 = load i32, ptr @a, align 4, !tbaa !5
  %7 = add nsw i32 %6, -1
  store i32 %7, ptr @a, align 4, !tbaa !5
  %8 = icmp eq i32 %6, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %5
  store i32 54, ptr @a, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %9, %5
  %11 = load i32, ptr @b, align 4, !tbaa !5
  %12 = add nsw i32 %11, -1
  store i32 %12, ptr @b, align 4, !tbaa !5
  %13 = icmp eq i32 %11, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %10
  store i32 54, ptr @b, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %14, %10
  %16 = load i32, ptr @a, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [55 x i32], ptr @arr, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = load i32, ptr @b, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [55 x i32], ptr @arr, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sub nsw i32 %19, %23
  store i32 %24, ptr %1, align 4, !tbaa !5
  %25 = icmp slt i32 %24, 0
  br i1 %25, label %26, label %29

26:                                               ; preds = %15
  %27 = load i32, ptr %1, align 4, !tbaa !5
  %28 = add nsw i32 %27, 2147483647
  store i32 %28, ptr %1, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %26, %15
  %30 = load i32, ptr %1, align 4, !tbaa !5
  %31 = load i32, ptr @a, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [55 x i32], ptr @arr, i64 0, i64 %32
  store i32 %30, ptr %33, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret i32 %30
}

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

; Function Attrs: nounwind uwtable
declare dso_local void @SRandom(i32 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; 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"

@initialized = external hidden local_unnamed_addr global i32, align 4
@a = external hidden local_unnamed_addr global i32, align 4
@b = external hidden local_unnamed_addr global i32, align 4
@arr = external hidden local_unnamed_addr global [55 x i32], align 16

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, -2147483648) i32 @Random() local_unnamed_addr #0 {
  %1 = load i32, ptr @initialized, align 4, !tbaa !5
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %2, label %3

2:                                                ; preds = %0
  tail call void @SRandom(i32 noundef 7913)
  br label %3

3:                                                ; preds = %2, %0
  %4 = load i32, ptr @a, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  %6 = icmp eq i32 %4, 0
  %spec.store.select = select i1 %6, i32 54, i32 %5
  store i32 %spec.store.select, ptr @a, align 4
  %7 = load i32, ptr @b, align 4, !tbaa !5
  %8 = add nsw i32 %7, -1
  %9 = icmp eq i32 %7, 0
  %spec.store.select1 = select i1 %9, i32 54, i32 %8
  store i32 %spec.store.select1, ptr @b, align 4
  %10 = sext i32 %spec.store.select to i64
  %11 = getelementptr inbounds [55 x i32], ptr @arr, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = sext i32 %spec.store.select1 to i64
  %14 = getelementptr inbounds [55 x i32], ptr @arr, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = sub nsw i32 %12, %15
  %17 = icmp slt i32 %16, 0
  %18 = add nsw i32 %16, 2147483647
  %spec.select = select i1 %17, i32 %18, i32 %16
  store i32 %spec.select, ptr %11, align 4, !tbaa !5
  ret i32 %spec.select
}

; Function Attrs: nounwind uwtable
declare dso_local void @SRandom(i32 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" }

!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,SROAPass,SimplifyCFGPass,TailCallElimPass