#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 */
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
void stbhw__stbhw__set_pixel_whiten(unsigned char *data, int stride, int xpos,
                                    int ypos, unsigned char color[3]) {
  unsigned char c2[3];
  int i;
  for (i = 0; i < 3; ++i)
    c2[i] = (color[i] * 2 + 255) / 3;
  memcpy(data + ypos * stride + xpos * 3, c2, 3);
}


x86 assembly (clang, -O0):
<stbhw__stbhw__set_pixel_whiten>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x3,-0x28(%rbp)
jge    116e <stbhw__stbhw__set_pixel_whiten+0x5e>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
shl    $0x1,%eax
add    $0xff,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %al,%cl
movslq -0x28(%rbp),%rax
mov    %cl,-0x23(%rbp,%rax,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1130 <stbhw__stbhw__set_pixel_whiten+0x20>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%eax
imul   -0xc(%rbp),%eax
cltq
add    %rax,%rdi
imul   $0x3,-0x10(%rbp),%eax
cltq
add    %rax,%rdi
lea    -0x23(%rbp),%rsi
mov    $0x3,%edx
call   1030 <memcpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stbhw__stbhw__set_pixel_whiten>:
push   %rax
movzbl (%r8),%eax
add    %eax,%eax
add    $0xff,%eax
imul   $0xaaab,%eax,%eax
shr    $0x11,%eax
mov    %al,0x5(%rsp)
movzbl 0x1(%r8),%eax
add    %eax,%eax
add    $0xff,%eax
imul   $0xaaab,%eax,%eax
shr    $0x11,%eax
mov    %al,0x6(%rsp)
movzbl 0x2(%r8),%eax
add    %eax,%eax
add    $0xff,%eax
imul   $0xaaab,%eax,%eax
shr    $0x11,%eax
mov    %al,0x7(%rsp)
imul   %ecx,%esi
movslq %esi,%rax
add    %rax,%rdi
lea    (%rdx,%rdx,2),%eax
cltq
add    %rax,%rdi
lea    0x5(%rsp),%rsi
mov    $0x3,%edx
call   1030 <memcpy@plt>
pop    %rax
ret

LLVM IR (-O0):
define void @stbhw__stbhw__set_pixel_whiten(i8* %0, i32 %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [3 x i8]
%12 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8* %4, i8** %10
store i32 0, i32* %12
br label %13
13: ; preds = %30, %5
%14 = load i32, i32* %12
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %33
16: ; preds = %13
%17 = load i8*, i8** %10
%18 = load i32, i32* %12
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = mul nsw i32 %22, 2
%24 = add nsw i32 %23, 255
%25 = sdiv i32 %24, 3
%26 = trunc i32 %25 to i8
%27 = load i32, i32* %12
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 %28
store i8 %26, i8* %29
br label %30
30: ; preds = %16
%31 = load i32, i32* %12
%32 = add nsw i32 %31, 1
store i32 %32, i32* %12
br label %13
33: ; preds = %13
%34 = load i8*, i8** %6
%35 = load i32, i32* %9
%36 = load i32, i32* %7
%37 = mul nsw i32 %35, %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %34, i64 %38
%40 = load i32, i32* %8
%41 = mul nsw i32 %40, 3
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
%44 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%45 = call i32 @memcpy(i8* %43, i8* %44, i32 3)
ret void
}

LLVM IR (-O2):
define void @stbhw__stbhw__set_pixel_whiten(i8* %0, i32 %1, i32 %2, i32 %3, i8* nocapture %4) {
%6 = alloca [3 x i8]
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%8 = load i8, i8* %4
%9 = zext i8 %8 to i16
%10 = shl nuw nsw i16 %9, 1
%11 = add nuw nsw i16 %10, 255
%12 = udiv i16 %11, 3
%13 = trunc i16 %12 to i8
store i8 %13, i8* %7
%14 = getelementptr inbounds i8, i8* %4, i64 1
%15 = load i8, i8* %14
%16 = zext i8 %15 to i16
%17 = shl nuw nsw i16 %16, 1
%18 = add nuw nsw i16 %17, 255
%19 = udiv i16 %18, 3
%20 = trunc i16 %19 to i8
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 1
store i8 %20, i8* %21
%22 = getelementptr inbounds i8, i8* %4, i64 2
%23 = load i8, i8* %22
%24 = zext i8 %23 to i16
%25 = shl nuw nsw i16 %24, 1
%26 = add nuw nsw i16 %25, 255
%27 = udiv i16 %26, 3
%28 = trunc i16 %27 to i8
%29 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 2
store i8 %28, i8* %29
%30 = mul nsw i32 %3, %1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %0, i64 %31
%33 = mul nsw i32 %2, 3
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = call i32 @memcpy(i8* %35, i8* %7, i32 3)
ret void
}