#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 */
struct Sample {
  int dummy;
};
typedef int /*<<< orphan*/ XImage;
typedef int /*<<< orphan*/ Window;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ XAllPlanes();
int /*<<< orphan*/ XFree(int /*<<< orphan*/ *);
int /*<<< orphan*/ *XGetImage(int /*<<< orphan*/ *, int /*<<< orphan*/, int,
                              int, int, int, int /*<<< orphan*/,
                              int /*<<< orphan*/);
int /*<<< orphan*/ ZPixmap;
int /*<<< orphan*/ img_to_sample(int /*<<< orphan*/ *, struct Sample *);
int /*<<< orphan*/ init_sample(struct Sample *, int, int);
int get_sample(Display *display, Window root_win, int x, int y,
               unsigned long int size, struct Sample *sample) {
  if (sample == NULL)
    return 1;
  XImage *img = XGetImage(display, root_win, x, y, 1, 1, XAllPlanes(), ZPixmap);
  if (img == NULL)
    return 1;
  init_sample(sample, 1, 32);
  img_to_sample(img, sample);
  XFree(img);
  return 0;
}


x86 assembly (clang, -O0):
<get_sample>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1184 <get_sample+0x34>
movl   $0x1,-0x4(%rbp)
jmp    121f <get_sample+0xcf>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    $0x0,%al
call   1040 <XAllPlanes@plt>
mov    -0x50(%rbp),%rdi
mov    -0x44(%rbp),%esi
mov    -0x40(%rbp),%edx
mov    -0x3c(%rbp),%ecx
mov    %eax,%r10d
mov    0x2e2c(%rip),%rax
mov    (%rax),%eax
mov    $0x1,%r9d
mov    %r9d,%r8d
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1070 <XGetImage@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11ef <get_sample+0x9f>
movl   $0x1,-0x4(%rbp)
jmp    121f <get_sample+0xcf>
mov    -0x30(%rbp),%rdi
mov    $0x1,%esi
mov    $0x20,%edx
call   1060 <init_sample@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <img_to_sample@plt>
mov    -0x38(%rbp),%rdi
call   1030 <XFree@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sample>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %r9,%r9
je     11da <get_sample+0x8a>
mov    %r9,%r14
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %esi,%r13d
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <XAllPlanes@plt>
mov    0x2e6b(%rip),%rcx
mov    (%rcx),%r10d
mov    $0x1,%ebp
mov    %rbx,%rdi
mov    %r13d,%esi
mov    %r12d,%edx
mov    %r15d,%ecx
mov    $0x1,%r8d
mov    $0x1,%r9d
push   %r10
push   %rax
call   1070 <XGetImage@plt>
add    $0x10,%rsp
test   %rax,%rax
je     11df <get_sample+0x8f>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x20,%edx
call   1060 <init_sample@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <img_to_sample@plt>
mov    %rbx,%rdi
call   1030 <XFree@plt>
xor    %ebp,%ebp
jmp    11df <get_sample+0x8f>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.Sample = type { i32 }
@ZPixmap = global i32 0
define i32 @get_sample(i32* %0, i32 %1, i32 %2, i32 %3, i64 %4, %struct.Sample* %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca %struct.Sample*
%14 = alloca i32*
store i32* %0, i32** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i64 %4, i64* %12
store %struct.Sample* %5, %struct.Sample** %13
%15 = load %struct.Sample*, %struct.Sample** %13
%16 = icmp eq %struct.Sample* %15, null
br i1 %16, label %17, label %18
17: ; preds = %6
store i32 1, i32* %7
br label %37
18: ; preds = %6
%19 = load i32*, i32** %8
%20 = load i32, i32* %9
%21 = load i32, i32* %10
%22 = load i32, i32* %11
%23 = call i32 (...) @XAllPlanes()
%24 = load i32, i32* @ZPixmap
%25 = call i32* @XGetImage(i32* %19, i32 %20, i32 %21, i32 %22, i32 1, i32 1, i32 %23, i32 %24)
store i32* %25, i32** %14
%26 = load i32*, i32** %14
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %29
28: ; preds = %18
store i32 1, i32* %7
br label %37
29: ; preds = %18
%30 = load %struct.Sample*, %struct.Sample** %13
%31 = call i32 @init_sample(%struct.Sample* %30, i32 1, i32 32)
%32 = load i32*, i32** %14
%33 = load %struct.Sample*, %struct.Sample** %13
%34 = call i32 @img_to_sample(i32* %32, %struct.Sample* %33)
%35 = load i32*, i32** %14
%36 = call i32 @XFree(i32* %35)
store i32 0, i32* %7
br label %37
37: ; preds = %29, %28, %17
%38 = load i32, i32* %7
ret i32 %38
}

LLVM IR (-O2):
%struct.Sample = type { i32 }
@ZPixmap = global i32 0
define i32 @get_sample(i32* %0, i32 %1, i32 %2, i32 %3, i64 %4, %struct.Sample* %5) {
%7 = icmp eq %struct.Sample* %5, null
br i1 %7, label %17, label %8
8: ; preds = %6
%9 = tail call i32 (...) @XAllPlanes()
%10 = load i32, i32* @ZPixmap
%11 = tail call i32* @XGetImage(i32* %0, i32 %1, i32 %2, i32 %3, i32 1, i32 1, i32 %9, i32 %10)
%12 = icmp eq i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = tail call i32 @init_sample(%struct.Sample* %5, i32 1, i32 32)
%15 = tail call i32 @img_to_sample(i32* %11, %struct.Sample* %5)
%16 = tail call i32 @XFree(i32* %11)
br label %17
17: ; preds = %13, %8, %6
%18 = phi i32 [ 1, %6 ], [ 0, %13 ], [ 1, %8 ]
ret i32 %18
}