#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");
  puts("LOCAL(div_table_clz):");
  printf("\t.byte\t%d\n", 0);
  for (i = 1; i <= 128; i++) {
    int n = 0;
    if (i == 128)
      puts("/* Lookup table translating positive divisor to index into table "
           "of\n   normalized inverse.  N.B. the '0' entry is also the last "
           "entry of the\n previous table, and causes an unaligned access for "
           "division by zero.  */\nLOCAL(div_table_ix):");
    for (j = i; j <= 128; j += j)
      n++;
    printf("\t.byte\t%d\n", n - 7);
  }
  for (i = 1; i <= 128; i++) {
    j = i < 0 ? -i : i;
    while (j < 128)
      j += j;
    printf("\t.byte\t%d\n", j * 2 - 96 * 4);
  }
  puts("/* 1/64 .. 1/127, normalized.  There is an implicit leading 1 in bit "
       "32.  */\n	.balign 4\nLOCAL(zero_l):");
  for (i = 64; i < 128; i++) {
    if (i == 96)
      puts("LOCAL(div_table):");
    q = 4. * (1 << 30) * 128 / i;
    r = ceil(q);
    printf("\t.long\t0x%X\n", (unsigned)r);
    err = r - q;
    if (err > max_err)
      max_err = err;
    err = err * i / 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    $0x40,%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    0xed4(%rip),%rdi
call   1030 <puts@plt>
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
lea    0xedd(%rip),%rdi
xorps  %xmm0,%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x80,-0x8(%rbp)
jg     1218 <main+0xd8>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x80,-0x8(%rbp)
jne    11c8 <main+0x88>
lea    0xeaf(%rip),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x80,-0xc(%rbp)
jg     11f2 <main+0xb2>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0xc(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11ce <main+0x8e>
mov    -0x3c(%rbp),%eax
sub    $0x7,%eax
cvtsi2sd %eax,%xmm0
lea    0xe64(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    119b <main+0x5b>
movl   $0x1,-0x8(%rbp)
cmpl   $0x80,-0x8(%rbp)
jg     1295 <main+0x155>
cmpl   $0x0,-0x8(%rbp)
jge    1243 <main+0x103>
xor    %eax,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x40(%rbp)
jmp    1249 <main+0x109>
mov    -0x8(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x80,-0xc(%rbp)
jge    126a <main+0x12a>
mov    -0xc(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    124f <main+0x10f>
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
sub    $0x180,%eax
cvtsi2sd %eax,%xmm0
lea    0xde7(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    121f <main+0xdf>
lea    0xec2(%rip),%rdi
call   1030 <puts@plt>
movl   $0x40,-0x8(%rbp)
cmpl   $0x80,-0x8(%rbp)
jge    1380 <main+0x240>
cmpl   $0x60,-0x8(%rbp)
jne    12cb <main+0x18b>
lea    0xeff(%rip),%rdi
call   1030 <puts@plt>
cvtsi2sdl -0x8(%rbp),%xmm1
movsd  0xd28(%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    0xed3(%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    1334 <main+0x1f4>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xcbe(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    136d <main+0x22d>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1372 <main+0x232>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12a8 <main+0x168>
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
lea    0xe53(%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    0xed1(%rip),%rdi
call   1030 <puts@plt>
lea    0xefb(%rip),%rdi
call   1030 <puts@plt>
lea    0xefa(%rip),%rdi
call   1030 <puts@plt>
lea    0xf04(%rip),%rbx
xorpd  %xmm0,%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0x1,%ebp
lea    0xef5(%rip),%r14
nopl   (%rax)
cmp    $0x80,%ebp
jne    11a0 <main+0x60>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    $0xfffffff9,%eax
mov    %ebp,%ecx
nopw   0x0(%rax,%rax,1)
lea    (%rcx,%rcx,1),%edx
add    $0x1,%eax
cmp    $0x41,%ecx
mov    %edx,%ecx
jl     11b0 <main+0x70>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
add    $0x1,%ebp
cmp    $0x81,%ebp
jne    1190 <main+0x50>
mov    $0x1,%ebp
lea    0xe92(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%ecx
lea    (%rcx,%rcx,1),%eax
cmp    $0x80,%ecx
jl     1200 <main+0xc0>
add    $0xfffffe80,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
add    $0x1,%ebp
cmp    $0x81,%ebp
jne    11f0 <main+0xb0>
lea    0xf39(%rip),%rdi
call   1030 <puts@plt>
movsd  0xdbe(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm3,%xmm3
mov    $0x40,%ebp
lea    0xf7d(%rip),%r14
lea    0xf88(%rip),%rbx
xorpd  %xmm2,%xmm2
jmp    12f1 <main+0x1b1>
nopl   0x0(%rax,%rax,1)
movsd  0xd90(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
call   1040 <ceil@plt>
movsd  %xmm0,0x10(%rsp)
cvttsd2si %xmm0,%rax
mov    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x10(%rsp),%xmm1
subsd  0x18(%rsp),%xmm1
movapd %xmm1,%xmm0
maxsd  0x20(%rsp),%xmm0
movsd  0x8(%rsp),%xmm2
mulsd  %xmm2,%xmm1
mulsd  0xd40(%rip),%xmm1
maxsd  0x28(%rsp),%xmm1
addsd  0xd3a(%rip),%xmm2
movsd  %xmm2,0x8(%rsp)
movapd %xmm1,%xmm3
movapd %xmm0,%xmm2
add    $0xffffffff,%ebp
je     1313 <main+0x1d3>
movsd  %xmm2,0x20(%rsp)
movsd  %xmm3,0x28(%rsp)
cmp    $0x20,%ebp
jne    1270 <main+0x130>
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    1270 <main+0x130>
lea    0xeda(%rip),%rdi
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 = [22 x i8] c"LOCAL(div_table_clz):\00"
@.str.3 = [11 x i8] c"\09.byte\09%d\0A\00"
@.str.4 = [236 x i8] c"/* Lookup table translating positive divisor to index into table of\0A normalized inverse. N.B. the '0' entry is also the last entry of the\0A previous table, and causes an unaligned access for division by zero. */\0ALOCAL(div_table_ix):\00"
@.str.5 = [103 x i8] c"/* 1/64 .. 1/127, normalized. There is an implicit leading 1 in bit 32. */\0A\09.balign 4\0ALOCAL(zero_l):\00"
@.str.6 = [18 x i8] c"LOCAL(div_table):\00"
@.str.7 = [13 x i8] c"\09.long\090x%X\0A\00"
@.str.8 = [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))
%12 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double 0.000000e+00)
store i32 1, i32* %2
br label %14
14: ; preds = %39, %0
%15 = load i32, i32* %2
%16 = icmp sle i32 %15, 128
br i1 %16, label %17, label %42
17: ; preds = %14
store i32 0, i32* %9
%18 = load i32, i32* %2
%19 = icmp eq i32 %18, 128
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @puts(i8* getelementptr inbounds ([236 x i8], [236 x i8]* @.str.4, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = load i32, i32* %2
store i32 %23, i32* %3
br label %24
24: ; preds = %30, %22
%25 = load i32, i32* %3
%26 = icmp sle i32 %25, 128
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = load i32, i32* %9
%29 = add nsw i32 %28, 1
store i32 %29, i32* %9
br label %30
30: ; preds = %27
%31 = load i32, i32* %3
%32 = load i32, i32* %3
%33 = add nsw i32 %32, %31
store i32 %33, i32* %3
br label %24
34: ; preds = %24
%35 = load i32, i32* %9
%36 = sub nsw i32 %35, 7
%37 = sitofp i32 %36 to double
%38 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double %37)
br label %39
39: ; preds = %34
%40 = load i32, i32* %2
%41 = add nsw i32 %40, 1
store i32 %41, i32* %2
br label %14
42: ; preds = %14
store i32 1, i32* %2
br label %43
43: ; preds = %69, %42
%44 = load i32, i32* %2
%45 = icmp sle i32 %44, 128
br i1 %45, label %46, label %72
46: ; preds = %43
%47 = load i32, i32* %2
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load i32, i32* %2
%51 = sub nsw i32 0, %50
br label %54
52: ; preds = %46
%53 = load i32, i32* %2
br label %54
54: ; preds = %52, %49
%55 = phi i32 [ %51, %49 ], [ %53, %52 ]
store i32 %55, i32* %3
br label %56
56: ; preds = %59, %54
%57 = load i32, i32* %3
%58 = icmp slt i32 %57, 128
br i1 %58, label %59, label %63
59: ; preds = %56
%60 = load i32, i32* %3
%61 = load i32, i32* %3
%62 = add nsw i32 %61, %60
store i32 %62, i32* %3
br label %56
63: ; preds = %56
%64 = load i32, i32* %3
%65 = mul nsw i32 %64, 2
%66 = sub nsw i32 %65, 384
%67 = sitofp i32 %66 to double
%68 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double %67)
br label %69
69: ; preds = %63
%70 = load i32, i32* %2
%71 = add nsw i32 %70, 1
store i32 %71, i32* %2
br label %43
72: ; preds = %43
%73 = call i32 @puts(i8* getelementptr inbounds ([103 x i8], [103 x i8]* @.str.5, i64 0, i64 0))
store i32 64, i32* %2
br label %74
74: ; preds = %112, %72
%75 = load i32, i32* %2
%76 = icmp slt i32 %75, 128
br i1 %76, label %77, label %115
77: ; preds = %74
%78 = load i32, i32* %2
%79 = icmp eq i32 %78, 96
br i1 %79, label %80, label %82
80: ; preds = %77
%81 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %82
82: ; preds = %80, %77
%83 = load i32, i32* %2
%84 = sitofp i32 %83 to double
%85 = fdiv double 0x4260000000000000, %84
store double %85, double* %4
%86 = load double, double* %4
%87 = call double @llvm.ceil.f64(double %86)
store double %87, double* %5
%88 = load double, double* %5
%89 = fptoui double %88 to i32
%90 = uitofp i32 %89 to double
%91 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), double %90)
%92 = load double, double* %5
%93 = load double, double* %4
%94 = fsub double %92, %93
store double %94, double* %6
%95 = load double, double* %6
%96 = load double, double* %7
%97 = fcmp ogt double %95, %96
br i1 %97, label %98, label %100
98: ; preds = %82
%99 = load double, double* %6
store double %99, double* %7
br label %100
100: ; preds = %98, %82
%101 = load double, double* %6
%102 = load i32, i32* %2
%103 = sitofp i32 %102 to double
%104 = fmul double %101, %103
%105 = fdiv double %104, 1.280000e+02
store double %105, double* %6
%106 = load double, double* %6
%107 = load double, double* %8
%108 = fcmp ogt double %106, %107
br i1 %108, label %109, label %111
109: ; preds = %100
%110 = load double, double* %6
store double %110, double* %8
br label %111
111: ; preds = %109, %100
br label %112
112: ; preds = %111
%113 = load i32, i32* %2
%114 = add nsw i32 %113, 1
store i32 %114, i32* %2
br label %74
115: ; preds = %74
%116 = load double, double* %7
%117 = load double, double* %8
%118 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0), double %116, double %117)
%119 = 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 = [22 x i8] c"LOCAL(div_table_clz):\00"
@.str.3 = [11 x i8] c"\09.byte\09%d\0A\00"
@.str.4 = [236 x i8] c"/* Lookup table translating positive divisor to index into table of\0A normalized inverse. N.B. the '0' entry is also the last entry of the\0A previous table, and causes an unaligned access for division by zero. */\0ALOCAL(div_table_ix):\00"
@.str.5 = [103 x i8] c"/* 1/64 .. 1/127, normalized. There is an implicit leading 1 in bit 32. */\0A\09.balign 4\0ALOCAL(zero_l):\00"
@.str.6 = [18 x i8] c"LOCAL(div_table):\00"
@.str.7 = [13 x i8] c"\09.long\090x%X\0A\00"
@.str.8 = [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))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%4 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double 0.000000e+00)
br label %5
5: ; preds = %0, %17
%6 = phi i32 [ 1, %0 ], [ %21, %17 ]
%7 = icmp eq i32 %6, 128
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([236 x i8], [236 x i8]* @.str.4, i64 0, i64 0))
br label %10
10: ; preds = %5, %8
br label %11
11: ; preds = %10, %11
%12 = phi i32 [ %14, %11 ], [ 0, %10 ]
%13 = phi i32 [ %15, %11 ], [ %6, %10 ]
%14 = add nuw nsw i32 %12, 1
%15 = shl nsw i32 %13, 1
%16 = icmp slt i32 %13, 65
br i1 %16, label %11, label %17
17: ; preds = %11
%18 = add nsw i32 %12, -6
%19 = sitofp i32 %18 to double
%20 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double %19)
%21 = add nuw nsw i32 %6, 1
%22 = icmp eq i32 %21, 129
br i1 %22, label %23, label %5
23: ; preds = %17, %29
%24 = phi i32 [ %33, %29 ], [ 1, %17 ]
br label %25
25: ; preds = %25, %23
%26 = phi i32 [ %28, %25 ], [ %24, %23 ]
%27 = icmp slt i32 %26, 128
%28 = shl nsw i32 %26, 1
br i1 %27, label %25, label %29
29: ; preds = %25
%30 = add nsw i32 %28, -384
%31 = sitofp i32 %30 to double
%32 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double %31)
%33 = add nuw nsw i32 %24, 1
%34 = icmp eq i32 %33, 129
br i1 %34, label %35, label %23
35: ; preds = %29
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([103 x i8], [103 x i8]* @.str.5, i64 0, i64 0))
br label %37
37: ; preds = %35, %44
%38 = phi double [ 0.000000e+00, %35 ], [ %57, %44 ]
%39 = phi double [ 0.000000e+00, %35 ], [ %53, %44 ]
%40 = phi i32 [ 64, %35 ], [ %58, %44 ]
%41 = icmp eq i32 %40, 96
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %44
44: ; preds = %42, %37
%45 = sitofp i32 %40 to double
%46 = fdiv double 0x4260000000000000, %45
%47 = tail call double @llvm.ceil.f64(double %46)
%48 = fptoui double %47 to i32
%49 = uitofp i32 %48 to double
%50 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), double %49)
%51 = fsub double %47, %46
%52 = fcmp ogt double %51, %39
%53 = select i1 %52, double %51, double %39
%54 = fmul double %51, %45
%55 = fmul double %54, 7.812500e-03
%56 = fcmp ogt double %55, %38
%57 = select i1 %56, double %55, double %38
%58 = add nuw nsw i32 %40, 1
%59 = icmp eq i32 %58, 128
br i1 %59, label %60, label %37
60: ; preds = %44
%61 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0), double %53, double %57)
%62 = tail call i32 @exit(i32 0)
unreachable
}