#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 fmod(double, double);
int /*<<< orphan*/ printf(char *, double, double, ...);
int main(void) {
  double x, xx;
  double xT, lft, rgt, dlt;
  int N;
  N = 4;
  lft = 2.0;
  rgt = -1.0;
  dlt = (rgt - lft) / (N - 1);
  xT = (rgt - lft) + dlt;
  printf("# (lft, rgt) = (%lf, %lf), dlt=%lf, xT =%lf\n", lft, rgt, dlt, xT);
  for (x = -8.0; x <= 8.0; x += 0.1) {
    xx = lft + fmod(x - lft, xT);
    if ((x - lft) * xT < 0) {
      xx += xT;
    }
    printf("%lf, %lf\n", x, xx);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4,-0x3c(%rbp)
movsd  0xed2(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xebd(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
mov    -0x3c(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm3
lea    0xe8c(%rip),%rdi
mov    $0x4,%al
call   1030 <printf@plt>
movsd  0xe55(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe60(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     124c <main+0x12c>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
call   1040 <fmod@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm1
subsd  -0x28(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    121d <main+0xfd>
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
lea    0xe27(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movsd  0xde3(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11b0 <main+0x90>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xf14(%rip),%rdi
movsd  0xecc(%rip),%xmm0
movsd  0xecc(%rip),%xmm1
movsd  0xecc(%rip),%xmm3
movapd %xmm1,%xmm2
mov    $0x4,%al
call   1030 <printf@plt>
movsd  0xec1(%rip),%xmm0
lea    0xf0f(%rip),%rbx
xchg   %ax,%ax
movsd  %xmm0,0x8(%rsp)
addsd  0xeb2(%rip),%xmm0
movapd %xmm0,0x10(%rsp)
movsd  0xe94(%rip),%xmm1
call   1040 <fmod@plt>
addsd  0xe77(%rip),%xmm0
movapd 0x10(%rsp),%xmm2
movsd  0xe79(%rip),%xmm3
mulsd  %xmm3,%xmm2
cmpltsd 0xe94(%rip),%xmm2
movapd %xmm2,%xmm1
andnpd %xmm0,%xmm1
addsd  %xmm3,%xmm0
andpd  %xmm0,%xmm2
orpd   %xmm1,%xmm2
movapd %xmm2,%xmm1
mov    %rbx,%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x2,%al
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm0
addsd  0xe4e(%rip),%xmm0
movsd  0xe4e(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    1160 <main+0x40>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [45 x i8] c"# (lft, rgt) = (%lf, %lf), dlt=%lf, xT =%lf\0A\00"
@.str.1 = [10 x i8] c"%lf, %lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
store i32 0, i32* %1
store i32 4, i32* %8
store double 2.000000e+00, double* %5
store double -1.000000e+00, double* %6
%9 = load double, double* %6
%10 = load double, double* %5
%11 = fsub double %9, %10
%12 = load i32, i32* %8
%13 = sub nsw i32 %12, 1
%14 = sitofp i32 %13 to double
%15 = fdiv double %11, %14
store double %15, double* %7
%16 = load double, double* %6
%17 = load double, double* %5
%18 = fsub double %16, %17
%19 = load double, double* %7
%20 = fadd double %18, %19
store double %20, double* %4
%21 = load double, double* %5
%22 = load double, double* %6
%23 = load double, double* %7
%24 = load double, double* %4
%25 = call i32 (i8*, double, double, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), double %21, double %22, double %23, double %24)
store double -8.000000e+00, double* %2
br label %26
26: ; preds = %51, %0
%27 = load double, double* %2
%28 = fcmp ole double %27, 8.000000e+00
br i1 %28, label %29, label %54
29: ; preds = %26
%30 = load double, double* %5
%31 = load double, double* %2
%32 = load double, double* %5
%33 = fsub double %31, %32
%34 = load double, double* %4
%35 = call double @fmod(double %33, double %34)
%36 = fadd double %30, %35
store double %36, double* %3
%37 = load double, double* %2
%38 = load double, double* %5
%39 = fsub double %37, %38
%40 = load double, double* %4
%41 = fmul double %39, %40
%42 = fcmp olt double %41, 0.000000e+00
br i1 %42, label %43, label %47
43: ; preds = %29
%44 = load double, double* %4
%45 = load double, double* %3
%46 = fadd double %45, %44
store double %46, double* %3
br label %47
47: ; preds = %43, %29
%48 = load double, double* %2
%49 = load double, double* %3
%50 = call i32 (i8*, double, double, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %48, double %49)
br label %51
51: ; preds = %47
%52 = load double, double* %2
%53 = fadd double %52, 1.000000e-01
store double %53, double* %2
br label %26
54: ; preds = %26
ret i32 0
}

LLVM IR (-O2):
@.str = [45 x i8] c"# (lft, rgt) = (%lf, %lf), dlt=%lf, xT =%lf\0A\00"
@.str.1 = [10 x i8] c"%lf, %lf\0A\00"
define i32 @main() {
%1 = tail call i32 (i8*, double, double, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), double 2.000000e+00, double -1.000000e+00, double -1.000000e+00, double -4.000000e+00)
br label %2
2: ; preds = %0, %2
%3 = phi double [ -8.000000e+00, %0 ], [ %12, %2 ]
%4 = fadd double %3, -2.000000e+00
%5 = tail call double @fmod(double %4, double -4.000000e+00)
%6 = fadd double %5, 2.000000e+00
%7 = fmul double %4, -4.000000e+00
%8 = fcmp olt double %7, 0.000000e+00
%9 = fadd double %6, -4.000000e+00
%10 = select i1 %8, double %9, double %6
%11 = tail call i32 (i8*, double, double, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %3, double %10)
%12 = fadd double %3, 1.000000e-01
%13 = fcmp ugt double %12, 8.000000e+00
br i1 %13, label %14, label %2
14: ; preds = %2
ret i32 0
}