#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 *, int, int);
int stub1(int);
int stub2(int);
int stub3(int);
int somma(int (*f)(int), int start, int end) {
  int val;
  int ris = 0;
  for (val = start; val < end; val++) {
    printf("%3d + %2d\n", ris, (*f)(val));
    ris = ris + (*f)(val);
  }
  return ris;
}


x86 assembly (clang, -O0):
<somma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1182 <somma+0x72>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%edi
call   *%rax
mov    -0x20(%rbp),%esi
mov    %eax,%edx
lea    0xeaa(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%edi
call   *%rax
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112f <somma+0x1f>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<somma>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %ebx,%ebx
cmp    %edx,%esi
jge    1150 <somma+0x40>
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
xor    %ebx,%ebx
lea    0xed1(%rip),%r12
nop
mov    %ebp,%edi
call   *%r15
mov    %r12,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %ebp,%edi
call   *%r15
add    %eax,%ebx
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    1130 <somma+0x20>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"%3d + %2d\0A\00"
define i32 @somma(i32 (i32)* nocapture %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, %2
br i1 %4, label %5, label %14
5: ; preds = %3, %5
%6 = phi i32 [ %11, %5 ], [ 0, %3 ]
%7 = phi i32 [ %12, %5 ], [ %1, %3 ]
%8 = tail call i32 %0(i32 %7)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %8)
%10 = tail call i32 %0(i32 %7)
%11 = add nsw i32 %10, %6
%12 = add i32 %7, 1
%13 = icmp eq i32 %12, %2
br i1 %13, label %14, label %5
14: ; preds = %5, %3
%15 = phi i32 [ 0, %3 ], [ %11, %5 ]
ret i32 %15
}