#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  unsigned long pixel;
  int /*<<< orphan*/ blue;
  int /*<<< orphan*/ green;
  int /*<<< orphan*/ red;
};
typedef TYPE_1__ XColor;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ DefaultColormap(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ False;
scalar_t__ XAllocColor(int /*<<< orphan*/ *, int /*<<< orphan*/, TYPE_1__ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ uchar2ushort(unsigned char);
unsigned long get_gs_pixel(Display *disp, unsigned char k) {
  XColor color = {
      .red = uchar2ushort(k),
      .green = uchar2ushort(k),
      .blue = uchar2ushort(k),
  };
  if (XAllocColor(disp, DefaultColormap(disp, 0), &color) == False) {
    printf("XAllocColor() failed in get_gs_color()\n");
    exit(1);
  }
  return color.pixel;
}


x86 assembly (clang, -O0):
<get_gs_pixel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movq   $0x0,-0x28(%rbp)
movzbl -0x9(%rbp),%edi
call   1050 <uchar2ushort@plt>
mov    %eax,-0x20(%rbp)
movzbl -0x9(%rbp),%edi
call   1050 <uchar2ushort@plt>
mov    %eax,-0x1c(%rbp)
movzbl -0x9(%rbp),%edi
call   1050 <uchar2ushort@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1060 <DefaultColormap@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
lea    -0x28(%rbp),%rdx
call   1030 <XAllocColor@plt>
mov    0x2e31(%rip),%rcx
cmp    (%rcx),%rax
jne    11d6 <get_gs_pixel+0x86>
lea    0xe39(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_gs_pixel>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
movq   $0x0,(%rsp)
mov    %esi,%edi
call   1050 <uchar2ushort@plt>
mov    %eax,0x8(%rsp)
mov    %ebx,%edi
call   1050 <uchar2ushort@plt>
mov    %eax,0xc(%rsp)
mov    %ebx,%edi
call   1050 <uchar2ushort@plt>
mov    %eax,0x10(%rsp)
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <DefaultColormap@plt>
mov    %rsp,%rdx
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <XAllocColor@plt>
mov    0x2e45(%rip),%rcx
cmp    (%rcx),%rax
je     11b4 <get_gs_pixel+0x64>
mov    (%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe45(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64, i32, i32, i32 }
@False = global i64 0
@.str = [40 x i8] c"XAllocColor() failed in get_gs_color()\0A\00"
define i64 @get_gs_pixel(i32* %0, i8 zeroext %1) {
%3 = alloca i32*
%4 = alloca i8
%5 = alloca %struct.TYPE_3__
store i32* %0, i32** %3
store i8 %1, i8* %4
%6 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i32 0, i32 0
store i64 0, i64* %6
%7 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i32 0, i32 1
%8 = load i8, i8* %4
%9 = call i32 @uchar2ushort(i8 zeroext %8)
store i32 %9, i32* %7
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i32 0, i32 2
%11 = load i8, i8* %4
%12 = call i32 @uchar2ushort(i8 zeroext %11)
store i32 %12, i32* %10
%13 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i32 0, i32 3
%14 = load i8, i8* %4
%15 = call i32 @uchar2ushort(i8 zeroext %14)
store i32 %15, i32* %13
%16 = load i32*, i32** %3
%17 = load i32*, i32** %3
%18 = call i32 @DefaultColormap(i32* %17, i32 0)
%19 = call i64 @XAllocColor(i32* %16, i32 %18, %struct.TYPE_3__* %5)
%20 = load i64, i64* @False
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i32 0, i32 0
%27 = load i64, i64* %26
ret i64 %27
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i32, i32, i32 }
@False = global i64 0
@str = [39 x i8] c"XAllocColor() failed in get_gs_color()\00"
define i64 @get_gs_pixel(i32* %0, i8 zeroext %1) {
%3 = alloca %struct.TYPE_3__
%4 = bitcast %struct.TYPE_3__* %3 to i8*
%5 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 0
store i64 0, i64* %5
%6 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 1
%7 = tail call i32 @uchar2ushort(i8 zeroext %1)
store i32 %7, i32* %6
%8 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 2
%9 = tail call i32 @uchar2ushort(i8 zeroext %1)
store i32 %9, i32* %8
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 3
%11 = tail call i32 @uchar2ushort(i8 zeroext %1)
store i32 %11, i32* %10
%12 = tail call i32 @DefaultColormap(i32* %0, i32 0)
%13 = call i64 @XAllocColor(i32* %0, i32 %12, %struct.TYPE_3__* %3)
%14 = load i64, i64* @False
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i64, i64* %5
ret i64 %20
}