1  /* { dg-do compile } */
       2  /* { dg-options "-O2 -fcf-protection" } */
       3  /* { dg-require-ifunc "" } */
       4  /* { dg-final { scan-assembler-times {\mendbr} 4 } } */
       5  
       6  int resolver_fn = 0;
       7  int resolved_fn = 0;
       8  
       9  static inline void
      10  do_it_right_at_runtime_A (void)
      11  {
      12    resolved_fn++;
      13  }
      14  
      15  static inline void
      16  do_it_right_at_runtime_B (void)
      17  {
      18    resolved_fn++;
      19  }
      20  
      21  static inline void do_it_right_at_runtime (void);
      22  
      23  void do_it_right_at_runtime (void)
      24    __attribute__ ((ifunc ("resolve_do_it_right_at_runtime")));
      25  
      26  extern int r;
      27  static void (*resolve_do_it_right_at_runtime (void)) (void)
      28  {
      29    resolver_fn++;
      30  
      31    typeof(do_it_right_at_runtime) *func;
      32    if (r & 1)
      33      func = do_it_right_at_runtime_A;
      34    else
      35      func = do_it_right_at_runtime_B;
      36  
      37    return (void *) func;
      38  }
      39  
      40  int
      41  main ()
      42  {
      43    do_it_right_at_runtime ();
      44    return 0;
      45  }