#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 double uint8_t;
typedef int uint32_t;
typedef double int32_t;

/* Variables and functions */
double C(int);
int acos(int);
double cos(int);
int /*<<< orphan*/ printf(char *, ...);
void idct_block(int32_t in[64], uint8_t out[64]) {
  for (uint32_t i = 0; i < 8; i++) {
    for (uint32_t j = 0; j < 8; j++) {
      double sum = 0;
      for (uint32_t k = 0; k < 8; k++) {
        for (uint32_t l = 0; l < 8; l++) {
          sum += C(k) * C(l) * (cos(((2. * i + 1.) * k * acos(-1) / 16))) *
                 (cos(((2. * j + 1.) * l * acos(-1) / 16))) * in[8 * k + l];
        }
      }
      printf("%f ", sum);
      sum *= 0.25;
      printf("%f ", sum);
      sum += 128.;
      printf("%f ", sum);
      if (sum < 0)
        sum = 0;
      if (sum > 255)
        sum = 255;
      out[8 * i + j] = sum;
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<idct_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    1397 <idct_block+0x257>
movl   $0x0,-0x18(%rbp)
cmpl   $0x8,-0x18(%rbp)
jge    1384 <idct_block+0x244>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x8,-0x24(%rbp)
jge    12c5 <idct_block+0x185>
movl   $0x0,-0x28(%rbp)
cmpl   $0x8,-0x28(%rbp)
jge    12b2 <idct_block+0x172>
mov    -0x24(%rbp),%edi
call   1050 <C@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x28(%rbp),%edi
call   1050 <C@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe4d(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    $0xffffffff,%edi
call   1040 <acos@plt>
movsd  -0x48(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe14(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1060 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xded(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsi2sdl -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    $0xffffffff,%edi
call   1040 <acos@plt>
movsd  -0x38(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdb4(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1060 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
shl    $0x3,%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1192 <idct_block+0x52>
jmp    12b7 <idct_block+0x177>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1181 <idct_block+0x41>
movsd  -0x20(%rbp),%xmm0
lea    0xd57(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0xd28(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xd32(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0xcfb(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xd0d(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1338 <idct_block+0x1f8>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xccb(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    135c <idct_block+0x21c>
movsd  0xcb9(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x3,%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1168 <idct_block+0x28>
jmp    1389 <idct_block+0x249>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1157 <idct_block+0x17>
lea    0xc8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<idct_block>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,0x20(%rsp)
mov    %rdi,0x18(%rsp)
xor    %eax,%eax
lea    0xeb7(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  %xmm0,%xmm0
addsd  0xe6d(%rip),%xmm0
movsd  %xmm0,0x28(%rsp)
mov    %rax,0x10(%rsp)
lea    0x0(,%rax,8),%rbp
xor    %r14d,%r14d
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
addsd  %xmm0,%xmm0
addsd  0xe3c(%rip),%xmm0
movsd  %xmm0,0x30(%rsp)
xorps  %xmm1,%xmm1
mov    0x18(%rsp),%r15
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nop
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
mulsd  0x28(%rsp),%xmm0
movsd  %xmm0,0x38(%rsp)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movsd  %xmm1,(%rsp)
mov    %r13d,%edi
call   1060 <C@plt>
movsd  %xmm0,0x8(%rsp)
mov    %ebx,%edi
call   1060 <C@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0xffffffff,%edi
call   1050 <acos@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x38(%rsp),%xmm0
movsd  0xdc3(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1070 <cos@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  0x30(%rsp),%xmm0
movsd  %xmm0,0x40(%rsp)
mov    $0xffffffff,%edi
call   1050 <acos@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x40(%rsp),%xmm0
mulsd  0xd78(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1070 <cos@plt>
movsd  (%rsp),%xmm1
mulsd  0x8(%rsp),%xmm0
mulsd  (%r15,%rbx,8),%xmm0
addsd  %xmm0,%xmm1
add    $0x1,%rbx
cmp    $0x8,%rbx
jne    1200 <idct_block+0xb0>
add    $0x1,%r13
add    $0x40,%r15
cmp    $0x8,%r13
jne    11e0 <idct_block+0x90>
mov    %r12,%rdi
movapd %xmm1,%xmm0
mov    $0x1,%al
movsd  %xmm1,(%rsp)
call   1040 <printf@plt>
movsd  (%rsp),%xmm0
mulsd  0xd22(%rip),%xmm0
movsd  %xmm0,(%rsp)
mov    %r12,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  (%rsp),%xmm0
addsd  0xd0e(%rip),%xmm0
movsd  %xmm0,(%rsp)
mov    %r12,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xorpd  %xmm0,%xmm0
maxsd  (%rsp),%xmm0
movsd  0xcf6(%rip),%xmm1
minsd  %xmm0,%xmm1
lea    (%r14,%rbp,1),%rax
mov    0x20(%rsp),%rcx
movsd  %xmm1,(%rcx,%rax,8)
add    $0x1,%r14
cmp    $0x8,%r14
jne    11b0 <idct_block+0x60>
mov    0x10(%rsp),%rax
add    $0x1,%rax
cmp    $0x8,%rax
jne    1180 <idct_block+0x30>
mov    $0xa,%edi
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%f \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @idct_block(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
store double* %0, double** %3
store double* %1, double** %4
store i32 0, i32* %5
br label %10
10: ; preds = %105, %2
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 8
br i1 %12, label %13, label %108
13: ; preds = %10
store i32 0, i32* %6
br label %14
14: ; preds = %101, %13
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 8
br i1 %16, label %17, label %104
17: ; preds = %14
store double 0.000000e+00, double* %7
store i32 0, i32* %8
br label %18
18: ; preds = %71, %17
%19 = load i32, i32* %8
%20 = icmp slt i32 %19, 8
br i1 %20, label %21, label %74
21: ; preds = %18
store i32 0, i32* %9
br label %22
22: ; preds = %67, %21
%23 = load i32, i32* %9
%24 = icmp slt i32 %23, 8
br i1 %24, label %25, label %70
25: ; preds = %22
%26 = load i32, i32* %8
%27 = call double @C(i32 %26)
%28 = load i32, i32* %9
%29 = call double @C(i32 %28)
%30 = fmul double %27, %29
%31 = load i32, i32* %5
%32 = sitofp i32 %31 to double
%33 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %32, double 1.000000e+00)
%34 = load i32, i32* %8
%35 = sitofp i32 %34 to double
%36 = fmul double %33, %35
%37 = call i32 @acos(i32 -1)
%38 = sitofp i32 %37 to double
%39 = fmul double %36, %38
%40 = fdiv double %39, 1.600000e+01
%41 = fptosi double %40 to i32
%42 = call double @cos(i32 %41)
%43 = fmul double %30, %42
%44 = load i32, i32* %6
%45 = sitofp i32 %44 to double
%46 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %45, double 1.000000e+00)
%47 = load i32, i32* %9
%48 = sitofp i32 %47 to double
%49 = fmul double %46, %48
%50 = call i32 @acos(i32 -1)
%51 = sitofp i32 %50 to double
%52 = fmul double %49, %51
%53 = fdiv double %52, 1.600000e+01
%54 = fptosi double %53 to i32
%55 = call double @cos(i32 %54)
%56 = fmul double %43, %55
%57 = load double*, double** %3
%58 = load i32, i32* %8
%59 = mul nsw i32 8, %58
%60 = load i32, i32* %9
%61 = add nsw i32 %59, %60
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %57, i64 %62
%64 = load double, double* %63
%65 = load double, double* %7
%66 = call double @llvm.fmuladd.f64(double %56, double %64, double %65)
store double %66, double* %7
br label %67
67: ; preds = %25
%68 = load i32, i32* %9
%69 = add nsw i32 %68, 1
store i32 %69, i32* %9
br label %22
70: ; preds = %22
br label %71
71: ; preds = %70
%72 = load i32, i32* %8
%73 = add nsw i32 %72, 1
store i32 %73, i32* %8
br label %18
74: ; preds = %18
%75 = load double, double* %7
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %75)
%77 = load double, double* %7
%78 = fmul double %77, 2.500000e-01
store double %78, double* %7
%79 = load double, double* %7
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %79)
%81 = load double, double* %7
%82 = fadd double %81, 1.280000e+02
store double %82, double* %7
%83 = load double, double* %7
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %83)
%85 = load double, double* %7
%86 = fcmp olt double %85, 0.000000e+00
br i1 %86, label %87, label %88
87: ; preds = %74
store double 0.000000e+00, double* %7
br label %88
88: ; preds = %87, %74
%89 = load double, double* %7
%90 = fcmp ogt double %89, 2.550000e+02
br i1 %90, label %91, label %92
91: ; preds = %88
store double 2.550000e+02, double* %7
br label %92
92: ; preds = %91, %88
%93 = load double, double* %7
%94 = load double*, double** %4
%95 = load i32, i32* %5
%96 = mul nsw i32 8, %95
%97 = load i32, i32* %6
%98 = add nsw i32 %96, %97
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds double, double* %94, i64 %99
store double %93, double* %100
br label %101
101: ; preds = %92
%102 = load i32, i32* %6
%103 = add nsw i32 %102, 1
store i32 %103, i32* %6
br label %14
104: ; preds = %14
br label %105
105: ; preds = %104
%106 = load i32, i32* %5
%107 = add nsw i32 %106, 1
store i32 %107, i32* %5
br label %10
108: ; preds = %10
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%f \00"
define void @idct_block(double* nocapture %0, double* nocapture writeonly %1) {
br label %3
3: ; preds = %2, %16
%4 = phi i64 [ 0, %2 ], [ %17, %16 ]
%5 = trunc i64 %4 to i32
%6 = sitofp i32 %5 to double
%7 = tail call double @llvm.fmuladd.f64(double %6, double 2.000000e+00, double 1.000000e+00)
%8 = shl nsw i64 %4, 3
br label %11
9: ; preds = %16
%10 = tail call i32 @putchar(i32 10)
ret void
11: ; preds = %3, %26
%12 = phi i64 [ 0, %3 ], [ %38, %26 ]
%13 = trunc i64 %12 to i32
%14 = sitofp i32 %13 to double
%15 = tail call double @llvm.fmuladd.f64(double %14, double 2.000000e+00, double 1.000000e+00)
br label %19
16: ; preds = %26
%17 = add nuw nsw i64 %4, 1
%18 = icmp eq i64 %17, 8
br i1 %18, label %9, label %3
19: ; preds = %11, %40
%20 = phi i64 [ 0, %11 ], [ %41, %40 ]
%21 = phi double [ 0.000000e+00, %11 ], [ %69, %40 ]
%22 = trunc i64 %20 to i32
%23 = sitofp i32 %22 to double
%24 = fmul double %7, %23
%25 = shl nsw i64 %20, 3
br label %43
26: ; preds = %40
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %69)
%28 = fmul double %69, 2.500000e-01
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %28)
%30 = fadd double %28, 1.280000e+02
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %30)
%32 = fcmp olt double %30, 0.000000e+00
%33 = select i1 %32, double 0.000000e+00, double %30
%34 = fcmp ogt double %33, 2.550000e+02
%35 = select i1 %34, double 2.550000e+02, double %33
%36 = add nuw nsw i64 %12, %8
%37 = getelementptr inbounds double, double* %1, i64 %36
store double %35, double* %37
%38 = add nuw nsw i64 %12, 1
%39 = icmp eq i64 %38, 8
br i1 %39, label %16, label %11
40: ; preds = %43
%41 = add nuw nsw i64 %20, 1
%42 = icmp eq i64 %41, 8
br i1 %42, label %26, label %19
43: ; preds = %19, %43
%44 = phi i64 [ 0, %19 ], [ %70, %43 ]
%45 = phi double [ %21, %19 ], [ %69, %43 ]
%46 = tail call double @C(i32 %22)
%47 = trunc i64 %44 to i32
%48 = tail call double @C(i32 %47)
%49 = fmul double %46, %48
%50 = tail call i32 @acos(i32 -1)
%51 = sitofp i32 %50 to double
%52 = fmul double %24, %51
%53 = fmul double %52, 6.250000e-02
%54 = fptosi double %53 to i32
%55 = tail call double @cos(i32 %54)
%56 = fmul double %49, %55
%57 = sitofp i32 %47 to double
%58 = fmul double %15, %57
%59 = tail call i32 @acos(i32 -1)
%60 = sitofp i32 %59 to double
%61 = fmul double %58, %60
%62 = fmul double %61, 6.250000e-02
%63 = fptosi double %62 to i32
%64 = tail call double @cos(i32 %63)
%65 = fmul double %56, %64
%66 = add nuw nsw i64 %44, %25
%67 = getelementptr inbounds double, double* %0, i64 %66
%68 = load double, double* %67
%69 = tail call double @llvm.fmuladd.f64(double %65, double %68, double %45)
%70 = add nuw nsw i64 %44, 1
%71 = icmp eq i64 %70, 8
br i1 %71, label %40, label %43
}