#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 */
float RAND_MAX;
scalar_t__ fabs(int /*<<< orphan*/);
scalar_t__ rand();
int /*<<< orphan*/ round(int);
void fdither_absolute(float *x, int N, int scale) {
  for (int i = 0; i < N; i++) {
    float r = ((float)rand()) / RAND_MAX;
    x[i] += fabs(round(scale * 2 * r - 1));
  }
}


x86 assembly (clang, -O0):
<fdither_absolute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c5 <fdither_absolute+0x95>
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2e80(%rip),%rax
divss  (%rax),%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
cvtsi2ss %eax,%xmm0
movss  -0x18(%rbp),%xmm1
mulss  %xmm1,%xmm0
movss  0xe74(%rip),%xmm1
addss  %xmm1,%xmm0
cvttss2si %xmm0,%edi
call   1040 <round@plt>
mov    %eax,%edi
call   1030 <fabs@plt>
cvtsi2ss %rax,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
addss  (%rax,%rcx,4),%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1149 <fdither_absolute+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fdither_absolute>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    11af <fdither_absolute+0x7f>
mov    %rdi,%r12
add    %edx,%edx
cvtsi2ss %edx,%xmm0
movss  %xmm0,0x4(%rsp)
mov    %esi,%r14d
mov    0x2e93(%rip),%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
divss  (%r15),%xmm0
mulss  0x4(%rsp),%xmm0
addss  0xe7e(%rip),%xmm0
cvttss2si %xmm0,%edi
call   1040 <round@plt>
mov    %eax,%edi
call   1030 <fabs@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  (%r12,%rbx,4),%xmm0
movss  %xmm0,(%r12,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1160 <fdither_absolute+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@RAND_MAX = global float 0.000000e+00
define void @fdither_absolute(float* %0, i32 %1, i32 %2) {
%4 = alloca float*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca float
store float* %0, float** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %33, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %36
13: ; preds = %9
%14 = call i64 (...) @rand()
%15 = sitofp i64 %14 to float
%16 = load float, float* @RAND_MAX
%17 = fdiv float %15, %16
store float %17, float* %8
%18 = load i32, i32* %6
%19 = mul nsw i32 %18, 2
%20 = sitofp i32 %19 to float
%21 = load float, float* %8
%22 = call float @llvm.fmuladd.f32(float %20, float %21, float -1.000000e+00)
%23 = fptosi float %22 to i32
%24 = call i32 @round(i32 %23)
%25 = call i64 @fabs(i32 %24)
%26 = sitofp i64 %25 to float
%27 = load float*, float** %4
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds float, float* %27, i64 %29
%31 = load float, float* %30
%32 = fadd float %31, %26
store float %32, float* %30
br label %33
33: ; preds = %13
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
br label %9
36: ; preds = %9
ret void
}

LLVM IR (-O2):
@RAND_MAX = global float 0.000000e+00
define void @fdither_absolute(float* nocapture %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %9
5: ; preds = %3
%6 = shl nsw i32 %2, 1
%7 = sitofp i32 %6 to float
%8 = zext i32 %1 to i64
br label %10
9: ; preds = %10, %3
ret void
10: ; preds = %5, %10
%11 = phi i64 [ 0, %5 ], [ %24, %10 ]
%12 = tail call i64 (...) @rand()
%13 = sitofp i64 %12 to float
%14 = load float, float* @RAND_MAX
%15 = fdiv float %13, %14
%16 = tail call float @llvm.fmuladd.f32(float %7, float %15, float -1.000000e+00)
%17 = fptosi float %16 to i32
%18 = tail call i32 @round(i32 %17)
%19 = tail call i64 @fabs(i32 %18)
%20 = sitofp i64 %19 to float
%21 = getelementptr inbounds float, float* %0, i64 %11
%22 = load float, float* %21
%23 = fadd float %22, %20
store float %23, float* %21
%24 = add nuw nsw i64 %11, 1
%25 = icmp eq i64 %24, %8
br i1 %25, label %9, label %10
}