#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 atof(char *);
int /*<<< orphan*/ printf(char *, ...);
int sqrt(int);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  if (argc != 5) {
    usage();
    return 1;
  }
  double wheel_diameter_m = atof(argv[1]);
  double steps_ = atof(argv[2]);
  double max_speed_mps = atof(argv[3]);
  double acceleration_duration_s = atof(argv[4]);
  printf("/* This file has been generated using the command:\n"
         " * > step_table %f %f %f %f\n"
         " */\n"
         "\n"
         "#ifndef ACCELERATIONTABLE_H_\n"
         "#define ACCELERATIONTABLE_H_\n"
         "\n"
         "#include <avr/pgmspace.h>\n"
         "\n"
         "static const unsigned short DELAYS[] PROGMEM = {\n",
         wheel_diameter_m, steps_, max_speed_mps, acceleration_duration_s);
  double acceleration_mpss = max_speed_mps / acceleration_duration_s;
  double distance_m = 0.5 * acceleration_mpss * acceleration_duration_s *
                      acceleration_duration_s;
  double distance_per_step_m = wheel_diameter_m * 3.1415927 / 400;
  double distance_ = distance_m / distance_per_step_m;
  int c = 0;
  double x_;
  double x_m;
  double T_s;
  double T_us;
  for (x_ = 0; x_ < distance_ - 1; x_++) {
    x_m = (x_ + 0.5) * distance_per_step_m;
    T_s = 1 / sqrt(2 * acceleration_mpss * x_m);
    T_us = T_s * 1000.;
    if (T_us < 65536) {
      c++;
      if (c < 8) {
        printf("%5d, ", (int)T_us);
      } else {
        printf("%5d,\n", (int)T_us);
        c = 0;
      }
    }
  }
  x_m = (x_ + 0.5) * distance_per_step_m;
  T_s = 1 / sqrt(2 * acceleration_mpss * x_m);
  T_us = T_s * 1000.;
  if (T_us < 65536) {
    printf("%5d\n", (int)T_us);
  }
  printf("};\n"
         "\n"
         "#endif /* ACCELERATIONTABLE_H_ */\n");
}


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   $0x5,-0x8(%rbp)
je     1176 <main+0x36>
mov    $0x0,%al
call   1050 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c2 <main+0x282>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm3
lea    0xe5f(%rip),%rdi
mov    $0x4,%al
call   1040 <printf@plt>
movsd  -0x28(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe19(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xdf5(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  0xde0(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
divsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm0
movsd  0xdbf(%rip),%xmm2
subsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    1337 <main+0x1f7>
movsd  0xda1(%rip),%xmm0
addsd  -0x60(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  0xdaa(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
mulsd  -0x68(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1060 <sqrt@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  0xd74(%rip),%xmm0
mulsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  0xd5a(%rip),%xmm0
ucomisd -0x78(%rbp),%xmm0
jbe    131b <main+0x1db>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
cmpl   $0x8,-0x54(%rbp)
jge    12fc <main+0x1bc>
cvttsd2si -0x78(%rbp),%esi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1316 <main+0x1d6>
cvttsd2si -0x78(%rbp),%esi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x54(%rbp)
jmp    131b <main+0x1db>
jmp    1320 <main+0x1e0>
movsd  0xcf0(%rip),%xmm0
addsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    1247 <main+0x107>
movsd  0xcd1(%rip),%xmm0
addsd  -0x60(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  0xcda(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
mulsd  -0x68(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1060 <sqrt@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  0xca4(%rip),%xmm0
mulsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  0xc8a(%rip),%xmm0
ucomisd -0x78(%rbp),%xmm0
jbe    13b4 <main+0x274>
cvttsd2si -0x78(%rbp),%esi
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
cmp    $0x5,%edi
jne    12c8 <main+0x178>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1040 <atof@plt>
movsd  %xmm0,0x8(%rsp)
mov    0x10(%rbx),%rdi
call   1040 <atof@plt>
movsd  %xmm0,0x10(%rsp)
mov    0x18(%rbx),%rdi
call   1040 <atof@plt>
movsd  %xmm0,(%rsp)
mov    0x20(%rbx),%rdi
call   1040 <atof@plt>
movaps %xmm0,%xmm3
movsd  %xmm0,0x18(%rsp)
lea    0xe7b(%rip),%rdi
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
movsd  (%rsp),%xmm2
mov    $0x4,%al
call   1050 <printf@plt>
movsd  (%rsp),%xmm2
movsd  0x18(%rsp),%xmm4
divsd  %xmm4,%xmm2
movsd  0xe24(%rip),%xmm0
movapd %xmm2,%xmm1
movapd %xmm2,%xmm3
mulsd  %xmm0,%xmm1
mulsd  %xmm4,%xmm1
movsd  0x8(%rsp),%xmm2
mulsd  0xe0e(%rip),%xmm2
divsd  0xe0e(%rip),%xmm2
mulsd  %xmm4,%xmm1
movsd  %xmm2,0x8(%rsp)
divsd  %xmm2,%xmm1
addsd  0xe00(%rip),%xmm1
xorpd  %xmm2,%xmm2
movsd  %xmm1,0x18(%rsp)
ucomisd %xmm2,%xmm1
addsd  %xmm3,%xmm3
movsd  %xmm3,(%rsp)
jbe    12e2 <main+0x192>
xor    %r12d,%r12d
lea    0xec5(%rip),%r14
lea    0xec4(%rip),%r15
xor    %ebx,%ebx
jmp    126a <main+0x11a>
nopw   0x0(%rax,%rax,1)
movsd  0x10(%rsp),%xmm2
addsd  0xdc2(%rip),%xmm2
movsd  0x18(%rsp),%xmm0
ucomisd %xmm2,%xmm0
jbe    12d6 <main+0x186>
movsd  %xmm2,0x10(%rsp)
movapd %xmm2,%xmm0
addsd  0xd84(%rip),%xmm0
mulsd  0x8(%rsp),%xmm0
mulsd  (%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1070 <sqrt@plt>
lea    0x1(%rax),%ecx
cmp    $0x3,%ecx
cmovae %r12d,%eax
cltq
imul   $0x3e8,%rax,%rsi
cmp    $0xffff,%rsi
jg     1250 <main+0x100>
lea    0x1(%rbx),%ebp
cmp    $0x7,%ebx
mov    %r15,%rdi
cmovl  %r14,%rdi
cmovge %r12d,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%ebx
jmp    1250 <main+0x100>
xor    %eax,%eax
call   1060 <usage@plt>
mov    $0x1,%ebx
jmp    1335 <main+0x1e5>
addsd  0xd22(%rip),%xmm2
movapd %xmm2,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  (%rsp),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1070 <sqrt@plt>
lea    0x1(%rax),%ecx
xor    %ebx,%ebx
cmp    $0x3,%ecx
cmovae %ebx,%eax
cltq
imul   $0x3e8,%rax,%rsi
cmp    $0xffff,%rsi
jg     1329 <main+0x1d9>
lea    0xdee(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xde5(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [220 x i8] c"/* This file has been generated using the command:\0A * > step_table %f %f %f %f\0A */\0A\0A#ifndef ACCELERATIONTABLE_H_\0A#define ACCELERATIONTABLE_H_\0A\0A#include <avr/pgmspace.h>\0A\0Astatic const unsigned short DELAYS[] PROGMEM = {\0A\00"
@.str.1 = [6 x i8] c"%5d, \00"
@.str.2 = [6 x i8] c"%5d,\0A\00"
@.str.3 = [5 x i8] c"%5d\0A\00"
@.str.4 = [39 x i8] c"};\0A\0A#endif /* ACCELERATIONTABLE_H_ */\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 double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca i32
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 5
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 (...) @usage()
store i32 1, i32* %3
br label %123
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call double @atof(i8* %26)
store double %27, double* %6
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call double @atof(i8* %30)
store double %31, double* %7
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 3
%34 = load i8*, i8** %33
%35 = call double @atof(i8* %34)
store double %35, double* %8
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 4
%38 = load i8*, i8** %37
%39 = call double @atof(i8* %38)
store double %39, double* %9
%40 = load double, double* %6
%41 = load double, double* %7
%42 = load double, double* %8
%43 = load double, double* %9
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([220 x i8], [220 x i8]* @.str, i64 0, i64 0), double %40, double %41, double %42, double %43)
%45 = load double, double* %8
%46 = load double, double* %9
%47 = fdiv double %45, %46
store double %47, double* %10
%48 = load double, double* %10
%49 = fmul double 5.000000e-01, %48
%50 = load double, double* %9
%51 = fmul double %49, %50
%52 = load double, double* %9
%53 = fmul double %51, %52
store double %53, double* %11
%54 = load double, double* %6
%55 = fmul double %54, 0x400921FB5A7ED197
%56 = fdiv double %55, 4.000000e+02
store double %56, double* %12
%57 = load double, double* %11
%58 = load double, double* %12
%59 = fdiv double %57, %58
store double %59, double* %13
store i32 0, i32* %14
store double 0.000000e+00, double* %15
br label %60
60: ; preds = %97, %23
%61 = load double, double* %15
%62 = load double, double* %13
%63 = fsub double %62, 1.000000e+00
%64 = fcmp olt double %61, %63
br i1 %64, label %65, label %100
65: ; preds = %60
%66 = load double, double* %15
%67 = fadd double %66, 5.000000e-01
%68 = load double, double* %12
%69 = fmul double %67, %68
store double %69, double* %16
%70 = load double, double* %10
%71 = fmul double 2.000000e+00, %70
%72 = load double, double* %16
%73 = fmul double %71, %72
%74 = fptosi double %73 to i32
%75 = call i32 @sqrt(i32 %74)
%76 = sdiv i32 1, %75
%77 = sitofp i32 %76 to double
store double %77, double* %17
%78 = load double, double* %17
%79 = fmul double %78, 1.000000e+03
store double %79, double* %18
%80 = load double, double* %18
%81 = fcmp olt double %80, 6.553600e+04
br i1 %81, label %82, label %96
82: ; preds = %65
%83 = load i32, i32* %14
%84 = add nsw i32 %83, 1
store i32 %84, i32* %14
%85 = load i32, i32* %14
%86 = icmp slt i32 %85, 8
br i1 %86, label %87, label %91
87: ; preds = %82
%88 = load double, double* %18
%89 = fptosi double %88 to i32
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %89)
br label %95
91: ; preds = %82
%92 = load double, double* %18
%93 = fptosi double %92 to i32
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %93)
store i32 0, i32* %14
br label %95
95: ; preds = %91, %87
br label %96
96: ; preds = %95, %65
br label %97
97: ; preds = %96
%98 = load double, double* %15
%99 = fadd double %98, 1.000000e+00
store double %99, double* %15
br label %60
100: ; preds = %60
%101 = load double, double* %15
%102 = fadd double %101, 5.000000e-01
%103 = load double, double* %12
%104 = fmul double %102, %103
store double %104, double* %16
%105 = load double, double* %10
%106 = fmul double 2.000000e+00, %105
%107 = load double, double* %16
%108 = fmul double %106, %107
%109 = fptosi double %108 to i32
%110 = call i32 @sqrt(i32 %109)
%111 = sdiv i32 1, %110
%112 = sitofp i32 %111 to double
store double %112, double* %17
%113 = load double, double* %17
%114 = fmul double %113, 1.000000e+03
store double %114, double* %18
%115 = load double, double* %18
%116 = fcmp olt double %115, 6.553600e+04
br i1 %116, label %117, label %121
117: ; preds = %100
%118 = load double, double* %18
%119 = fptosi double %118 to i32
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %119)
br label %121
121: ; preds = %117, %100
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %123
123: ; preds = %121, %21
%124 = load i32, i32* %3
ret i32 %124
}

LLVM IR (-O2):
@.str = [220 x i8] c"/* This file has been generated using the command:\0A * > step_table %f %f %f %f\0A */\0A\0A#ifndef ACCELERATIONTABLE_H_\0A#define ACCELERATIONTABLE_H_\0A\0A#include <avr/pgmspace.h>\0A\0Astatic const unsigned short DELAYS[] PROGMEM = {\0A\00"
@.str.1 = [6 x i8] c"%5d, \00"
@.str.2 = [6 x i8] c"%5d,\0A\00"
@.str.3 = [5 x i8] c"%5d\0A\00"
@str = [38 x i8] c"};\0A\0A#endif /* ACCELERATIONTABLE_H_ */\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 5
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 (...) @usage()
br label %74
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call double @atof(i8* %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call double @atof(i8* %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 3
%14 = load i8*, i8** %13
%15 = tail call double @atof(i8* %14)
%16 = getelementptr inbounds i8*, i8** %1, i64 4
%17 = load i8*, i8** %16
%18 = tail call double @atof(i8* %17)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([220 x i8], [220 x i8]* @.str, i64 0, i64 0), double %9, double %12, double %15, double %18)
%20 = fdiv double %15, %18
%21 = fmul double %20, 5.000000e-01
%22 = fmul double %18, %21
%23 = fmul double %18, %22
%24 = fmul double %9, 0x400921FB5A7ED197
%25 = fdiv double %24, 4.000000e+02
%26 = fdiv double %23, %25
%27 = fadd double %26, -1.000000e+00
%28 = fcmp ogt double %27, 0.000000e+00
%29 = fmul double %20, 2.000000e+00
br i1 %28, label %30, label %57
30: ; preds = %6, %51
%31 = phi double [ %53, %51 ], [ 0.000000e+00, %6 ]
%32 = phi i32 [ %52, %51 ], [ 0, %6 ]
%33 = fadd double %31, 5.000000e-01
%34 = fmul double %25, %33
%35 = fmul double %29, %34
%36 = fptosi double %35 to i32
%37 = tail call i32 @sqrt(i32 %36)
%38 = add i32 %37, 1
%39 = icmp ult i32 %38, 3
%40 = select i1 %39, i32 %37, i32 0
%41 = sext i32 %40 to i64
%42 = mul nsw i64 %41, 1000
%43 = icmp slt i64 %42, 65536
br i1 %43, label %44, label %51
44: ; preds = %30
%45 = icmp slt i32 %32, 7
%46 = add nsw i32 %32, 1
%47 = select i1 %45, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%48 = select i1 %45, i32 %46, i32 0
%49 = trunc i64 %42 to i32
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %47, i32 %49)
br label %51
51: ; preds = %44, %30
%52 = phi i32 [ %32, %30 ], [ %48, %44 ]
%53 = fadd double %31, 1.000000e+00
%54 = fcmp olt double %53, %27
br i1 %54, label %30, label %55
55: ; preds = %51
%56 = fadd double %53, 5.000000e-01
br label %57
57: ; preds = %6, %55
%58 = phi double [ %56, %55 ], [ 5.000000e-01, %6 ]
%59 = fmul double %25, %58
%60 = fmul double %29, %59
%61 = fptosi double %60 to i32
%62 = tail call i32 @sqrt(i32 %61)
%63 = add i32 %62, 1
%64 = icmp ult i32 %63, 3
%65 = select i1 %64, i32 %62, i32 0
%66 = sext i32 %65 to i64
%67 = mul nsw i64 %66, 1000
%68 = icmp slt i64 %67, 65536
br i1 %68, label %69, label %72
69: ; preds = %57
%70 = trunc i64 %67 to i32
%71 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %70)
br label %72
72: ; preds = %69, %57
%73 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
br label %74
74: ; preds = %72, %4
%75 = phi i32 [ 1, %4 ], [ 0, %72 ]
ret i32 %75
}