#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 */
float fabs(float);
int /*<<< orphan*/ rational(float, int, int *, int *);
void ratapp(float x, float *eps, int *num, int *den) {
  float epsloc;
  int inum, iden, i;
  for (i = 1; i < 40; i++) {
    rational(x, i, &inum, &iden);
    epsloc = fabs(x - (float)inum / (float)iden);
    if (epsloc <= *eps)
      break;
  }
  *num = inum;
  *den = iden;
  *eps = epsloc;
}


x86 assembly (clang, -O0):
<ratapp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x1,-0x30(%rbp)
cmpl   $0x28,-0x30(%rbp)
jge    11ae <ratapp+0x8e>
movss  -0x4(%rbp),%xmm0
mov    -0x30(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1040 <rational@plt>
movss  -0x4(%rbp),%xmm0
cvtsi2ssl -0x28(%rbp),%xmm1
cvtsi2ssl -0x2c(%rbp),%xmm2
divss  %xmm2,%xmm1
subss  %xmm1,%xmm0
call   1030 <fabs@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
ucomiss %xmm1,%xmm0
jb     119b <ratapp+0x7b>
jmp    11ae <ratapp+0x8e>
jmp    11a0 <ratapp+0x80>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1140 <ratapp+0x20>
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movss  -0x24(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ratapp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r13
movss  %xmm0,0xc(%rsp)
mov    $0x1,%ebx
lea    0x14(%rsp),%r12
lea    0x10(%rsp),%rbp
nopl   0x0(%rax)
movss  0xc(%rsp),%xmm0
mov    %ebx,%edi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1030 <rational@plt>
mov    0x14(%rsp),%eax
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
mov    0x10(%rsp),%ecx
xorps  %xmm0,%xmm0
cvtsi2ss %ecx,%xmm0
divss  %xmm0,%xmm1
movss  0xc(%rsp),%xmm0
subss  %xmm1,%xmm0
andps  0xe82(%rip),%xmm0
movss  0x0(%r13),%xmm1
ucomiss %xmm0,%xmm1
jae    1193 <ratapp+0x83>
lea    0x1(%rbx),%edx
cmp    $0x27,%ebx
mov    %edx,%ebx
jne    1140 <ratapp+0x30>
mov    %eax,(%r15)
mov    %ecx,(%r14)
movss  %xmm0,0x0(%r13)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @ratapp(float %0, float* %1, i32* %2, i32* %3) {
%5 = alloca float
%6 = alloca float*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca float
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store float %0, float* %5
store float* %1, float** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
store i32 1, i32* %12
br label %13
13: ; preds = %34, %4
%14 = load i32, i32* %12
%15 = icmp slt i32 %14, 40
br i1 %15, label %16, label %37
16: ; preds = %13
%17 = load float, float* %5
%18 = load i32, i32* %12
%19 = call i32 @rational(float %17, i32 %18, i32* %10, i32* %11)
%20 = load float, float* %5
%21 = load i32, i32* %10
%22 = sitofp i32 %21 to float
%23 = load i32, i32* %11
%24 = sitofp i32 %23 to float
%25 = fdiv float %22, %24
%26 = fsub float %20, %25
%27 = call float @fabs(float %26)
store float %27, float* %9
%28 = load float, float* %9
%29 = load float*, float** %6
%30 = load float, float* %29
%31 = fcmp ole float %28, %30
br i1 %31, label %32, label %33
32: ; preds = %16
br label %37
33: ; preds = %16
br label %34
34: ; preds = %33
%35 = load i32, i32* %12
%36 = add nsw i32 %35, 1
store i32 %36, i32* %12
br label %13
37: ; preds = %32, %13
%38 = load i32, i32* %10
%39 = load i32*, i32** %7
store i32 %38, i32* %39
%40 = load i32, i32* %11
%41 = load i32*, i32** %8
store i32 %40, i32* %41
%42 = load float, float* %9
%43 = load float*, float** %6
store float %42, float* %43
ret void
}

LLVM IR (-O2):
define void @ratapp(float %0, float* nocapture %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %5 to i8*
%8 = bitcast i32* %6 to i8*
br label %9
9: ; preds = %9, %4
%10 = phi i32 [ 1, %4 ], [ %21, %9 ]
%11 = call i32 @rational(float %0, i32 %10, i32* %5, i32* %6)
%12 = load i32, i32* %5
%13 = sitofp i32 %12 to float
%14 = load i32, i32* %6
%15 = sitofp i32 %14 to float
%16 = fdiv float %13, %15
%17 = fsub float %0, %16
%18 = call float @llvm.fabs.f32(float %17)
%19 = load float, float* %1
%20 = fcmp ole float %18, %19
%21 = add nuw nsw i32 %10, 1
%22 = icmp eq i32 %21, 40
%23 = select i1 %20, i1 true, i1 %22
br i1 %23, label %24, label %9
24: ; preds = %9
store i32 %12, i32* %2
store i32 %14, i32* %3
store float %18, float* %1
ret void
}