; LLVM IR from DionysiosB/CodeForces :: 0100-0199 (158B-Taxi)

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

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca [5 x i64], align 16
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  call void @llvm.lifetime.start.p0(i64 40, ptr %3) #4
  call void @llvm.memset.p0.i64(ptr align 16 %3, i8 0, i64 40, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  br label %7

7:                                                ; preds = %13, %0
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %4)
  %9 = load i64, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds [5 x i64], ptr %3, i64 0, i64 %9
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %12 = add nsw i64 %11, 1
  store i64 %12, ptr %10, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %7
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = add nsw i64 %14, -1
  store i64 %15, ptr %2, align 8, !tbaa !5
  %16 = icmp ne i64 %15, 0
  br i1 %16, label %7, label %17, !llvm.loop !9

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %18 = getelementptr inbounds [5 x i64], ptr %3, i64 0, i64 4
  %19 = load i64, ptr %18, align 16, !tbaa !5
  store i64 %19, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds [5 x i64], ptr %3, i64 0, i64 3
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %22 = load i64, ptr %5, align 8, !tbaa !5
  %23 = add nsw i64 %22, %21
  store i64 %23, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds [5 x i64], ptr %3, i64 0, i64 3
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %26 = getelementptr inbounds [5 x i64], ptr %3, i64 0, i64 1
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = sub nsw i64 %27, %25
  store i64 %28, ptr %26, align 8, !tbaa !5
  %29 = getelementptr inbounds [5 x i64], ptr %3, i64 0, i64 2
  %30 = load i64, ptr %29, align 16, !tbaa !5
  %31 = sdiv i64 %30, 2
  %32 = getelementptr inbounds [5 x i64], ptr %3, i64 0, i64 2
  %33 = load i64, ptr %32, align 16, !tbaa !5
  %34 = srem i64 %33, 2
  %35 = add nsw i64 %31, %34
  %36 = load i64, ptr %5, align 8, !tbaa !5
  %37 = add nsw i64 %36, %35
  store i64 %37, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds [5 x i64], ptr %3, i64 0, i64 2
  %39 = load i64, ptr %38, align 16, !tbaa !5
  %40 = srem i64 %39, 2
  %41 = mul nsw i64 2, %40
  %42 = getelementptr inbounds [5 x i64], ptr %3, i64 0, i64 1
  %43 = load i64, ptr %42, align 8, !tbaa !5
  %44 = sub nsw i64 %43, %41
  store i64 %44, ptr %42, align 8, !tbaa !5
  %45 = getelementptr inbounds [5 x i64], ptr %3, i64 0, i64 1
  %46 = load i64, ptr %45, align 8, !tbaa !5
  %47 = icmp sgt i64 %46, 0
  br i1 %47, label %48, label %60

48:                                               ; preds = %17
  %49 = getelementptr inbounds [5 x i64], ptr %3, i64 0, i64 1
  %50 = load i64, ptr %49, align 8, !tbaa !5
  %51 = sdiv i64 %50, 4
  %52 = getelementptr inbounds [5 x i64], ptr %3, i64 0, i64 1
  %53 = load i64, ptr %52, align 8, !tbaa !5
  %54 = srem i64 %53, 4
  %55 = icmp sgt i64 %54, 0
  %56 = zext i1 %55 to i64
  %57 = add nsw i64 %51, %56
  %58 = load i64, ptr %5, align 8, !tbaa !5
  %59 = add nsw i64 %58, %57
  store i64 %59, ptr %5, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %48, %17
  %61 = load i64, ptr %5, align 8, !tbaa !5
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %61)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  ret i32 0
}

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

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

declare i32 @printf(ptr noundef, ...) #2

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

attributes #0 = { mustprogress norecurse 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = alloca [5 x i64], align 16
  %3 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %2) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %2, i8 0, i64 40, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  br label %5

5:                                                ; preds = %5, %0
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %3)
  %7 = load i64, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds [5 x i64], ptr %2, i64 0, i64 %7
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = add nsw i64 %9, 1
  store i64 %10, ptr %8, align 8, !tbaa !5
  %11 = load i64, ptr %1, align 8, !tbaa !5
  %12 = add nsw i64 %11, -1
  store i64 %12, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %12, 0
  br i1 %.not, label %13, label %5, !llvm.loop !9

13:                                               ; preds = %5
  %14 = getelementptr inbounds i8, ptr %2, i64 32
  %15 = load i64, ptr %14, align 16, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %2, i64 24
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %2, i64 8
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %2, i64 16
  %21 = load i64, ptr %20, align 16, !tbaa !5
  %22 = sdiv i64 %21, 2
  %23 = srem i64 %21, 2
  %24 = add i64 %17, %15
  %25 = add i64 %24, %23
  %26 = add i64 %25, %22
  %27 = shl nsw i64 %23, 1
  %28 = add i64 %17, %27
  %29 = sub i64 %19, %28
  %30 = icmp sgt i64 %29, 0
  br i1 %30, label %31, label %38

31:                                               ; preds = %13
  %32 = lshr i64 %29, 2
  %33 = and i64 %29, 3
  %34 = icmp ne i64 %33, 0
  %35 = zext i1 %34 to i64
  %36 = add i64 %32, %26
  %37 = add i64 %36, %35
  br label %38

38:                                               ; preds = %31, %13
  %.0 = phi i64 [ %37, %31 ], [ %26, %13 ]
  %39 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %.0)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  ret i32 0
}

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

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

attributes #0 = { mustprogress nofree norecurse 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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