#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 floor(float);
void float_to_frac(float x, int *numerator, int *denominator) {
  int a = 1, b = 1;
  while (1) {
    float f = (float)a / b;
    if (f < x)
      ++a;
    else if (f > x) {
      ++b;
      a = floor(x * b);
    } else
      break;
  }
  *numerator = a;
  *denominator = b;
}


x86 assembly (clang, -O0):
<float_to_frac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
cvtsi2ssl -0x1c(%rbp),%xmm0
cvtsi2ssl -0x20(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm1
movss  -0x4(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    1167 <float_to_frac+0x57>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a4 <float_to_frac+0x94>
movss  -0x24(%rbp),%xmm0
ucomiss -0x4(%rbp),%xmm0
jbe    119a <float_to_frac+0x8a>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
movss  -0x4(%rbp),%xmm0
cvtsi2ssl -0x20(%rbp),%xmm1
mulss  %xmm1,%xmm0
call   1030 <floor@plt>
mov    %eax,-0x1c(%rbp)
jmp    119f <float_to_frac+0x8f>
jmp    11a9 <float_to_frac+0x99>
jmp    11a4 <float_to_frac+0x94>
jmp    1133 <float_to_frac+0x23>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<float_to_frac>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movaps %xmm0,%xmm2
mov    $0x1,%ebp
mov    $0x1,%eax
movss  %xmm0,0xc(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
nopw   0x0(%rax,%rax,1)
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
divss  %xmm0,%xmm1
ucomiss %xmm1,%xmm2
jbe    1170 <float_to_frac+0x60>
add    $0x1,%eax
jmp    1150 <float_to_frac+0x40>
cs nopw 0x0(%rax,%rax,1)
nop
ucomiss %xmm2,%xmm1
jbe    1190 <float_to_frac+0x80>
add    $0x1,%ebp
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
mulss  %xmm2,%xmm0
call   1030 <floor@plt>
movss  0xc(%rsp),%xmm2
jmp    1140 <float_to_frac+0x30>
mov    %eax,(%rbx)
mov    %ebp,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define void @float_to_frac(float %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
br label %4
4: ; preds = %17, %3
%5 = phi i32 [ %18, %17 ], [ 1, %3 ]
%6 = phi i32 [ %21, %17 ], [ 1, %3 ]
%7 = sitofp i32 %5 to float
br label %8
8: ; preds = %4, %13
%9 = phi i32 [ %14, %13 ], [ %6, %4 ]
%10 = sitofp i32 %9 to float
%11 = fdiv float %10, %7
%12 = fcmp olt float %11, %0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = add nsw i32 %9, 1
br label %8
15: ; preds = %8
%16 = fcmp ogt float %11, %0
br i1 %16, label %17, label %22
17: ; preds = %15
%18 = add nuw nsw i32 %5, 1
%19 = sitofp i32 %18 to float
%20 = fmul float %19, %0
%21 = tail call i32 @floor(float %20)
br label %4
22: ; preds = %15
store i32 %9, i32* %1
store i32 %5, i32* %2
ret void
}