#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 /*<<< orphan*/ Sys_Error(char *, double);
double floor(double);
void FloorDivMod(double numer, double denom, int *quotient, int *rem) {
  int q, r;
  double x;
  if (denom <= 0.0) {
    Sys_Error("FloorDivMod: bad denominator %d", denom);
  }
  if (numer >= 0.0) {
    x = floor(numer / denom);
    q = (int)x;
    r = (int)floor(numer - (x * denom));
  } else {
    x = floor(-numer / denom);
    q = -(int)x;
    r = (int)floor(-numer - (x * denom));
    if (r != 0) {
      q--;
      r = (int)denom - r;
    }
  }
  *quotient = q;
  *rem = r;
}


x86 assembly (clang, -O0):
<FloorDivMod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1159 <FloorDivMod+0x39>
movsd  -0x10(%rbp),%xmm0
lea    0xeac(%rip),%rdi
call   1030 <Sys_Error@plt>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11c6 <FloorDivMod+0xa6>
movsd  -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
call   1040 <floor@plt>
movsd  %xmm0,-0x30(%rbp)
cvttsd2si -0x30(%rbp),%eax
mov    %eax,-0x24(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <floor@plt>
cvttsd2si %xmm0,%eax
mov    %eax,-0x28(%rbp)
jmp    1271 <FloorDivMod+0x151>
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x10(%rbp),%xmm0
call   1040 <floor@plt>
movsd  %xmm0,-0x30(%rbp)
cvttsd2si -0x30(%rbp),%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <floor@plt>
cvttsd2si %xmm0,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     126c <FloorDivMod+0x14c>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
cvttsd2si -0x10(%rbp),%eax
sub    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1271 <FloorDivMod+0x151>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FloorDivMod>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
xorpd  %xmm2,%xmm2
ucomisd %xmm1,%xmm2
movsd  %xmm1,0x8(%rsp)
movapd %xmm0,0x10(%rsp)
jae    118c <FloorDivMod+0x6c>
ucomisd %xmm2,%xmm0
jae    11b2 <FloorDivMod+0x92>
xorpd  0xeae(%rip),%xmm0
divsd  %xmm1,%xmm0
call   1040 <floor@plt>
cvttsd2si %xmm0,%ebp
xorpd  0xe99(%rip),%xmm0
mulsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
call   1040 <floor@plt>
cvttsd2si %xmm0,%ecx
test   %ecx,%ecx
je     11de <FloorDivMod+0xbe>
not    %ebp
cvttsd2si 0x8(%rsp),%eax
sub    %ecx,%eax
jmp    11e2 <FloorDivMod+0xc2>
lea    0xe7d(%rip),%rdi
movapd %xmm1,%xmm0
call   1030 <Sys_Error@plt>
xorpd  %xmm2,%xmm2
movapd 0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm2,%xmm0
jb     114a <FloorDivMod+0x2a>
divsd  %xmm1,%xmm0
call   1040 <floor@plt>
cvttsd2si %xmm0,%ebp
mulsd  0x8(%rsp),%xmm0
movapd 0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1040 <floor@plt>
cvttsd2si %xmm0,%eax
jmp    11e2 <FloorDivMod+0xc2>
neg    %ebp
xor    %eax,%eax
mov    %ebp,(%rbx)
mov    %eax,(%r14)
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"FloorDivMod: bad denominator %d\00"
define void @FloorDivMod(double %0, double %1, i32* %2, i32* %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
store double %0, double* %5
store double %1, double* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%12 = load double, double* %6
%13 = fcmp ole double %12, 0.000000e+00
br i1 %13, label %14, label %17
14: ; preds = %4
%15 = load double, double* %6
%16 = call i32 @Sys_Error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double %15)
br label %17
17: ; preds = %14, %4
%18 = load double, double* %5
%19 = fcmp oge double %18, 0.000000e+00
br i1 %19, label %20, label %34
20: ; preds = %17
%21 = load double, double* %5
%22 = load double, double* %6
%23 = fdiv double %21, %22
%24 = call double @llvm.floor.f64(double %23)
store double %24, double* %11
%25 = load double, double* %11
%26 = fptosi double %25 to i32
store i32 %26, i32* %9
%27 = load double, double* %5
%28 = load double, double* %11
%29 = load double, double* %6
%30 = fneg double %28
%31 = call double @llvm.fmuladd.f64(double %30, double %29, double %27)
%32 = call double @llvm.floor.f64(double %31)
%33 = fptosi double %32 to i32
store i32 %33, i32* %10
br label %61
34: ; preds = %17
%35 = load double, double* %5
%36 = fneg double %35
%37 = load double, double* %6
%38 = fdiv double %36, %37
%39 = call double @llvm.floor.f64(double %38)
store double %39, double* %11
%40 = load double, double* %11
%41 = fptosi double %40 to i32
%42 = sub nsw i32 0, %41
store i32 %42, i32* %9
%43 = load double, double* %5
%44 = fneg double %43
%45 = load double, double* %11
%46 = load double, double* %6
%47 = fneg double %45
%48 = call double @llvm.fmuladd.f64(double %47, double %46, double %44)
%49 = call double @llvm.floor.f64(double %48)
%50 = fptosi double %49 to i32
store i32 %50, i32* %10
%51 = load i32, i32* %10
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %60
53: ; preds = %34
%54 = load i32, i32* %9
%55 = add nsw i32 %54, -1
store i32 %55, i32* %9
%56 = load double, double* %6
%57 = fptosi double %56 to i32
%58 = load i32, i32* %10
%59 = sub nsw i32 %57, %58
store i32 %59, i32* %10
br label %60
60: ; preds = %53, %34
br label %61
61: ; preds = %60, %20
%62 = load i32, i32* %9
%63 = load i32*, i32** %7
store i32 %62, i32* %63
%64 = load i32, i32* %10
%65 = load i32*, i32** %8
store i32 %64, i32* %65
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"FloorDivMod: bad denominator %d\00"
define void @FloorDivMod(double %0, double %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = fcmp ugt double %1, 0.000000e+00
br i1 %5, label %8, label %6
6: ; preds = %4
%7 = tail call i32 @Sys_Error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double %1)
br label %8
8: ; preds = %6, %4
%9 = fcmp ult double %0, 0.000000e+00
br i1 %9, label %18, label %10
10: ; preds = %8
%11 = fdiv double %0, %1
%12 = tail call double @llvm.floor.f64(double %11)
%13 = fptosi double %12 to i32
%14 = fneg double %12
%15 = tail call double @llvm.fmuladd.f64(double %14, double %1, double %0)
%16 = tail call double @llvm.floor.f64(double %15)
%17 = fptosi double %16 to i32
br label %33
18: ; preds = %8
%19 = fneg double %0
%20 = fdiv double %19, %1
%21 = tail call double @llvm.floor.f64(double %20)
%22 = fptosi double %21 to i32
%23 = sub nsw i32 0, %22
%24 = fneg double %21
%25 = tail call double @llvm.fmuladd.f64(double %24, double %1, double %19)
%26 = tail call double @llvm.floor.f64(double %25)
%27 = fptosi double %26 to i32
%28 = icmp eq i32 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %18
%30 = xor i32 %22, -1
%31 = fptosi double %1 to i32
%32 = sub nsw i32 %31, %27
br label %33
33: ; preds = %18, %29, %10
%34 = phi i32 [ %13, %10 ], [ %30, %29 ], [ %23, %18 ]
%35 = phi i32 [ %17, %10 ], [ %32, %29 ], [ 0, %18 ]
store i32 %34, i32* %2
store i32 %35, i32* %3
ret void
}