#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 */
double my_for(double start, double end, double dif,
              double (*ptr)(double, void *)) {
  double res;
  double i;
  if (ptr == NULL)
    return (0);
  i = start;
  res = 0;
  while ((dif < 0) ? (i > end) : (i < end)) {
    res = ptr(i, NULL);
    i += dif;
  }
  return (res);
}


x86 assembly (clang, -O0):
<my_for>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
mov    %rdi,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1133 <my_for+0x33>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c4 <my_for+0xc4>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    116d <my_for+0x6d>
movsd  -0x38(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x3c(%rbp)
jmp    1186 <my_for+0x86>
movsd  -0x38(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    $0x0,%eax
je     11ba <my_for+0xba>
mov    -0x28(%rbp),%rax
movsd  -0x38(%rbp),%xmm0
xor    %ecx,%ecx
mov    %ecx,%edi
call   *%rax
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1145 <my_for+0x45>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_for>:
test   %rdi,%rdi
je     119b <my_for+0x9b>
movapd %xmm0,%xmm3
xor    %eax,%eax
ucomisd %xmm1,%xmm0
seta   %al
xor    %ecx,%ecx
ucomisd %xmm0,%xmm1
seta   %cl
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
cmova  %eax,%ecx
cmp    $0x1,%cl
jne    119a <my_for+0x9a>
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movsd  %xmm2,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  %xmm3,0x18(%rsp)
movapd %xmm3,%xmm0
xor    %edi,%edi
call   *%rbx
movsd  0x18(%rsp),%xmm3
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
addsd  %xmm2,%xmm3
xor    %eax,%eax
ucomisd %xmm1,%xmm3
seta   %al
xor    %ecx,%ecx
ucomisd %xmm3,%xmm1
seta   %cl
xorpd  %xmm4,%xmm4
ucomisd %xmm2,%xmm4
cmova  %eax,%ecx
test   %cl,%cl
jne    1150 <my_for+0x50>
add    $0x20,%rsp
pop    %rbx
ret
xorps  %xmm0,%xmm0
ret

LLVM IR (-O0):
define double @my_for(double %0, double %1, double %2, double (double, i8*)* %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double (double, i8*)*
%10 = alloca double
%11 = alloca double
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double (double, i8*)* %3, double (double, i8*)** %9
%12 = load double (double, i8*)*, double (double, i8*)** %9
%13 = icmp eq double (double, i8*)* %12, null
br i1 %13, label %14, label %15
14: ; preds = %4
store double 0.000000e+00, double* %5
br label %42
15: ; preds = %4
%16 = load double, double* %6
store double %16, double* %11
store double 0.000000e+00, double* %10
br label %17
17: ; preds = %33, %15
%18 = load double, double* %8
%19 = fcmp olt double %18, 0.000000e+00
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load double, double* %11
%22 = load double, double* %7
%23 = fcmp ogt double %21, %22
%24 = zext i1 %23 to i32
br label %30
25: ; preds = %17
%26 = load double, double* %11
%27 = load double, double* %7
%28 = fcmp olt double %26, %27
%29 = zext i1 %28 to i32
br label %30
30: ; preds = %25, %20
%31 = phi i32 [ %24, %20 ], [ %29, %25 ]
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %30
%34 = load double (double, i8*)*, double (double, i8*)** %9
%35 = load double, double* %11
%36 = call double %34(double %35, i8* null)
store double %36, double* %10
%37 = load double, double* %8
%38 = load double, double* %11
%39 = fadd double %38, %37
store double %39, double* %11
br label %17
40: ; preds = %30
%41 = load double, double* %10
store double %41, double* %5
br label %42
42: ; preds = %40, %14
%43 = load double, double* %5
ret double %43
}

LLVM IR (-O2):
define double @my_for(double %0, double %1, double %2, double (double, i8*)* %3) {
%5 = icmp eq double (double, i8*)* %3, null
br i1 %5, label %18, label %6
6: ; preds = %4
%7 = fcmp olt double %2, 0.000000e+00
%8 = fcmp ogt double %0, %1
%9 = fcmp olt double %0, %1
%10 = select i1 %7, i1 %8, i1 %9
br i1 %10, label %11, label %18
11: ; preds = %6, %11
%12 = phi double [ %14, %11 ], [ %0, %6 ]
%13 = tail call double %3(double %12, i8* null)
%14 = fadd double %12, %2
%15 = fcmp ogt double %14, %1
%16 = fcmp olt double %14, %1
%17 = select i1 %7, i1 %15, i1 %16
br i1 %17, label %11, label %18
18: ; preds = %11, %6, %4
%19 = phi double [ 0.000000e+00, %4 ], [ 0.000000e+00, %6 ], [ %13, %11 ]
ret double %19
}