; LLVM IR from kazunetakahashi/atcoder :: 201510_201609/1112_codefes2014_relay/I.ll (Z4waitix)

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

@a = external dso_local global [100010 x i32], align 16
@b = external dso_local global [100010 x i32], align 16
@c = external dso_local global [100010 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z4waitix(i32 noundef %0, i64 noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %8 = load i64, ptr %5, align 8, !tbaa !9
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [100010 x i32], ptr @c, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = icmp slt i64 %8, %13
  br i1 %14, label %15, label %21

15:                                               ; preds = %2
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100010 x i32], ptr @c, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  store i64 %20, ptr %3, align 8
  br label %66

21:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %22 = load i64, ptr %5, align 8, !tbaa !9
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100010 x i32], ptr @c, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = sub nsw i64 %22, %27
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100010 x i32], ptr @a, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [100010 x i32], ptr @b, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = add nsw i32 %32, %36
  %38 = sext i32 %37 to i64
  %39 = srem i64 %28, %38
  store i64 %39, ptr %6, align 8, !tbaa !9
  %40 = load i64, ptr %6, align 8, !tbaa !9
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [100010 x i32], ptr @a, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = icmp sge i64 %40, %45
  br i1 %46, label %47, label %63

47:                                               ; preds = %21
  %48 = load i64, ptr %5, align 8, !tbaa !9
  %49 = load i64, ptr %6, align 8, !tbaa !9
  %50 = sub nsw i64 %48, %49
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [100010 x i32], ptr @a, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = add nsw i64 %50, %55
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [100010 x i32], ptr @b, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = add nsw i64 %56, %61
  store i64 %62, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %65

63:                                               ; preds = %21
  %64 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %64, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %65

65:                                               ; preds = %63, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %66

66:                                               ; preds = %65, %15
  %67 = load i64, ptr %3, align 8
  ret i64 %67
}

; 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

attributes #0 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, 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"

@a = external dso_local local_unnamed_addr global [100010 x i32], align 16
@b = external dso_local local_unnamed_addr global [100010 x i32], align 16
@c = external dso_local local_unnamed_addr global [100010 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef range(i64 -8589934591, -9223372036854775808) i64 @_Z4waitix(i32 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [100010 x i32], ptr @c, i64 0, i64 %3
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = icmp sgt i64 %6, %1
  br i1 %7, label %22, label %8

8:                                                ; preds = %2
  %9 = sub nsw i64 %1, %6
  %10 = getelementptr inbounds [100010 x i32], ptr @a, i64 0, i64 %3
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = getelementptr inbounds [100010 x i32], ptr @b, i64 0, i64 %3
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = add nsw i32 %13, %11
  %15 = sext i32 %14 to i64
  %16 = srem i64 %9, %15
  %17 = sext i32 %11 to i64
  %.not = icmp slt i64 %16, %17
  %18 = sext i32 %13 to i64
  %19 = add i64 %17, %1
  %20 = sub i64 %19, %16
  %21 = add nsw i64 %20, %18
  %.0 = select i1 %.not, i64 %1, i64 %21
  br label %22

22:                                               ; preds = %2, %8
  %.1 = phi i64 [ %.0, %8 ], [ %6, %2 ]
  ret i64 %.1
}

attributes #0 = { mustprogress nofree norecurse 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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