Dead Code and Dead Store Elimination

f <- function(n) {
  a <- 24
  b <- 25 # Dead store, as it is not used, nor returned
  c <- 0
  
  for (i in seq_len(n)) {
    c <- c + a * 4
    aux <- c^2 # Dead store, as it is not used, nor returned
    if (FALSE) { # Dead code (maybe evaluate it in another f_opt)
      b <- b + 24 # Dead store, as it never enters
    }
  }
  return(c)
}

f_opt <- function(n) {
  a <- 24
  c <- 0
  
  for (i in seq_len(n)) {
    c <- c + a * 4
  }
  return(c)
}

f_c <- cmpfun(f)
f_opt_c <- cmpfun(f_opt)
n <- 10000
autoplot(microbenchmark(f(n), f_c(n), f_opt(n), f_opt_c(n)))