#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 abs(int);
int /*<<< orphan*/ assert(int);
int mask(int);
int random();
double remainder(double, double);
double remquo(double, double, int *);
int /*<<< orphan*/ signbit(double);
void testd(double x, double y, double expected_rem, int expected_quo) {
  int q;
  double rem;
  q = random();
  rem = remainder(x, y);
  assert(rem == expected_rem);
  assert(!signbit(rem) == !signbit(expected_rem));
  rem = remquo(x, y, &q);
  assert(rem == expected_rem);
  assert(!signbit(rem) == !signbit(expected_rem));
  assert((q ^ expected_quo) >= 0);
  assert((q & 0x7) == (expected_quo & 0x7));
  if (q != 0) {
    assert((q > 0) ^ !(expected_quo > 0));
    q = abs(q);
    assert(q == (abs(expected_quo) & mask(q)));
  }
}


x86 assembly (clang, -O0):
<testd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
mov    $0x0,%al
call   1050 <random@plt>
mov    %eax,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1060 <remainder@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
sete   %al
setnp  %cl
and    %cl,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movsd  -0x28(%rbp),%xmm0
call   1070 <signbit@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1070 <signbit@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    $0x0,%ecx
setne  %cl
xor    $0xff,%cl
and    $0x1,%cl
movzbl %cl,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
lea    -0x20(%rbp),%rdi
call   1080 <remquo@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
sete   %al
setnp  %cl
and    %cl,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movsd  -0x28(%rbp),%xmm0
call   1070 <signbit@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1070 <signbit@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    $0x0,%ecx
setne  %cl
xor    $0xff,%cl
and    $0x1,%cl
movzbl %cl,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x20(%rbp),%eax
xor    -0x1c(%rbp),%eax
cmp    $0x0,%eax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x20(%rbp),%eax
and    $0x7,%eax
mov    -0x1c(%rbp),%ecx
and    $0x7,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x0,-0x20(%rbp)
je     131f <testd+0x1af>
cmpl   $0x0,-0x20(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
cmpl   $0x0,-0x1c(%rbp)
setg   %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
xor    %eax,%edi
call   1040 <assert@plt>
mov    -0x20(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%edi
call   1090 <mask@plt>
mov    -0x38(%rbp),%ecx
mov    %eax,%edx
mov    -0x34(%rbp),%eax
and    %edx,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testd>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %edi,%r14d
movsd  %xmm2,0x18(%rsp)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x20(%rsp)
xor    %eax,%eax
call   1040 <random@plt>
mov    %eax,0xc(%rsp)
movsd  0x20(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
call   1050 <remainder@plt>
movsd  %xmm0,0x28(%rsp)
movapd %xmm0,%xmm1
cmpeqsd 0x18(%rsp),%xmm1
movq   %xmm1,%rdi
and    $0x1,%edi
call   1030 <assert@plt>
movsd  0x28(%rsp),%xmm0
call   1060 <signbit@plt>
test   %eax,%eax
setne  %bl
movsd  0x18(%rsp),%xmm0
call   1060 <signbit@plt>
test   %eax,%eax
sete   %al
xor    %bl,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    0xc(%rsp),%rdi
movsd  0x20(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
call   1070 <remquo@plt>
movsd  %xmm0,0x10(%rsp)
movapd %xmm0,%xmm1
cmpeqsd 0x18(%rsp),%xmm1
movq   %xmm1,%rdi
and    $0x1,%edi
call   1030 <assert@plt>
movsd  0x10(%rsp),%xmm0
call   1060 <signbit@plt>
test   %eax,%eax
setne  %bl
movsd  0x18(%rsp),%xmm0
call   1060 <signbit@plt>
test   %eax,%eax
sete   %al
xor    %bl,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    0xc(%rsp),%edi
xor    %r14d,%edi
not    %edi
shr    $0x1f,%edi
call   1030 <assert@plt>
mov    0xc(%rsp),%eax
xor    %r14d,%eax
xor    %edi,%edi
test   $0x7,%al
sete   %dil
call   1030 <assert@plt>
cmpl   $0x0,0xc(%rsp)
je     12ac <testd+0x14c>
setg   %al
test   %r14d,%r14d
setle  %cl
xor    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
mov    0xc(%rsp),%eax
mov    %eax,%ebp
neg    %ebp
cmovs  %eax,%ebp
mov    %ebp,0xc(%rsp)
mov    %r14d,%ebx
neg    %ebx
cmovs  %r14d,%ebx
mov    %ebp,%edi
call   1080 <mask@plt>
and    %ebx,%eax
xor    %edi,%edi
cmp    %eax,%ebp
sete   %dil
call   1030 <assert@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @testd(double %0, double %1, double %2, i32 %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store i32 %3, i32* %8
%11 = call i32 (...) @random()
store i32 %11, i32* %9
%12 = load double, double* %5
%13 = load double, double* %6
%14 = call double @remainder(double %12, double %13)
store double %14, double* %10
%15 = load double, double* %10
%16 = load double, double* %7
%17 = fcmp oeq double %15, %16
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load double, double* %10
%21 = call i32 @signbit(double %20)
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
%24 = zext i1 %23 to i32
%25 = load double, double* %7
%26 = call i32 @signbit(double %25)
%27 = icmp ne i32 %26, 0
%28 = xor i1 %27, true
%29 = zext i1 %28 to i32
%30 = icmp eq i32 %24, %29
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = load double, double* %5
%34 = load double, double* %6
%35 = call double @remquo(double %33, double %34, i32* %9)
store double %35, double* %10
%36 = load double, double* %10
%37 = load double, double* %7
%38 = fcmp oeq double %36, %37
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = load double, double* %10
%42 = call i32 @signbit(double %41)
%43 = icmp ne i32 %42, 0
%44 = xor i1 %43, true
%45 = zext i1 %44 to i32
%46 = load double, double* %7
%47 = call i32 @signbit(double %46)
%48 = icmp ne i32 %47, 0
%49 = xor i1 %48, true
%50 = zext i1 %49 to i32
%51 = icmp eq i32 %45, %50
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
%54 = load i32, i32* %9
%55 = load i32, i32* %8
%56 = xor i32 %54, %55
%57 = icmp sge i32 %56, 0
%58 = zext i1 %57 to i32
%59 = call i32 @assert(i32 %58)
%60 = load i32, i32* %9
%61 = and i32 %60, 7
%62 = load i32, i32* %8
%63 = and i32 %62, 7
%64 = icmp eq i32 %61, %63
%65 = zext i1 %64 to i32
%66 = call i32 @assert(i32 %65)
%67 = load i32, i32* %9
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %90
69: ; preds = %4
%70 = load i32, i32* %9
%71 = icmp sgt i32 %70, 0
%72 = zext i1 %71 to i32
%73 = load i32, i32* %8
%74 = icmp sgt i32 %73, 0
%75 = xor i1 %74, true
%76 = zext i1 %75 to i32
%77 = xor i32 %72, %76
%78 = call i32 @assert(i32 %77)
%79 = load i32, i32* %9
%80 = call i32 @abs(i32 %79)
store i32 %80, i32* %9
%81 = load i32, i32* %9
%82 = load i32, i32* %8
%83 = call i32 @abs(i32 %82)
%84 = load i32, i32* %9
%85 = call i32 @mask(i32 %84)
%86 = and i32 %83, %85
%87 = icmp eq i32 %81, %86
%88 = zext i1 %87 to i32
%89 = call i32 @assert(i32 %88)
br label %90
90: ; preds = %69, %4
ret void
}

LLVM IR (-O2):
define void @testd(double %0, double %1, double %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = tail call i32 (...) @random()
store i32 %7, i32* %5
%8 = tail call double @remainder(double %0, double %1)
%9 = fcmp oeq double %8, %2
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = tail call i32 @signbit(double %8)
%13 = icmp ne i32 %12, 0
%14 = tail call i32 @signbit(double %2)
%15 = icmp eq i32 %14, 0
%16 = xor i1 %13, %15
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = call double @remquo(double %0, double %1, i32* %5)
%20 = fcmp oeq double %19, %2
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = call i32 @signbit(double %19)
%24 = icmp ne i32 %23, 0
%25 = call i32 @signbit(double %2)
%26 = icmp eq i32 %25, 0
%27 = xor i1 %24, %26
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = load i32, i32* %5
%31 = xor i32 %30, %3
%32 = xor i32 %31, -1
%33 = lshr i32 %32, 31
%34 = call i32 @assert(i32 %33)
%35 = load i32, i32* %5
%36 = xor i32 %35, %3
%37 = and i32 %36, 7
%38 = icmp eq i32 %37, 0
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = load i32, i32* %5
%42 = icmp eq i32 %41, 0
br i1 %42, label %57, label %43
43: ; preds = %4
%44 = icmp sgt i32 %41, 0
%45 = icmp slt i32 %3, 1
%46 = xor i1 %45, %44
%47 = zext i1 %46 to i32
%48 = call i32 @assert(i32 %47)
%49 = load i32, i32* %5
%50 = call i32 @llvm.abs.i32(i32 %49, i1 true)
store i32 %50, i32* %5
%51 = call i32 @llvm.abs.i32(i32 %3, i1 true)
%52 = call i32 @mask(i32 %50)
%53 = and i32 %52, %51
%54 = icmp eq i32 %50, %53
%55 = zext i1 %54 to i32
%56 = call i32 @assert(i32 %55)
br label %57
57: ; preds = %43, %4
ret void
}