#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 RAND_MAX;
double rand();
int /*<<< orphan*/ srand(int);
void saltPepperNoise(int *image, int *width, int *height, int *depth,
                     double *percent) {
  int i = 0, plane_size = *width * *height * *depth;
  double pr = 1.0 - *percent / 100.0;
  srand(1);
  for (i = 0; i < plane_size; i++) {
    double random = 2.0 * (rand() - RAND_MAX / 2.0) / RAND_MAX;
    if (random > pr) {
      image[i] = 255;
    } else if (random < -pr) {
      image[i] = 0;
    }
  }
}


x86 assembly (clang, -O0):
<saltPepperNoise>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%rcx
imul   (%rcx),%eax
mov    -0x20(%rbp),%rcx
imul   (%rcx),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm1
movsd  0xe9e(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe8a(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    $0x1,%edi
call   1030 <srand@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    1253 <saltPepperNoise+0x133>
mov    $0x0,%al
call   1040 <rand@plt>
movaps %xmm0,%xmm1
mov    0x2e3b(%rip),%rax
movsd  (%rax),%xmm0
movsd  0xe57(%rip),%xmm2
divsd  %xmm2,%xmm0
subsd  %xmm0,%xmm1
movsd  0xe47(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2e14(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    1201 <saltPepperNoise+0xe1>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movl   $0xff,(%rax,%rcx,4)
jmp    1240 <saltPepperNoise+0x120>
movsd  -0x40(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
ucomisd %xmm1,%xmm0
jbe    123b <saltPepperNoise+0x11b>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    1240 <saltPepperNoise+0x120>
jmp    1245 <saltPepperNoise+0x125>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1190 <saltPepperNoise+0x70>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<saltPepperNoise>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    (%rdx),%ebx
imul   (%rsi),%ebx
mov    %rdi,%r14
imul   (%rcx),%ebx
movsd  (%r8),%xmm0
movapd %xmm0,(%rsp)
mov    $0x1,%edi
call   1030 <srand@plt>
test   %ebx,%ebx
jle    11dd <saltPepperNoise+0xbd>
movapd (%rsp),%xmm0
divsd  0xea1(%rip),%xmm0
addsd  0xea1(%rip),%xmm0
movapd 0xeb1(%rip),%xmm1
movapd %xmm0,(%rsp)
xorpd  %xmm0,%xmm1
movapd %xmm1,0x10(%rsp)
mov    %ebx,%r12d
mov    0x2e60(%rip),%r15
xor    %ebx,%ebx
jmp    119d <saltPepperNoise+0x7d>
nopl   0x0(%rax)
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r12
je     11dd <saltPepperNoise+0xbd>
xor    %eax,%eax
call   1040 <rand@plt>
movsd  (%r15),%xmm2
movapd %xmm2,%xmm1
mulsd  0xe5b(%rip),%xmm1
addsd  %xmm0,%xmm1
addsd  %xmm1,%xmm1
divsd  %xmm2,%xmm1
mov    $0xff,%eax
ucomisd (%rsp),%xmm1
ja     1190 <saltPepperNoise+0x70>
xor    %eax,%eax
movapd 0x10(%rsp),%xmm0
ucomisd %xmm1,%xmm0
ja     1190 <saltPepperNoise+0x70>
jmp    1194 <saltPepperNoise+0x74>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
define void @saltPepperNoise(i32* %0, i32* %1, i32* %2, i32* %3, double* %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca double*
%11 = alloca i32
%12 = alloca i32
%13 = alloca double
%14 = alloca double
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store double* %4, double** %10
store i32 0, i32* %11
%15 = load i32*, i32** %7
%16 = load i32, i32* %15
%17 = load i32*, i32** %8
%18 = load i32, i32* %17
%19 = mul nsw i32 %16, %18
%20 = load i32*, i32** %9
%21 = load i32, i32* %20
%22 = mul nsw i32 %19, %21
store i32 %22, i32* %12
%23 = load double*, double** %10
%24 = load double, double* %23
%25 = fdiv double %24, 1.000000e+02
%26 = fsub double 1.000000e+00, %25
store double %26, double* %13
%27 = call i32 @srand(i32 1)
store i32 0, i32* %11
br label %28
28: ; preds = %60, %5
%29 = load i32, i32* %11
%30 = load i32, i32* %12
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %63
32: ; preds = %28
%33 = call double (...) @rand()
%34 = load double, double* @RAND_MAX
%35 = fdiv double %34, 2.000000e+00
%36 = fsub double %33, %35
%37 = fmul double 2.000000e+00, %36
%38 = load double, double* @RAND_MAX
%39 = fdiv double %37, %38
store double %39, double* %14
%40 = load double, double* %14
%41 = load double, double* %13
%42 = fcmp ogt double %40, %41
br i1 %42, label %43, label %48
43: ; preds = %32
%44 = load i32*, i32** %6
%45 = load i32, i32* %11
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
store i32 255, i32* %47
br label %59
48: ; preds = %32
%49 = load double, double* %14
%50 = load double, double* %13
%51 = fneg double %50
%52 = fcmp olt double %49, %51
br i1 %52, label %53, label %58
53: ; preds = %48
%54 = load i32*, i32** %6
%55 = load i32, i32* %11
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %54, i64 %56
store i32 0, i32* %57
br label %58
58: ; preds = %53, %48
br label %59
59: ; preds = %58, %43
br label %60
60: ; preds = %59
%61 = load i32, i32* %11
%62 = add nsw i32 %61, 1
store i32 %62, i32* %11
br label %28
63: ; preds = %28
ret void
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define void @saltPepperNoise(i32* nocapture writeonly %0, i32* nocapture %1, i32* nocapture %2, i32* nocapture %3, double* nocapture %4) {
%6 = load i32, i32* %1
%7 = load i32, i32* %2
%8 = mul nsw i32 %7, %6
%9 = load i32, i32* %3
%10 = mul i32 %8, %9
%11 = load double, double* %4
%12 = fdiv double %11, 1.000000e+02
%13 = fsub double 1.000000e+00, %12
%14 = tail call i32 @srand(i32 1)
%15 = icmp sgt i32 %10, 0
br i1 %15, label %16, label %36
16: ; preds = %5
%17 = fneg double %13
%18 = zext i32 %10 to i64
br label %19
19: ; preds = %16, %33
%20 = phi i64 [ 0, %16 ], [ %34, %33 ]
%21 = tail call double (...) @rand()
%22 = load double, double* @RAND_MAX
%23 = fmul double %22, 5.000000e-01
%24 = fsub double %21, %23
%25 = fmul double %24, 2.000000e+00
%26 = fdiv double %25, %22
%27 = fcmp ogt double %26, %13
br i1 %27, label %30, label %28
28: ; preds = %19
%29 = fcmp olt double %26, %17
br i1 %29, label %30, label %33
30: ; preds = %28, %19
%31 = phi i32 [ 255, %19 ], [ 0, %28 ]
%32 = getelementptr inbounds i32, i32* %0, i64 %20
store i32 %31, i32* %32
br label %33
33: ; preds = %30, %28
%34 = add nuw nsw i64 %20, 1
%35 = icmp eq i64 %34, %18
br i1 %35, label %36, label %19
36: ; preds = %33, %5
ret void
}