#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *, ...);
int stub1(int);
int stub2(int);
void test_r_(char *r_name, int (*r_func)(int)) {
  printf("testing %s():\n", r_name);
  for (int i = 0; i < 3; i++) {
    printf("\t%s(%d) = %d\n", r_name, i, (*r_func)(i));
  }
  return;
}


x86 assembly (clang, -O0):
<test_r_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xed5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    117f <test_r_+0x6f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%edi
call   *%rax
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    %eax,%ecx
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1139 <test_r_+0x29>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_r_>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xede(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
call   *%r14
lea    0xed7(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   *%r14
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x2,%edi
call   *%r14
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
mov    %eax,%ecx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"testing %s():\0A\00"
@.str.1 = [14 x i8] c"\09%s(%d) = %d\0A\00"
define void @test_r_(i8* %0, i32 (i32)* %1) {
%3 = alloca i8*
%4 = alloca i32 (i32)*
%5 = alloca i32
store i8* %0, i8** %3
store i32 (i32)* %1, i32 (i32)** %4
%6 = load i8*, i8** %3
%7 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %6)
store i32 0, i32* %5
br label %8
8: ; preds = %18, %2
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = load i8*, i8** %3
%13 = load i32, i32* %5
%14 = load i32 (i32)*, i32 (i32)** %4
%15 = load i32, i32* %5
%16 = call i32 %14(i32 %15)
%17 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32 %13, i32 %16)
br label %18
18: ; preds = %11
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
store i32 %20, i32* %5
br label %8
21: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"testing %s():\0A\00"
@.str.1 = [14 x i8] c"\09%s(%d) = %d\0A\00"
define void @test_r_(i8* %0, i32 (i32)* nocapture %1) {
%3 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = tail call i32 %1(i32 0)
%5 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 0, i32 %4)
%6 = tail call i32 %1(i32 1)
%7 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 1, i32 %6)
%8 = tail call i32 %1(i32 2)
%9 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 2, i32 %8)
ret void
}