#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 */
struct timespec {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int EXIT_SUCCESS;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ convert_time_to_string(struct timespec, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ usleep(int);
int main(void) {
  double delay_sec = 2;
  int delay_us = delay_sec * 1000000;
  double num_steps = 10;
  double pmax = 44;
  double pmin = 20;
  double step_height = (pmax - pmin) / num_steps;
  int i;
  struct timespec tv;
  char time_buffer[32];
  FILE *fp = NULL;
  fp = fopen("data/setpoint.csv", "w");
  for (i = 0; i < num_steps + 1; i++) {
    fprintf(stdout, "p%.2f\n", pmin);
    clock_gettime(CLOCK_MONOTONIC, &tv);
    convert_time_to_string(tv, time_buffer);
    fprintf(fp, "%s,%.2f,\n", time_buffer, pmin);
    usleep(delay_us);
    fprintf(stdout, "p%.2f\n", (double)i * step_height + pmin);
    clock_gettime(CLOCK_MONOTONIC, &tv);
    convert_time_to_string(tv, time_buffer);
    fprintf(fp, "%s,%.2f,\n", time_buffer, (double)i * step_height + pmin);
    usleep(delay_us);
  }
  fprintf(stdout, "q\n");
  if (fp != NULL)
    fclose(fp);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xea9(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe94(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
movsd  0xe78(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe63(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe4e(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movq   $0x0,-0x68(%rbp)
lea    0xe56(%rip),%rdi
lea    0xe61(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x68(%rbp)
movl   $0x0,-0x3c(%rbp)
cvtsi2sdl -0x3c(%rbp),%xmm1
movsd  0xe2a(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    12fd <main+0x19d>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
movsd  -0x30(%rbp),%xmm0
lea    0xe22(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
call   1030 <clock_gettime@plt>
lea    -0x60(%rbp),%rsi
mov    -0x40(%rbp),%edi
call   1060 <convert_time_to_string@plt>
mov    -0x68(%rbp),%rax
mov    %eax,%edi
lea    -0x60(%rbp),%rdx
movsd  -0x30(%rbp),%xmm0
lea    0xdee(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1080 <usleep@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
cvtsi2sdl -0x3c(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
lea    0xdb1(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
call   1030 <clock_gettime@plt>
lea    -0x60(%rbp),%rsi
mov    -0x40(%rbp),%edi
call   1060 <convert_time_to_string@plt>
mov    -0x68(%rbp),%rax
mov    %eax,%edi
lea    -0x60(%rbp),%rdx
cvtsi2sdl -0x3c(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
lea    0xd6b(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1080 <usleep@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11f1 <main+0x91>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
lea    0xd48(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpq   $0x0,-0x68(%rbp)
je     1328 <main+0x1c8>
mov    -0x68(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2ca1(%rip),%rax
mov    (%rax),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
lea    0xea3(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,0x8(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    $0xb,%ebp
mov    0x8(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    0x2e31(%rip),%r14
mov    (%r14),%edi
lea    0xe7b(%rip),%rsi
movsd  0xe47(%rip),%xmm0
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    0x2e21(%rip),%r13
mov    0x0(%r13),%edi
mov    %rsp,%r12
mov    %r12,%rsi
call   1030 <clock_gettime@plt>
mov    (%rsp),%edi
lea    0x20(%rsp),%r15
mov    %r15,%rsi
call   1060 <convert_time_to_string@plt>
mov    %ebx,%edi
lea    0xe44(%rip),%rsi
mov    %r15,%rdx
movsd  0xe06(%rip),%xmm0
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    $0x1e8480,%edi
call   1080 <usleep@plt>
mov    (%r14),%edi
movsd  0x10(%rsp),%xmm0
mulsd  0xdec(%rip),%xmm0
addsd  0xddc(%rip),%xmm0
movsd  %xmm0,0x18(%rsp)
lea    0xdfb(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    0x0(%r13),%edi
mov    %r12,%rsi
call   1030 <clock_gettime@plt>
mov    (%rsp),%edi
mov    %r15,%rsi
call   1060 <convert_time_to_string@plt>
mov    %ebx,%edi
lea    0xddb(%rip),%rsi
mov    %r15,%rdx
movsd  0x18(%rsp),%xmm0
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    $0x1e8480,%edi
call   1080 <usleep@plt>
movsd  0x10(%rsp),%xmm0
addsd  0xd90(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
add    $0xffffffff,%ebp
jne    11a0 <main+0x40>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
lea    0xd9e(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
cmpq   $0x0,0x8(%rsp)
je     12b8 <main+0x158>
mov    0x8(%rsp),%rdi
call   1040 <fclose@plt>
mov    0x2d11(%rip),%rax
mov    (%rax),%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@.str = [18 x i8] c"data/setpoint.csv\00"
@.str.1 = [2 x i8] c"w\00"
@stdout = global i32 0
@.str.2 = [7 x i8] c"p%.2f\0A\00"
@CLOCK_MONOTONIC = global i32 0
@.str.3 = [10 x i8] c"%s,%.2f,\0A\00"
@.str.4 = [3 x i8] c"q\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca %struct.timespec
%10 = alloca [32 x i8]
%11 = alloca i32*
store i32 0, i32* %1
store double 2.000000e+00, double* %2
%12 = load double, double* %2
%13 = fmul double %12, 1.000000e+06
%14 = fptosi double %13 to i32
store i32 %14, i32* %3
store double 1.000000e+01, double* %4
store double 4.400000e+01, double* %5
store double 2.000000e+01, double* %6
%15 = load double, double* %5
%16 = load double, double* %6
%17 = fsub double %15, %16
%18 = load double, double* %4
%19 = fdiv double %17, %18
store double %19, double* %7
store i32* null, i32** %11
%20 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %11
store i32 0, i32* %8
br label %21
21: ; preds = %68, %0
%22 = load i32, i32* %8
%23 = sitofp i32 %22 to double
%24 = load double, double* %4
%25 = fadd double %24, 1.000000e+00
%26 = fcmp olt double %23, %25
br i1 %26, label %27, label %71
27: ; preds = %21
%28 = load i32, i32* @stdout
%29 = load double, double* %6
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %29)
%31 = load i32, i32* @CLOCK_MONOTONIC
%32 = call i32 @clock_gettime(i32 %31, %struct.timespec* %9)
%33 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%34 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 @convert_time_to_string(i32 %35, i8* %33)
%37 = load i32*, i32** %11
%38 = ptrtoint i32* %37 to i32
%39 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%40 = load double, double* %6
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %39, double %40)
%42 = load i32, i32* %3
%43 = call i32 @usleep(i32 %42)
%44 = load i32, i32* @stdout
%45 = load i32, i32* %8
%46 = sitofp i32 %45 to double
%47 = load double, double* %7
%48 = load double, double* %6
%49 = call double @llvm.fmuladd.f64(double %46, double %47, double %48)
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %49)
%51 = load i32, i32* @CLOCK_MONOTONIC
%52 = call i32 @clock_gettime(i32 %51, %struct.timespec* %9)
%53 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%54 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 0
%55 = load i32, i32* %54
%56 = call i32 @convert_time_to_string(i32 %55, i8* %53)
%57 = load i32*, i32** %11
%58 = ptrtoint i32* %57 to i32
%59 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%60 = load i32, i32* %8
%61 = sitofp i32 %60 to double
%62 = load double, double* %7
%63 = load double, double* %6
%64 = call double @llvm.fmuladd.f64(double %61, double %62, double %63)
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %59, double %64)
%66 = load i32, i32* %3
%67 = call i32 @usleep(i32 %66)
br label %68
68: ; preds = %27
%69 = load i32, i32* %8
%70 = add nsw i32 %69, 1
store i32 %70, i32* %8
br label %21
71: ; preds = %21
%72 = load i32, i32* @stdout
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%74 = load i32*, i32** %11
%75 = icmp ne i32* %74, null
br i1 %75, label %76, label %79
76: ; preds = %71
%77 = load i32*, i32** %11
%78 = call i32 @fclose(i32* %77)
br label %79
79: ; preds = %76, %71
%80 = load i32, i32* @EXIT_SUCCESS
ret i32 %80
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@.str = [18 x i8] c"data/setpoint.csv\00"
@.str.1 = [2 x i8] c"w\00"
@stdout = global i32 0
@.str.2 = [7 x i8] c"p%.2f\0A\00"
@CLOCK_MONOTONIC = global i32 0
@.str.3 = [10 x i8] c"%s,%.2f,\0A\00"
@.str.4 = [3 x i8] c"q\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.timespec
%2 = alloca [32 x i8]
%3 = bitcast %struct.timespec* %1 to i8*
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%7 = ptrtoint i32* %5 to i64
%8 = trunc i64 %7 to i32
br label %9
9: ; preds = %0, %9
%10 = phi i32 [ 0, %0 ], [ %29, %9 ]
%11 = sitofp i32 %10 to double
%12 = load i32, i32* @stdout
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double 2.000000e+01)
%14 = load i32, i32* @CLOCK_MONOTONIC
%15 = call i32 @clock_gettime(i32 %14, %struct.timespec* %1)
%16 = load i32, i32* %6
%17 = call i32 @convert_time_to_string(i32 %16, i8* %4)
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %4, double 2.000000e+01)
%19 = call i32 @usleep(i32 2000000)
%20 = load i32, i32* @stdout
%21 = call double @llvm.fmuladd.f64(double %11, double 2.400000e+00, double 2.000000e+01)
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %21)
%23 = load i32, i32* @CLOCK_MONOTONIC
%24 = call i32 @clock_gettime(i32 %23, %struct.timespec* %1)
%25 = load i32, i32* %6
%26 = call i32 @convert_time_to_string(i32 %25, i8* %4)
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %4, double %21)
%28 = call i32 @usleep(i32 2000000)
%29 = add nuw nsw i32 %10, 1
%30 = icmp eq i32 %29, 11
br i1 %30, label %31, label %9
31: ; preds = %9
%32 = load i32, i32* @stdout
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%34 = icmp eq i32* %5, null
br i1 %34, label %37, label %35
35: ; preds = %31
%36 = call i32 @fclose(i32* %5)
br label %37
37: ; preds = %35, %31
%38 = load i32, i32* @EXIT_SUCCESS
ret i32 %38
}