#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 */
typedef scalar_t__ uint64_t;

/* Variables and functions */
scalar_t__ about_equal(double, double);
int atoi(char *);
scalar_t__ float64_to_uint64(double);
double fmod(double, double);
double getrandom_double();
int /*<<< orphan*/ isnormal(double);
double our_fmod(double, double);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  double x, y, libc_res, our_res;
  uint64_t ux, uy, uint_libc_res, uint_our_res;
  size_t i, limit, errors;
  int inlim, print;
  inlim = (argc > 1) ? atoi(argv[1]) : 0;
  limit = (inlim <= 0) ? 10 : (size_t)inlim;
  errors = 0;
  x = 0.0;
  y = -0.0;
  for (i = 0; i < limit; ++i) {
    do {
      x = getrandom_double();
    } while (!isnormal(x));
    ux = float64_to_uint64(x);
    do {
      y = getrandom_double();
    } while (!isnormal(y));
    uy = float64_to_uint64(y);
    libc_res = fmod(x, y);
    uint_libc_res = float64_to_uint64(libc_res);
    our_res = our_fmod(x, y);
    uint_our_res = float64_to_uint64(our_res);
    if (about_equal(libc_res, our_res)) {
      print = 0;
    } else {
      ++errors;
      print = 1;
    }
    if (print) {
      printf("    fmod(%g, %g)\n == (%g)\n", x, y, libc_res);
      printf("our_fmod(%g, %g)\n == (%g)\n", x, y, our_res);
      printf("    fmod(0x%016lx, 0x%016lx)\n == (0x%016lx)\n",
             (unsigned long)ux, (unsigned long)uy,
             (unsigned long)uint_libc_res);
      printf("our_fmod(0x%016lx, 0x%016lx)\n == (0x%016lx)\n",
             (unsigned long)ux, (unsigned long)uy, (unsigned long)uint_our_res);
      printf("\n");
    }
  }
  if (errors) {
    printf("differences from LibC: %lu of %lu\n", (unsigned long)errors,
           (unsigned long)i);
  }
  return errors ? 1 : 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11b8 <main+0x38>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x74(%rbp)
jmp    11c2 <main+0x42>
xor    %eax,%eax
mov    %eax,-0x74(%rbp)
jmp    11c2 <main+0x42>
mov    -0x74(%rbp),%eax
mov    %eax,-0x6c(%rbp)
cmpl   $0x0,-0x6c(%rbp)
jg     11e0 <main+0x60>
mov    $0xa,%eax
mov    %rax,-0x80(%rbp)
jmp    11e8 <main+0x68>
movslq -0x6c(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rax
mov    %rax,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xdf8(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movq   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%rax
cmp    -0x60(%rbp),%rax
jae    13a8 <main+0x228>
jmp    1228 <main+0xa8>
mov    $0x0,%al
call   10a0 <getrandom_double@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1080 <isnormal@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1228 <main+0xa8>
movsd  -0x18(%rbp),%xmm0
call   1060 <float64_to_uint64@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   10a0 <getrandom_double@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1080 <isnormal@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    125c <main+0xdc>
movsd  -0x20(%rbp),%xmm0
call   1060 <float64_to_uint64@plt>
mov    %rax,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
call   1040 <fmod@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1060 <float64_to_uint64@plt>
mov    %rax,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
call   1070 <our_fmod@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1060 <float64_to_uint64@plt>
mov    %rax,-0x50(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
call   1050 <about_equal@plt>
cmp    $0x0,%rax
je     12f9 <main+0x179>
movl   $0x0,-0x70(%rbp)
jmp    130c <main+0x18c>
mov    -0x68(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
movl   $0x1,-0x70(%rbp)
cmpl   $0x0,-0x70(%rbp)
je     1392 <main+0x212>
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
lea    0xcdc(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
lea    0xcda(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rcx
lea    0xcdb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x50(%rbp),%rcx
lea    0xcee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xc96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1397 <main+0x217>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    1215 <main+0x95>
cmpq   $0x0,-0x68(%rbp)
je     13c9 <main+0x249>
mov    -0x68(%rbp),%rsi
mov    -0x58(%rbp),%rdx
lea    0xcd6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x68(%rbp),%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
cmp    $0x2,%edi
jl     11b0 <main+0x20>
mov    0x8(%rsi),%rdi
call   10a0 <atoi@plt>
test   %eax,%eax
jg     11b5 <main+0x25>
mov    $0xa,%eax
mov    %eax,%eax
mov    %rax,0x10(%rsp)
xor    %ebx,%ebx
xor    %r14d,%r14d
jmp    11e0 <main+0x50>
mov    %r13b,%r15b
add    %r15,%rbx
add    $0x1,%r14
cmp    0x10(%rsp),%r14
je     1316 <main+0x186>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10b0 <getrandom_double@plt>
movsd  %xmm0,0x8(%rsp)
call   1090 <isnormal@plt>
test   %eax,%eax
je     11e0 <main+0x50>
movsd  0x8(%rsp),%xmm0
call   1070 <float64_to_uint64@plt>
mov    %rax,0x30(%rsp)
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   10b0 <getrandom_double@plt>
movsd  %xmm0,(%rsp)
call   1090 <isnormal@plt>
test   %eax,%eax
je     1210 <main+0x80>
movsd  (%rsp),%xmm0
call   1070 <float64_to_uint64@plt>
mov    %rax,%r12
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
call   1050 <fmod@plt>
movsd  %xmm0,0x20(%rsp)
call   1070 <float64_to_uint64@plt>
mov    %rax,%rbp
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
call   1080 <our_fmod@plt>
movsd  %xmm0,0x18(%rsp)
call   1070 <float64_to_uint64@plt>
mov    %rax,0x28(%rsp)
movsd  0x20(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
call   1060 <about_equal@plt>
xor    %r15d,%r15d
test   %rax,%rax
sete   %r13b
jne    11c3 <main+0x33>
lea    0xd68(%rip),%rdi
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
movsd  0x20(%rsp),%xmm2
mov    $0x3,%al
call   1040 <printf@plt>
lea    0xd64(%rip),%rdi
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
movsd  0x18(%rsp),%xmm2
mov    $0x3,%al
call   1040 <printf@plt>
lea    0xd60(%rip),%rdi
mov    %rbp,%rcx
mov    %r12,%rbp
mov    0x30(%rsp),%r12
mov    %r12,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd6e(%rip),%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
mov    0x28(%rsp),%rcx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11c3 <main+0x33>
test   %rbx,%rbx
je     1331 <main+0x1a1>
lea    0xd6e(%rip),%rdi
mov    %rbx,%rsi
mov    0x10(%rsp),%rdx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
test   %rbx,%rbx
setne  %al
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c" fmod(%g, %g)\0A == (%g)\0A\00"
@.str.1 = [27 x i8] c"our_fmod(%g, %g)\0A == (%g)\0A\00"
@.str.2 = [45 x i8] c" fmod(0x%016lx, 0x%016lx)\0A == (0x%016lx)\0A\00"
@.str.3 = [45 x i8] c"our_fmod(0x%016lx, 0x%016lx)\0A == (0x%016lx)\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [35 x i8] c"differences from LibC: %lu of %lu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
%17 = alloca i32
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 1
br i1 %20, label %21, label %26
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
br label %27
26: ; preds = %2
br label %27
27: ; preds = %26, %21
%28 = phi i32 [ %25, %21 ], [ 0, %26 ]
store i32 %28, i32* %17
%29 = load i32, i32* %17
%30 = icmp sle i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
br label %35
32: ; preds = %27
%33 = load i32, i32* %17
%34 = sext i32 %33 to i64
br label %35
35: ; preds = %32, %31
%36 = phi i64 [ 10, %31 ], [ %34, %32 ]
store i64 %36, i64* %15
store i64 0, i64* %16
store double 0.000000e+00, double* %6
store double -0.000000e+00, double* %7
store i64 0, i64* %14
br label %37
37: ; preds = %102, %35
%38 = load i64, i64* %14
%39 = load i64, i64* %15
%40 = icmp ult i64 %38, %39
br i1 %40, label %41, label %105
41: ; preds = %37
br label %42
42: ; preds = %44, %41
%43 = call double (...) @getrandom_double()
store double %43, double* %6
br label %44
44: ; preds = %42
%45 = load double, double* %6
%46 = call i32 @isnormal(double %45)
%47 = icmp ne i32 %46, 0
%48 = xor i1 %47, true
br i1 %48, label %42, label %49
49: ; preds = %44
%50 = load double, double* %6
%51 = call i64 @float64_to_uint64(double %50)
store i64 %51, i64* %10
br label %52
52: ; preds = %54, %49
%53 = call double (...) @getrandom_double()
store double %53, double* %7
br label %54
54: ; preds = %52
%55 = load double, double* %7
%56 = call i32 @isnormal(double %55)
%57 = icmp ne i32 %56, 0
%58 = xor i1 %57, true
br i1 %58, label %52, label %59
59: ; preds = %54
%60 = load double, double* %7
%61 = call i64 @float64_to_uint64(double %60)
store i64 %61, i64* %11
%62 = load double, double* %6
%63 = load double, double* %7
%64 = call double @fmod(double %62, double %63)
store double %64, double* %8
%65 = load double, double* %8
%66 = call i64 @float64_to_uint64(double %65)
store i64 %66, i64* %12
%67 = load double, double* %6
%68 = load double, double* %7
%69 = call double @our_fmod(double %67, double %68)
store double %69, double* %9
%70 = load double, double* %9
%71 = call i64 @float64_to_uint64(double %70)
store i64 %71, i64* %13
%72 = load double, double* %8
%73 = load double, double* %9
%74 = call i64 @about_equal(double %72, double %73)
%75 = icmp ne i64 %74, 0
br i1 %75, label %76, label %77
76: ; preds = %59
store i32 0, i32* %18
br label %80
77: ; preds = %59
%78 = load i64, i64* %16
%79 = add i64 %78, 1
store i64 %79, i64* %16
store i32 1, i32* %18
br label %80
80: ; preds = %77, %76
%81 = load i32, i32* %18
%82 = icmp ne i32 %81, 0
br i1 %82, label %83, label %101
83: ; preds = %80
%84 = load double, double* %6
%85 = load double, double* %7
%86 = load double, double* %8
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), double %84, double %85, double %86)
%88 = load double, double* %6
%89 = load double, double* %7
%90 = load double, double* %9
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), double %88, double %89, double %90)
%92 = load i64, i64* %10
%93 = load i64, i64* %11
%94 = load i64, i64* %12
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i64 %92, i64 %93, i64 %94)
%96 = load i64, i64* %10
%97 = load i64, i64* %11
%98 = load i64, i64* %13
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i64 %96, i64 %97, i64 %98)
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %101
101: ; preds = %83, %80
br label %102
102: ; preds = %101
%103 = load i64, i64* %14
%104 = add i64 %103, 1
store i64 %104, i64* %14
br label %37
105: ; preds = %37
%106 = load i64, i64* %16
%107 = icmp ne i64 %106, 0
br i1 %107, label %108, label %112
108: ; preds = %105
%109 = load i64, i64* %16
%110 = load i64, i64* %14
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i64 %109, i64 %110)
br label %112
112: ; preds = %108, %105
%113 = load i64, i64* %16
%114 = icmp ne i64 %113, 0
%115 = zext i1 %114 to i64
%116 = select i1 %114, i32 1, i32 0
ret i32 %116
}

LLVM IR (-O2):
@.str = [27 x i8] c" fmod(%g, %g)\0A == (%g)\0A\00"
@.str.1 = [27 x i8] c"our_fmod(%g, %g)\0A == (%g)\0A\00"
@.str.2 = [45 x i8] c" fmod(0x%016lx, 0x%016lx)\0A == (0x%016lx)\0A\00"
@.str.3 = [45 x i8] c"our_fmod(0x%016lx, 0x%016lx)\0A == (0x%016lx)\0A\00"
@.str.5 = [35 x i8] c"differences from LibC: %lu of %lu\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %10
9: ; preds = %2, %4
br label %10
10: ; preds = %9, %4
%11 = phi i32 [ 10, %9 ], [ %7, %4 ]
%12 = zext i32 %11 to i64
br label %13
13: ; preds = %10, %42
%14 = phi i64 [ %35, %42 ], [ 0, %10 ]
%15 = phi i64 [ %43, %42 ], [ 0, %10 ]
br label %16
16: ; preds = %13, %16
%17 = tail call double (...) @getrandom_double()
%18 = tail call i32 @isnormal(double %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %16, label %20
20: ; preds = %16
%21 = tail call i64 @float64_to_uint64(double %17)
br label %22
22: ; preds = %22, %20
%23 = tail call double (...) @getrandom_double()
%24 = tail call i32 @isnormal(double %23)
%25 = icmp eq i32 %24, 0
br i1 %25, label %22, label %26
26: ; preds = %22
%27 = tail call i64 @float64_to_uint64(double %23)
%28 = tail call double @fmod(double %17, double %23)
%29 = tail call i64 @float64_to_uint64(double %28)
%30 = tail call double @our_fmod(double %17, double %23)
%31 = tail call i64 @float64_to_uint64(double %30)
%32 = tail call i64 @about_equal(double %28, double %30)
%33 = icmp eq i64 %32, 0
%34 = zext i1 %33 to i64
%35 = add i64 %14, %34
br i1 %33, label %36, label %42
36: ; preds = %26
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), double %17, double %23, double %28)
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), double %17, double %23, double %30)
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i64 %21, i64 %27, i64 %29)
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i64 %21, i64 %27, i64 %31)
%41 = tail call i32 @putchar(i32 10)
br label %42
42: ; preds = %26, %36
%43 = add nuw nsw i64 %15, 1
%44 = icmp eq i64 %43, %12
br i1 %44, label %45, label %13
45: ; preds = %42
%46 = icmp eq i64 %35, 0
br i1 %46, label %49, label %47
47: ; preds = %45
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i64 %35, i64 %12)
br label %49
49: ; preds = %47, %45
%50 = xor i1 %46, true
%51 = zext i1 %50 to i32
ret i32 %51
}