#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 fabs(double);
double floor(double);
double gcd(double x, double y) {
  while (fabs(x) > 1e-4 && fabs(y) > 1e-4) {
    if (x > y)
      x -= floor(x / y) * y;
    else
      y -= floor(y / x) * x;
  }
  return x + y;
}


x86 assembly (clang, -O0):
<gcd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm0
xor    %eax,%eax
movsd  0xeb6(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x11(%rbp)
jbe    1177 <gcd+0x57>
movsd  -0x10(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe93(%rip),%xmm1
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1187 <gcd+0x67>
jmp    121b <gcd+0xfb>
movsd  -0x8(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11d9 <gcd+0xb9>
movsd  -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
call   1040 <floor@plt>
movsd  -0x10(%rbp),%xmm2
movsd  -0x8(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1216 <gcd+0xf6>
movsd  -0x10(%rbp),%xmm0
divsd  -0x8(%rbp),%xmm0
call   1040 <floor@plt>
movsd  -0x8(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1132 <gcd+0x12>
movsd  -0x8(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gcd>:
sub    $0x18,%rsp
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1030 <fabs@plt>
test   %eax,%eax
jle    11d4 <gcd+0xb4>
movsd  0x8(%rsp),%xmm1
jmp    118c <gcd+0x6c>
cs nopw 0x0(%rax,%rax,1)
nop
divsd  %xmm1,%xmm0
call   1040 <floor@plt>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0x8(%rsp),%xmm2
subsd  %xmm0,%xmm2
movsd  %xmm2,0x8(%rsp)
movsd  %xmm1,0x10(%rsp)
movapd %xmm1,%xmm0
call   1030 <fabs@plt>
test   %eax,%eax
movsd  0x8(%rsp),%xmm1
jle    11da <gcd+0xba>
movapd %xmm1,%xmm0
movsd  %xmm1,0x8(%rsp)
call   1030 <fabs@plt>
test   %eax,%eax
jle    11d4 <gcd+0xb4>
movsd  0x10(%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
ucomisd %xmm0,%xmm1
jbe    1150 <gcd+0x30>
movapd %xmm0,%xmm2
movapd %xmm1,%xmm0
divsd  %xmm2,%xmm0
call   1040 <floor@plt>
movsd  0x10(%rsp),%xmm1
mulsd  0x8(%rsp),%xmm0
subsd  %xmm0,%xmm1
jmp    1173 <gcd+0x53>
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm0
addsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @gcd(double %0, double %1) {
%3 = alloca double
%4 = alloca double
store double %0, double* %3
store double %1, double* %4
br label %5
5: ; preds = %39, %2
%6 = load double, double* %3
%7 = call i32 @fabs(double %6)
%8 = sitofp i32 %7 to double
%9 = fcmp ogt double %8, 1.000000e-04
br i1 %9, label %10, label %15
10: ; preds = %5
%11 = load double, double* %4
%12 = call i32 @fabs(double %11)
%13 = sitofp i32 %12 to double
%14 = fcmp ogt double %13, 1.000000e-04
br label %15
15: ; preds = %10, %5
%16 = phi i1 [ false, %5 ], [ %14, %10 ]
br i1 %16, label %17, label %40
17: ; preds = %15
%18 = load double, double* %3
%19 = load double, double* %4
%20 = fcmp ogt double %18, %19
br i1 %20, label %21, label %30
21: ; preds = %17
%22 = load double, double* %3
%23 = load double, double* %4
%24 = fdiv double %22, %23
%25 = call double @llvm.floor.f64(double %24)
%26 = load double, double* %4
%27 = load double, double* %3
%28 = fneg double %25
%29 = call double @llvm.fmuladd.f64(double %28, double %26, double %27)
store double %29, double* %3
br label %39
30: ; preds = %17
%31 = load double, double* %4
%32 = load double, double* %3
%33 = fdiv double %31, %32
%34 = call double @llvm.floor.f64(double %33)
%35 = load double, double* %3
%36 = load double, double* %4
%37 = fneg double %34
%38 = call double @llvm.fmuladd.f64(double %37, double %35, double %36)
store double %38, double* %4
br label %39
39: ; preds = %30, %21
br label %5
40: ; preds = %15
%41 = load double, double* %3
%42 = load double, double* %4
%43 = fadd double %41, %42
ret double %43
}

LLVM IR (-O2):
define double @gcd(double %0, double %1) {
%3 = tail call i32 @fabs(double %0)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %27
5: ; preds = %2, %22
%6 = phi double [ %24, %22 ], [ %1, %2 ]
%7 = phi double [ %23, %22 ], [ %0, %2 ]
%8 = tail call i32 @fabs(double %6)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %27
10: ; preds = %5
%11 = fcmp ogt double %7, %6
br i1 %11, label %12, label %17
12: ; preds = %10
%13 = fdiv double %7, %6
%14 = tail call double @llvm.floor.f64(double %13)
%15 = fneg double %14
%16 = tail call double @llvm.fmuladd.f64(double %15, double %6, double %7)
br label %22
17: ; preds = %10
%18 = fdiv double %6, %7
%19 = tail call double @llvm.floor.f64(double %18)
%20 = fneg double %19
%21 = tail call double @llvm.fmuladd.f64(double %20, double %7, double %6)
br label %22
22: ; preds = %17, %12
%23 = phi double [ %16, %12 ], [ %7, %17 ]
%24 = phi double [ %6, %12 ], [ %21, %17 ]
%25 = tail call i32 @fabs(double %23)
%26 = icmp sgt i32 %25, 0
br i1 %26, label %5, label %27
27: ; preds = %5, %22, %2
%28 = phi double [ %0, %2 ], [ %23, %22 ], [ %7, %5 ]
%29 = phi double [ %1, %2 ], [ %24, %22 ], [ %6, %5 ]
%30 = fadd double %28, %29
ret double %30
}