#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_pow(int, unsigned int);
double ft_trunc(double d, unsigned int p) {
  double temp;
  double res;
  unsigned int i;
  i = 0;
  res = (long long int)d;
  d -= (long long int)d;
  while (i < p) {
    temp = d * 10;
    temp = (long long int)temp;
    temp /= ft_pow(10, i + 1);
    d *= 10;
    d -= (long long int)d;
    res += temp;
    i++;
  }
  return (res);
}


x86 assembly (clang, -O0):
<ft_trunc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movl   $0x0,-0x24(%rbp)
cvttsd2si -0x8(%rbp),%rax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
cvttsd2si -0x8(%rbp),%rax
cvtsi2sd %rax,%xmm1
movsd  -0x8(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11e7 <ft_trunc+0xd7>
movsd  0xe9c(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
cvttsd2si -0x18(%rbp),%rax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x24(%rbp),%esi
add    $0x1,%esi
mov    $0xa,%edi
call   1030 <ft_pow@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe59(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
cvttsd2si -0x8(%rbp),%rax
cvtsi2sd %rax,%xmm1
movsd  -0x8(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1150 <ft_trunc+0x40>
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_trunc>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movapd %xmm0,%xmm1
cvttsd2si %xmm0,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
test   %edi,%edi
je     11a2 <ft_trunc+0x92>
mov    %edi,%r14d
subsd  %xmm0,%xmm1
neg    %r14d
mov    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x10(%rsp)
mulsd  0xeb2(%rip),%xmm1
movsd  %xmm1,0x8(%rsp)
cvttsd2si %xmm1,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,(%rsp)
mov    $0xa,%edi
mov    %ebx,%esi
call   1030 <ft_pow@plt>
movsd  0x8(%rsp),%xmm1
movsd  (%rsp),%xmm2
subsd  %xmm2,%xmm1
divsd  %xmm0,%xmm2
movsd  0x10(%rsp),%xmm0
addsd  %xmm2,%xmm0
lea    (%r14,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
jne    1140 <ft_trunc+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @ft_trunc(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store double %0, double* %3
store i32 %1, i32* %4
store i32 0, i32* %7
%8 = load double, double* %3
%9 = fptosi double %8 to i64
%10 = sitofp i64 %9 to double
store double %10, double* %6
%11 = load double, double* %3
%12 = fptosi double %11 to i64
%13 = sitofp i64 %12 to double
%14 = load double, double* %3
%15 = fsub double %14, %13
store double %15, double* %3
br label %16
16: ; preds = %20, %2
%17 = load i32, i32* %7
%18 = load i32, i32* %4
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %43
20: ; preds = %16
%21 = load double, double* %3
%22 = fmul double %21, 1.000000e+01
store double %22, double* %5
%23 = load double, double* %5
%24 = fptosi double %23 to i64
%25 = sitofp i64 %24 to double
store double %25, double* %5
%26 = load i32, i32* %7
%27 = add i32 %26, 1
%28 = call double @ft_pow(i32 10, i32 %27)
%29 = load double, double* %5
%30 = fdiv double %29, %28
store double %30, double* %5
%31 = load double, double* %3
%32 = fmul double %31, 1.000000e+01
store double %32, double* %3
%33 = load double, double* %3
%34 = fptosi double %33 to i64
%35 = sitofp i64 %34 to double
%36 = load double, double* %3
%37 = fsub double %36, %35
store double %37, double* %3
%38 = load double, double* %5
%39 = load double, double* %6
%40 = fadd double %39, %38
store double %40, double* %6
%41 = load i32, i32* %7
%42 = add i32 %41, 1
store i32 %42, i32* %7
br label %16
43: ; preds = %16
%44 = load double, double* %6
ret double %44
}

LLVM IR (-O2):
define double @ft_trunc(double %0, i32 %1) {
%3 = fptosi double %0 to i64
%4 = sitofp i64 %3 to double
%5 = icmp eq i32 %1, 0
br i1 %5, label %21, label %6
6: ; preds = %2
%7 = fsub double %0, %4
br label %8
8: ; preds = %6, %8
%9 = phi i32 [ %15, %8 ], [ 0, %6 ]
%10 = phi double [ %19, %8 ], [ %4, %6 ]
%11 = phi double [ %18, %8 ], [ %7, %6 ]
%12 = fmul double %11, 1.000000e+01
%13 = fptosi double %12 to i64
%14 = sitofp i64 %13 to double
%15 = add nuw i32 %9, 1
%16 = tail call double @ft_pow(i32 10, i32 %15)
%17 = fdiv double %14, %16
%18 = fsub double %12, %14
%19 = fadd double %10, %17
%20 = icmp eq i32 %15, %1
br i1 %20, label %21, label %8
21: ; preds = %8, %2
%22 = phi double [ %4, %2 ], [ %19, %8 ]
ret double %22
}