#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 int incr;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void generate_tune1(void) {
  int start, end;
  int ndiv;
  int incr;
  int cicosr;
  int sdnominal;
  int i, temp;
  start = 758;
  end = start + 325;
  printf("const struct stfm1000_tune1\n"
         "stfm1000_tune1_table[STFM1000_FREQUENCY_100KHZ_RANGE] = {\n");
  for (i = start; i < end; i++) {
    ndiv = (int)((i + 14) / 15) - 48;
    incr = i - (int)(i / 15) * 15;
    cicosr = (int)(i * 2 / 3.0 / 16.0 + 0.5);
    sdnominal = (int)(i * 100.0e3 / 1.5 / (double)cicosr / 2.0 / 2.0 * 2.0 *
                      8.0 * 256.0 / 228.0e3 * 65536);
    temp = 0x00000000;
    temp = temp | ((cicosr << 9) & 0x00007E00);
    temp = temp | ((ndiv << 4) & 0x000001FF);
    temp = temp | ((incr)&0x000001FF);
    printf("\t[%d - STFM1000_FREQUENCY_100KHZ_MIN] = "
           "{ .tune1 = 0x%08x, .sdnom = 0x%08x },\n",
           i, temp, sdnominal);
  }
  printf("};\n");
}


x86 assembly (clang, -O0):
<generate_tune1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x2f6,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x145,%eax
mov    %eax,-0x8(%rbp)
lea    0xf1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1297 <generate_tune1+0x187>
mov    -0x1c(%rbp),%eax
add    $0xe,%eax
mov    $0xf,%ecx
cltd
idiv   %ecx
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0xf,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
imul   $0xf,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  0xeba(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xea6(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe92(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  0xe72(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe5e(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe41(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe35(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe29(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe15(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe01(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xded(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xdd9(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x14(%rbp),%ecx
shl    $0x9,%ecx
and    $0x7e00,%ecx
or     %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0xc(%rbp),%ecx
shl    $0x4,%ecx
and    $0x1ff,%ecx
or     %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x10(%rbp),%ecx
and    $0x1ff,%ecx
or     %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113e <generate_tune1+0x2e>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_tune1>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xf79(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2f6,%ebx
movsd  0xec0(%rip),%xmm0
mov    $0x5ec,%ebp
mov    $0x88888889,%r15d
lea    0xf06(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm0,(%rsp)
mov    %ebx,%eax
imul   %r15,%rax
shr    $0x23,%rax
mov    %eax,%ecx
shl    $0x4,%ecx
sub    %ecx,%eax
lea    0xe(%rbx),%ecx
movzwl %cx,%ecx
imul   $0x8889,%ecx,%edx
shr    $0xf,%edx
and    $0x1f0,%edx
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
add    %ebx,%eax
divsd  0xe6c(%rip),%xmm0
mulsd  0xe6c(%rip),%xmm0
movsd  0xe6c(%rip),%xmm2
addsd  %xmm2,%xmm0
cvttsd2si %xmm0,%esi
movsd  (%rsp),%xmm1
mulsd  0xe5f(%rip),%xmm1
divsd  0xe5f(%rip),%xmm1
cvttpd2dq %xmm0,%xmm0
cvtdq2pd %xmm0,%xmm0
divsd  %xmm0,%xmm1
mulsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm1,%xmm1
mulsd  0xe47(%rip),%xmm1
mulsd  0xe47(%rip),%xmm1
divsd  0xe47(%rip),%xmm1
mulsd  0xe47(%rip),%xmm1
cvttsd2si %xmm1,%ecx
and    $0x3f,%esi
shl    $0x9,%esi
add    $0x100,%edx
and    $0x1f0,%edx
or     %eax,%edx
or     %esi,%edx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movsd  (%rsp),%xmm0
addsd  0xe1c(%rip),%xmm0
add    $0x1,%ebx
add    $0x2,%ebp
cmp    $0x876,%ebp
jne    1160 <generate_tune1+0x40>
lea    0xeb0(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [87 x i8] c"const struct stfm1000_tune1\0Astfm1000_tune1_table[STFM1000_FREQUENCY_100KHZ_RANGE] = {\0A\00"
@.str.1 = [79 x i8] c"\09[%d - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x%08x, .sdnom = 0x%08x },\0A\00"
@.str.2 = [4 x i8] c"};\0A\00"
define void @generate_tune1() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 758, i32* %1
%9 = load i32, i32* %1
%10 = add nsw i32 %9, 325
store i32 %10, i32* %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* %1
store i32 %12, i32* %7
br label %13
13: ; preds = %67, %0
%14 = load i32, i32* %7
%15 = load i32, i32* %2
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %70
17: ; preds = %13
%18 = load i32, i32* %7
%19 = add nsw i32 %18, 14
%20 = sdiv i32 %19, 15
%21 = sub nsw i32 %20, 48
store i32 %21, i32* %3
%22 = load i32, i32* %7
%23 = load i32, i32* %7
%24 = sdiv i32 %23, 15
%25 = mul nsw i32 %24, 15
%26 = sub nsw i32 %22, %25
store i32 %26, i32* %4
%27 = load i32, i32* %7
%28 = mul nsw i32 %27, 2
%29 = sitofp i32 %28 to double
%30 = fdiv double %29, 3.000000e+00
%31 = fdiv double %30, 1.600000e+01
%32 = fadd double %31, 5.000000e-01
%33 = fptosi double %32 to i32
store i32 %33, i32* %5
%34 = load i32, i32* %7
%35 = sitofp i32 %34 to double
%36 = fmul double %35, 1.000000e+05
%37 = fdiv double %36, 1.500000e+00
%38 = load i32, i32* %5
%39 = sitofp i32 %38 to double
%40 = fdiv double %37, %39
%41 = fdiv double %40, 2.000000e+00
%42 = fdiv double %41, 2.000000e+00
%43 = fmul double %42, 2.000000e+00
%44 = fmul double %43, 8.000000e+00
%45 = fmul double %44, 2.560000e+02
%46 = fdiv double %45, 2.280000e+05
%47 = fmul double %46, 6.553600e+04
%48 = fptosi double %47 to i32
store i32 %48, i32* %6
store i32 0, i32* %8
%49 = load i32, i32* %8
%50 = load i32, i32* %5
%51 = shl i32 %50, 9
%52 = and i32 %51, 32256
%53 = or i32 %49, %52
store i32 %53, i32* %8
%54 = load i32, i32* %8
%55 = load i32, i32* %3
%56 = shl i32 %55, 4
%57 = and i32 %56, 511
%58 = or i32 %54, %57
store i32 %58, i32* %8
%59 = load i32, i32* %8
%60 = load i32, i32* %4
%61 = and i32 %60, 511
%62 = or i32 %59, %61
store i32 %62, i32* %8
%63 = load i32, i32* %7
%64 = load i32, i32* %8
%65 = load i32, i32* %6
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.1, i64 0, i64 0), i32 %63, i32 %64, i32 %65)
br label %67
67: ; preds = %17
%68 = load i32, i32* %7
%69 = add nsw i32 %68, 1
store i32 %69, i32* %7
br label %13
70: ; preds = %13
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [79 x i8] c"\09[%d - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x%08x, .sdnom = 0x%08x },\0A\00"
@str = [86 x i8] c"const struct stfm1000_tune1\0Astfm1000_tune1_table[STFM1000_FREQUENCY_100KHZ_RANGE] = {\00"
@str.3 = [3 x i8] c"};\00"
define void @generate_tune1() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([86 x i8], [86 x i8]* @str, i64 0, i64 0))
br label %2
2: ; preds = %0, %2
%3 = phi i32 [ 758, %0 ], [ %37, %2 ]
%4 = trunc i32 %3 to i16
%5 = add i16 %4, 14
%6 = udiv i16 %5, 15
%7 = zext i16 %6 to i32
%8 = urem i16 %4, 15
%9 = zext i16 %8 to i32
%10 = shl nuw nsw i32 %3, 1
%11 = sitofp i32 %10 to double
%12 = fdiv double %11, 3.000000e+00
%13 = fmul double %12, 6.250000e-02
%14 = fadd double %13, 5.000000e-01
%15 = fptosi double %14 to i32
%16 = sitofp i32 %3 to double
%17 = fmul double %16, 1.000000e+05
%18 = fdiv double %17, 1.500000e+00
%19 = sitofp i32 %15 to double
%20 = fdiv double %18, %19
%21 = fmul double %20, 5.000000e-01
%22 = fmul double %21, 5.000000e-01
%23 = fmul double %22, 2.000000e+00
%24 = fmul double %23, 8.000000e+00
%25 = fmul double %24, 2.560000e+02
%26 = fdiv double %25, 2.280000e+05
%27 = fmul double %26, 6.553600e+04
%28 = fptosi double %27 to i32
%29 = shl i32 %15, 9
%30 = and i32 %29, 32256
%31 = shl nuw nsw i32 %7, 4
%32 = add nuw nsw i32 %31, 256
%33 = and i32 %32, 496
%34 = or i32 %33, %9
%35 = or i32 %34, %30
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 x i8]* @.str.1, i64 0, i64 0), i32 %3, i32 %35, i32 %28)
%37 = add nuw nsw i32 %3, 1
%38 = icmp eq i32 %37, 1083
br i1 %38, label %39, label %2
39: ; preds = %2
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.3, i64 0, i64 0))
ret void
}