#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 ceil(double);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, double, ...);
int /*<<< orphan*/ puts(char *);
int main() {
  int i, j;
  double q, r, err, max_err = 0, max_s_err = 0;
  puts("/* This table has been generated by divtab-sh4.c.  */");
  puts("\t.balign 4");
  for (i = -128; i < 128; i++) {
    int n = 0;
    if (i == 0) {
      puts("LOCAL(div_table_clz):\n\t.byte\t0");
      continue;
    }
    for (j = i < 0 ? -i : i; j < 128; j += j)
      n++;
    printf("\t.byte\t%d\n", n - 7);
  }
  puts("/* 1/-128 .. 1/127, normalized.  There is an implicit leading 1 in bit "
       "32,\n   or in bit 33 for powers of two.  */\n	.balign 4");
  for (i = -128; i < 128; i++) {
    if (i == 0) {
      puts("LOCAL(div_table_inv):\n\t.long\t0x0");
      continue;
    }
    j = i < 0 ? -i : i;
    while (j < 64)
      j += j;
    q = 4. * (1 << 30) * 128 / j;
    r = ceil(q);
    printf("\t.long\t0x%X\n", (unsigned)r);
    err = r - q;
    if (err > max_err)
      max_err = err;
    err = err * j / 128;
    if (err > max_s_err)
      max_s_err = err;
  }
  printf("\t/* maximum error: %f scaled: %f*/\n", max_err, max_s_err);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
lea    0xeaa(%rip),%rdi
call   1030 <puts@plt>
lea    0xf70(%rip),%rdi
call   1030 <puts@plt>
movl   $0xffffff80,-0x8(%rbp)
cmpl   $0x80,-0x8(%rbp)
jge    121a <main+0xda>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11ad <main+0x6d>
lea    0xea3(%rip),%rdi
call   1030 <puts@plt>
jmp    120c <main+0xcc>
cmpl   $0x0,-0x8(%rbp)
jge    11c4 <main+0x84>
xor    %eax,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x40(%rbp)
jmp    11ca <main+0x8a>
mov    -0x8(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x80,-0xc(%rbp)
jge    11f4 <main+0xb4>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0xc(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11d0 <main+0x90>
mov    -0x3c(%rbp),%eax
sub    $0x7,%eax
cvtsi2sd %eax,%xmm0
lea    0xe60(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117e <main+0x3e>
lea    0xe4f(%rip),%rdi
call   1030 <puts@plt>
movl   $0xffffff80,-0x8(%rbp)
cmpl   $0x80,-0x8(%rbp)
jge    1345 <main+0x205>
cmpl   $0x0,-0x8(%rbp)
jne    1255 <main+0x115>
lea    0xea2(%rip),%rdi
call   1030 <puts@plt>
jmp    1337 <main+0x1f7>
cmpl   $0x0,-0x8(%rbp)
jge    126c <main+0x12c>
xor    %eax,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    1272 <main+0x132>
mov    -0x8(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x40,-0xc(%rbp)
jge    1290 <main+0x150>
mov    -0xc(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1278 <main+0x138>
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  0xd63(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <ceil@plt>
movsd  %xmm0,-0x20(%rbp)
cvttsd2si -0x20(%rbp),%rax
mov    %eax,%eax
cvtsi2sd %rax,%xmm0
lea    0xe45(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    12f9 <main+0x1b9>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xcf9(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    1332 <main+0x1f2>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1337 <main+0x1f7>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    122d <main+0xed>
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
lea    0xdc5(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
lea    0xf87(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffff80,%ebp
lea    0xeda(%rip),%r14
lea    0xef2(%rip),%rbx
jmp    119f <main+0x5f>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0xfffffff9,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
add    $0x1,%ebp
cmp    $0x80,%ebp
je     11da <main+0x9a>
test   %ebp,%ebp
je     11d0 <main+0x90>
mov    %ebp,%ecx
neg    %ecx
cmovs  %ebp,%ecx
xor    %eax,%eax
cmp    $0x7f,%ecx
ja     1180 <main+0x40>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%eax
lea    (%rcx,%rcx,1),%edx
cmp    $0x40,%ecx
mov    %edx,%ecx
jl     11c0 <main+0x80>
jmp    1180 <main+0x40>
nop
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    1194 <main+0x54>
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffff80,%ebp
xorpd  %xmm1,%xmm1
lea    0xef7(%rip),%r14
lea    0xf11(%rip),%rbx
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
jmp    122d <main+0xed>
nopl   0x0(%rax)
mov    %r14,%rdi
call   1030 <puts@plt>
movsd  0x10(%rsp),%xmm1
add    $0x1,%ebp
cmp    $0x80,%ebp
je     12db <main+0x19b>
test   %ebp,%ebp
movsd  %xmm1,0x10(%rsp)
je     1210 <main+0xd0>
mov    %ebp,%eax
neg    %eax
cmovs  %ebp,%eax
xchg   %ax,%ax
mov    %eax,%ecx
lea    (%rcx,%rcx,1),%eax
cmp    $0x40,%ecx
jl     1240 <main+0x100>
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
movsd  %xmm1,0x28(%rsp)
movsd  0xda1(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x20(%rsp)
call   1040 <ceil@plt>
movsd  %xmm0,0x18(%rsp)
cvttsd2si %xmm0,%rax
mov    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x18(%rsp),%xmm2
subsd  0x20(%rsp),%xmm2
movapd %xmm2,%xmm0
maxsd  0x8(%rsp),%xmm0
mulsd  0x28(%rsp),%xmm2
mulsd  0xd57(%rip),%xmm2
movsd  0x10(%rsp),%xmm1
ucomisd %xmm1,%xmm2
jbe    12d0 <main+0x190>
movsd  %xmm0,0x8(%rsp)
movapd %xmm2,%xmm1
jmp    121e <main+0xde>
nopl   0x0(%rax)
movsd  %xmm0,0x8(%rsp)
jmp    121e <main+0xde>
lea    0xe39(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x2,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [54 x i8] c"/* This table has been generated by divtab-sh4.c. */\00"
@.str.1 = [11 x i8] c"\09.balign 4\00"
@.str.2 = [31 x i8] c"LOCAL(div_table_clz):\0A\09.byte\090\00"
@.str.3 = [11 x i8] c"\09.byte\09%d\0A\00"
@.str.4 = [125 x i8] c"/* 1/-128 .. 1/127, normalized. There is an implicit leading 1 in bit 32,\0A or in bit 33 for powers of two. */\0A\09.balign 4\00"
@.str.5 = [33 x i8] c"LOCAL(div_table_inv):\0A\09.long\090x0\00"
@.str.6 = [13 x i8] c"\09.long\090x%X\0A\00"
@.str.7 = [36 x i8] c"\09/* maximum error: %f scaled: %f*/\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
store i32 0, i32* %1
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
%10 = call i32 @puts(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 -128, i32* %2
br label %12
12: ; preds = %45, %0
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 128
br i1 %14, label %15, label %48
15: ; preds = %12
store i32 0, i32* %9
%16 = load i32, i32* %2
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @puts(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %45
20: ; preds = %15
%21 = load i32, i32* %2
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* %2
%25 = sub nsw i32 0, %24
br label %28
26: ; preds = %20
%27 = load i32, i32* %2
br label %28
28: ; preds = %26, %23
%29 = phi i32 [ %25, %23 ], [ %27, %26 ]
store i32 %29, i32* %3
br label %30
30: ; preds = %36, %28
%31 = load i32, i32* %3
%32 = icmp slt i32 %31, 128
br i1 %32, label %33, label %40
33: ; preds = %30
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
br label %36
36: ; preds = %33
%37 = load i32, i32* %3
%38 = load i32, i32* %3
%39 = add nsw i32 %38, %37
store i32 %39, i32* %3
br label %30
40: ; preds = %30
%41 = load i32, i32* %9
%42 = sub nsw i32 %41, 7
%43 = sitofp i32 %42 to double
%44 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double %43)
br label %45
45: ; preds = %40, %18
%46 = load i32, i32* %2
%47 = add nsw i32 %46, 1
store i32 %47, i32* %2
br label %12
48: ; preds = %12
%49 = call i32 @puts(i8* getelementptr inbounds ([125 x i8], [125 x i8]* @.str.4, i64 0, i64 0))
store i32 -128, i32* %2
br label %50
50: ; preds = %105, %48
%51 = load i32, i32* %2
%52 = icmp slt i32 %51, 128
br i1 %52, label %53, label %108
53: ; preds = %50
%54 = load i32, i32* %2
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %53
%57 = call i32 @puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
br label %105
58: ; preds = %53
%59 = load i32, i32* %2
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = load i32, i32* %2
%63 = sub nsw i32 0, %62
br label %66
64: ; preds = %58
%65 = load i32, i32* %2
br label %66
66: ; preds = %64, %61
%67 = phi i32 [ %63, %61 ], [ %65, %64 ]
store i32 %67, i32* %3
br label %68
68: ; preds = %71, %66
%69 = load i32, i32* %3
%70 = icmp slt i32 %69, 64
br i1 %70, label %71, label %75
71: ; preds = %68
%72 = load i32, i32* %3
%73 = load i32, i32* %3
%74 = add nsw i32 %73, %72
store i32 %74, i32* %3
br label %68
75: ; preds = %68
%76 = load i32, i32* %3
%77 = sitofp i32 %76 to double
%78 = fdiv double 0x4260000000000000, %77
store double %78, double* %4
%79 = load double, double* %4
%80 = call double @llvm.ceil.f64(double %79)
store double %80, double* %5
%81 = load double, double* %5
%82 = fptoui double %81 to i32
%83 = uitofp i32 %82 to double
%84 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), double %83)
%85 = load double, double* %5
%86 = load double, double* %4
%87 = fsub double %85, %86
store double %87, double* %6
%88 = load double, double* %6
%89 = load double, double* %7
%90 = fcmp ogt double %88, %89
br i1 %90, label %91, label %93
91: ; preds = %75
%92 = load double, double* %6
store double %92, double* %7
br label %93
93: ; preds = %91, %75
%94 = load double, double* %6
%95 = load i32, i32* %3
%96 = sitofp i32 %95 to double
%97 = fmul double %94, %96
%98 = fdiv double %97, 1.280000e+02
store double %98, double* %6
%99 = load double, double* %6
%100 = load double, double* %8
%101 = fcmp ogt double %99, %100
br i1 %101, label %102, label %104
102: ; preds = %93
%103 = load double, double* %6
store double %103, double* %8
br label %104
104: ; preds = %102, %93
br label %105
105: ; preds = %104, %56
%106 = load i32, i32* %2
%107 = add nsw i32 %106, 1
store i32 %107, i32* %2
br label %50
108: ; preds = %50
%109 = load double, double* %7
%110 = load double, double* %8
%111 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), double %109, double %110)
%112 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [54 x i8] c"/* This table has been generated by divtab-sh4.c. */\00"
@.str.1 = [11 x i8] c"\09.balign 4\00"
@.str.2 = [31 x i8] c"LOCAL(div_table_clz):\0A\09.byte\090\00"
@.str.3 = [11 x i8] c"\09.byte\09%d\0A\00"
@.str.4 = [125 x i8] c"/* 1/-128 .. 1/127, normalized. There is an implicit leading 1 in bit 32,\0A or in bit 33 for powers of two. */\0A\09.balign 4\00"
@.str.5 = [33 x i8] c"LOCAL(div_table_inv):\0A\09.long\090x0\00"
@.str.6 = [13 x i8] c"\09.long\090x%X\0A\00"
@.str.7 = [36 x i8] c"\09/* maximum error: %f scaled: %f*/\0A\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %3
3: ; preds = %0, %22
%4 = phi i32 [ -128, %0 ], [ %23, %22 ]
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %22
8: ; preds = %3
%9 = tail call i32 @llvm.abs.i32(i32 %4, i1 true)
%10 = icmp ult i32 %9, 128
br i1 %10, label %11, label %17
11: ; preds = %8, %11
%12 = phi i32 [ %14, %11 ], [ 0, %8 ]
%13 = phi i32 [ %15, %11 ], [ %9, %8 ]
%14 = add nuw nsw i32 %12, 1
%15 = shl nsw i32 %13, 1
%16 = icmp slt i32 %13, 64
br i1 %16, label %11, label %17
17: ; preds = %11, %8
%18 = phi i32 [ 0, %8 ], [ %14, %11 ]
%19 = add nsw i32 %18, -7
%20 = sitofp i32 %19 to double
%21 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double %20)
br label %22
22: ; preds = %17, %6
%23 = add nsw i32 %4, 1
%24 = icmp eq i32 %23, 128
br i1 %24, label %25, label %3
25: ; preds = %22
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([125 x i8], [125 x i8]* @.str.4, i64 0, i64 0))
br label %27
27: ; preds = %25, %54
%28 = phi double [ 0.000000e+00, %25 ], [ %56, %54 ]
%29 = phi double [ 0.000000e+00, %25 ], [ %55, %54 ]
%30 = phi i32 [ -128, %25 ], [ %57, %54 ]
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
br label %54
34: ; preds = %27
%35 = tail call i32 @llvm.abs.i32(i32 %30, i1 true)
br label %36
36: ; preds = %36, %34
%37 = phi i32 [ %35, %34 ], [ %39, %36 ]
%38 = icmp slt i32 %37, 64
%39 = shl nsw i32 %37, 1
br i1 %38, label %36, label %40
40: ; preds = %36
%41 = sitofp i32 %37 to double
%42 = fdiv double 0x4260000000000000, %41
%43 = tail call double @llvm.ceil.f64(double %42)
%44 = fptoui double %43 to i32
%45 = uitofp i32 %44 to double
%46 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), double %45)
%47 = fsub double %43, %42
%48 = fcmp ogt double %47, %29
%49 = select i1 %48, double %47, double %29
%50 = fmul double %47, %41
%51 = fmul double %50, 7.812500e-03
%52 = fcmp ogt double %51, %28
br i1 %52, label %53, label %54
53: ; preds = %40
br label %54
54: ; preds = %40, %53, %32
%55 = phi double [ %29, %32 ], [ %49, %53 ], [ %49, %40 ]
%56 = phi double [ %28, %32 ], [ %51, %53 ], [ %28, %40 ]
%57 = add nsw i32 %30, 1
%58 = icmp eq i32 %57, 128
br i1 %58, label %59, label %27
59: ; preds = %54
%60 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), double %55, double %56)
%61 = tail call i32 @exit(i32 0)
unreachable
}