#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 ft_modf(double, double *);
int ft_gp(double n) {
  int power;
  double f;
  double i;
  power = 0;
  f = ft_modf(n, &i);
  f = (f < 0) ? -f : f;
  i = (i < 0) ? -i : i;
  if (i == 0.0)
    return (0);
  if (i < 1.0)
    while ((f *= 10.0) < 1.0)
      power--;
  else
    while ((i /= 10.0) >= 1.0)
      power++;
  return (power);
}


x86 assembly (clang, -O0):
<ft_gp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    -0x28(%rbp),%rdi
call   1030 <ft_modf@plt>
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    116b <ft_gp+0x5b>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1175 <ft_gp+0x65>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    11b3 <ft_gp+0xa3>
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11bd <ft_gp+0xad>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11eb <ft_gp+0xdb>
jp     11eb <ft_gp+0xdb>
movl   $0x0,-0x4(%rbp)
jmp    1280 <ft_gp+0x170>
movsd  0xe0d(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    123a <ft_gp+0x12a>
jmp    1203 <ft_gp+0xf3>
movsd  0xdfd(%rip),%xmm1
mulsd  -0x20(%rbp),%xmm1
movsd  %xmm1,-0x20(%rbp)
movsd  0xde3(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1235 <ft_gp+0x125>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1203 <ft_gp+0xf3>
jmp    127a <ft_gp+0x16a>
jmp    123f <ft_gp+0x12f>
movsd  -0x28(%rbp),%xmm0
movsd  0xdbc(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xda3(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1275 <ft_gp+0x165>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    123f <ft_gp+0x12f>
jmp    127a <ft_gp+0x16a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_gp>:
push   %rax
mov    %rsp,%rdi
call   1030 <ft_modf@plt>
movsd  (%rsp),%xmm1
movapd 0xeda(%rip),%xmm3
xorpd  %xmm1,%xmm3
xorpd  %xmm4,%xmm4
movapd %xmm1,%xmm2
cmpltsd %xmm4,%xmm2
andpd  %xmm2,%xmm3
andnpd %xmm1,%xmm2
orpd   %xmm3,%xmm2
xor    %eax,%eax
ucomisd %xmm4,%xmm2
jne    114d <ft_gp+0x3d>
jnp    11bd <ft_gp+0xad>
movsd  0xebb(%rip),%xmm1
ucomisd %xmm2,%xmm1
jbe    119f <ft_gp+0x8f>
movapd 0xe9d(%rip),%xmm3
xorpd  %xmm0,%xmm3
xorpd  %xmm4,%xmm4
movapd %xmm0,%xmm2
cmpltsd %xmm4,%xmm2
andpd  %xmm2,%xmm3
andnpd %xmm0,%xmm2
orpd   %xmm3,%xmm2
mov    $0x1,%eax
movsd  0xe8b(%rip),%xmm0
nopl   (%rax)
mulsd  %xmm0,%xmm2
add    $0xffffffff,%eax
ucomisd %xmm2,%xmm1
ja     1190 <ft_gp+0x80>
jmp    11bd <ft_gp+0xad>
mov    $0xffffffff,%eax
movsd  0xe6c(%rip),%xmm0
nopl   0x0(%rax)
divsd  %xmm0,%xmm2
add    $0x1,%eax
ucomisd %xmm1,%xmm2
jae    11b0 <ft_gp+0xa0>
pop    %rcx
ret

LLVM IR (-O0):
define i32 @ft_gp(double %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
store double %0, double* %3
store i32 0, i32* %4
%7 = load double, double* %3
%8 = call double @ft_modf(double %7, double* %6)
store double %8, double* %5
%9 = load double, double* %5
%10 = fcmp olt double %9, 0.000000e+00
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load double, double* %5
%13 = fneg double %12
br label %16
14: ; preds = %1
%15 = load double, double* %5
br label %16
16: ; preds = %14, %11
%17 = phi double [ %13, %11 ], [ %15, %14 ]
store double %17, double* %5
%18 = load double, double* %6
%19 = fcmp olt double %18, 0.000000e+00
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load double, double* %6
%22 = fneg double %21
br label %25
23: ; preds = %16
%24 = load double, double* %6
br label %25
25: ; preds = %23, %20
%26 = phi double [ %22, %20 ], [ %24, %23 ]
store double %26, double* %6
%27 = load double, double* %6
%28 = fcmp oeq double %27, 0.000000e+00
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 0, i32* %2
br label %53
30: ; preds = %25
%31 = load double, double* %6
%32 = fcmp olt double %31, 1.000000e+00
br i1 %32, label %33, label %42
33: ; preds = %30
br label %34
34: ; preds = %38, %33
%35 = load double, double* %5
%36 = fmul double %35, 1.000000e+01
store double %36, double* %5
%37 = fcmp olt double %36, 1.000000e+00
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = load i32, i32* %4
%40 = add nsw i32 %39, -1
store i32 %40, i32* %4
br label %34
41: ; preds = %34
br label %51
42: ; preds = %30
br label %43
43: ; preds = %47, %42
%44 = load double, double* %6
%45 = fdiv double %44, 1.000000e+01
store double %45, double* %6
%46 = fcmp oge double %45, 1.000000e+00
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = load i32, i32* %4
%49 = add nsw i32 %48, 1
store i32 %49, i32* %4
br label %43
50: ; preds = %43
br label %51
51: ; preds = %50, %41
%52 = load i32, i32* %4
store i32 %52, i32* %2
br label %53
53: ; preds = %51, %29
%54 = load i32, i32* %2
ret i32 %54
}

LLVM IR (-O2):
define i32 @ft_gp(double %0) {
%2 = alloca double
%3 = bitcast double* %2 to i8*
%4 = call double @ft_modf(double %0, double* %2)
%5 = load double, double* %2
%6 = fcmp olt double %5, 0.000000e+00
%7 = fneg double %5
%8 = select i1 %6, double %7, double %5
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %28, label %10
10: ; preds = %1
%11 = fcmp olt double %8, 1.000000e+00
br i1 %11, label %12, label %22
12: ; preds = %10
%13 = fcmp olt double %4, 0.000000e+00
%14 = fneg double %4
%15 = select i1 %13, double %14, double %4
br label %16
16: ; preds = %12, %16
%17 = phi i32 [ %21, %16 ], [ 0, %12 ]
%18 = phi double [ %19, %16 ], [ %15, %12 ]
%19 = fmul double %18, 1.000000e+01
%20 = fcmp olt double %19, 1.000000e+00
%21 = add nsw i32 %17, -1
br i1 %20, label %16, label %28
22: ; preds = %10, %22
%23 = phi double [ %25, %22 ], [ %8, %10 ]
%24 = phi i32 [ %27, %22 ], [ 0, %10 ]
%25 = fdiv double %23, 1.000000e+01
%26 = fcmp ult double %25, 1.000000e+00
%27 = add nuw nsw i32 %24, 1
br i1 %26, label %28, label %22
28: ; preds = %22, %16, %1
%29 = phi i32 [ 0, %1 ], [ %17, %16 ], [ %24, %22 ]
ret i32 %29
}