#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 int uint8_t;

/* Variables and functions */
int col_from_rgb(int, int, int);
int col_get_blue(int);
int col_get_green(int);
int col_get_red(int);
int col_make_dim(int colour) {
  uint8_t dim_red = col_get_red(colour) * 2 / 3;
  uint8_t dim_green = col_get_green(colour) * 2 / 3;
  uint8_t dim_blue = col_get_blue(colour) * 2 / 3;
  colour = col_from_rgb(dim_red, dim_green, dim_blue);
  return colour;
}


x86 assembly (clang, -O0):
<col_make_dim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <col_get_red@plt>
shl    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <col_get_green@plt>
shl    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <col_get_blue@plt>
shl    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <col_from_rgb@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<col_make_dim>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
call   1030 <col_get_red@plt>
add    %eax,%eax
cltq
imul   $0x55555556,%rax,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
shr    $0x20,%rbx
add    %eax,%ebx
mov    %r14d,%edi
call   1060 <col_get_green@plt>
add    %eax,%eax
cltq
imul   $0x55555556,%rax,%rbp
mov    %rbp,%rax
shr    $0x3f,%rax
shr    $0x20,%rbp
add    %eax,%ebp
mov    %r14d,%edi
call   1050 <col_get_blue@plt>
add    %eax,%eax
cltq
imul   $0x55555556,%rax,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
shr    $0x20,%rdx
add    %eax,%edx
mov    %ebx,%edi
mov    %ebp,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <col_from_rgb@plt>

LLVM IR (-O0):
define i32 @col_make_dim(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = call i32 @col_get_red(i32 %6)
%8 = mul nsw i32 %7, 2
%9 = sdiv i32 %8, 3
store i32 %9, i32* %3
%10 = load i32, i32* %2
%11 = call i32 @col_get_green(i32 %10)
%12 = mul nsw i32 %11, 2
%13 = sdiv i32 %12, 3
store i32 %13, i32* %4
%14 = load i32, i32* %2
%15 = call i32 @col_get_blue(i32 %14)
%16 = mul nsw i32 %15, 2
%17 = sdiv i32 %16, 3
store i32 %17, i32* %5
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = call i32 @col_from_rgb(i32 %18, i32 %19, i32 %20)
store i32 %21, i32* %2
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
define i32 @col_make_dim(i32 %0) {
%2 = tail call i32 @col_get_red(i32 %0)
%3 = shl nsw i32 %2, 1
%4 = sdiv i32 %3, 3
%5 = tail call i32 @col_get_green(i32 %0)
%6 = shl nsw i32 %5, 1
%7 = sdiv i32 %6, 3
%8 = tail call i32 @col_get_blue(i32 %0)
%9 = shl nsw i32 %8, 1
%10 = sdiv i32 %9, 3
%11 = tail call i32 @col_from_rgb(i32 %4, i32 %7, i32 %10)
ret i32 %11
}