; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/WF/Easy Medium/CSEQ/A.ll (Z4getfx)

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

@f = external dso_local global [1000003 x i64], align 16

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z4getfx(i64 noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  %7 = load i64, ptr %3, align 8, !tbaa !5
  %8 = icmp sle i64 %7, 1
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  store i64 1, ptr %2, align 8
  br label %37

10:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = sdiv i64 %11, 1000003
  store i64 %12, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %13 = load i64, ptr %3, align 8, !tbaa !5
  %14 = srem i64 %13, 1000003
  store i64 %14, ptr %5, align 8, !tbaa !5
  %15 = load i64, ptr %4, align 8, !tbaa !5
  %16 = and i64 %15, 1
  %17 = icmp ne i64 %16, 0
  br i1 %17, label %18, label %28

18:                                               ; preds = %10
  %19 = load i64, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds [1000003 x i64], ptr @f, i64 0, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %22 = load i64, ptr %4, align 8, !tbaa !5
  %23 = call noundef i64 @_Z4getfx(i64 noundef %22)
  %24 = mul nsw i64 %21, %23
  %25 = srem i64 %24, 1000003
  %26 = mul nsw i64 %25, 1000002
  %27 = srem i64 %26, 1000003
  store i64 %27, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %36

28:                                               ; preds = %10
  %29 = load i64, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds [1000003 x i64], ptr @f, i64 0, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !5
  %32 = load i64, ptr %4, align 8, !tbaa !5
  %33 = call noundef i64 @_Z4getfx(i64 noundef %32)
  %34 = mul nsw i64 %31, %33
  %35 = srem i64 %34, 1000003
  store i64 %35, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %36

36:                                               ; preds = %28, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %37

37:                                               ; preds = %36, %9
  %38 = load i64, ptr %2, align 8
  ret i64 %38
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple 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"

@f = external dso_local local_unnamed_addr global [1000003 x i64], align 16

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef range(i64 -1000002, 1000003) i64 @_Z4getfx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = icmp slt i64 %0, 2
  br i1 %2, label %15, label %3

3:                                                ; preds = %1
  %4 = udiv i64 %0, 1000003
  %5 = urem i64 %0, 1000003
  %6 = and i64 %4, 1
  %.not = icmp eq i64 %6, 0
  %7 = getelementptr inbounds [1000003 x i64], ptr @f, i64 0, i64 %5
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = tail call noundef i64 @_Z4getfx(i64 noundef %4)
  %10 = mul nsw i64 %9, %8
  br i1 %.not, label %14, label %11

11:                                               ; preds = %3
  %12 = srem i64 %10, 1000003
  %13 = mul nsw i64 %12, 1000002
  br label %14

14:                                               ; preds = %3, %11
  %.0.in = phi i64 [ %13, %11 ], [ %10, %3 ]
  %.0 = srem i64 %.0.in, 1000003
  br label %15

15:                                               ; preds = %1, %14
  %.1 = phi i64 [ %.0, %14 ], [ 1, %1 ]
  ret i64 %.1
}

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

!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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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