#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 /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ Display;
typedef int /*<<< orphan*/ Atom;

/* Variables and functions */
scalar_t__ DefaultScreen(int /*<<< orphan*/ *);
int /*<<< orphan*/ False;
int /*<<< orphan*/ Log(char *);
scalar_t__ None;
scalar_t__ XGetSelectionOwner(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XInternAtom(int /*<<< orphan*/ *, char *,
                               int /*<<< orphan*/);
int snprintf(char *, int, char *, int);
int HaveCompositor(Display *display) {
  char buf[64];
  int buflen =
      snprintf(buf, sizeof(buf), "_NET_WM_CM_S%d", (int)DefaultScreen(display));
  if (buflen <= 0 || (size_t)buflen >= sizeof(buf)) {
    Log("Wow, pretty long screen number you got there");
    return 0;
  }
  Atom atom = XInternAtom(display, buf, False);
  return XGetSelectionOwner(display, atom) != None;
}


x86 assembly (clang, -O0):
<HaveCompositor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <DefaultScreen@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%ecx
mov    $0x40,%esi
lea    0xe81(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jle    119f <HaveCompositor+0x4f>
movslq -0x54(%rbp),%rax
cmp    $0x40,%rax
jb     11b7 <HaveCompositor+0x67>
lea    0xe69(%rip),%rdi
call   1060 <Log@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f1 <HaveCompositor+0xa1>
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    0x2e22(%rip),%rax
mov    (%rax),%edx
call   1050 <XInternAtom@plt>
mov    %eax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x58(%rbp),%esi
call   1040 <XGetSelectionOwner@plt>
mov    0x2dfd(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HaveCompositor>:
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%rbx
call   1070 <DefaultScreen@plt>
lea    0xe9c(%rip),%rdx
mov    %rsp,%rdi
mov    $0x40,%esi
mov    %eax,%ecx
call   1030 <snprintf@plt>
add    $0xffffffc0,%eax
cmp    $0xffffffc0,%eax
ja     118b <HaveCompositor+0x3b>
lea    0xe8d(%rip),%rdi
call   1060 <Log@plt>
xor    %eax,%eax
jmp    11bb <HaveCompositor+0x6b>
mov    0x2e56(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <XInternAtom@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <XGetSelectionOwner@plt>
mov    %rax,%rcx
mov    0x2e2d(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
setne  %al
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"_NET_WM_CM_S%d\00"
@.str.1 = [45 x i8] c"Wow, pretty long screen number you got there\00"
@False = global i32 0
@None = global i64 0
define i32 @HaveCompositor(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [64 x i8]
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%8 = load i32*, i32** %3
%9 = call i64 @DefaultScreen(i32* %8)
%10 = trunc i64 %9 to i32
%11 = call i32 @snprintf(i8* %7, i32 64, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp sle i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %1
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = icmp uge i64 %16, 64
br i1 %17, label %18, label %20
18: ; preds = %14, %1
%19 = call i32 @Log(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %31
20: ; preds = %14
%21 = load i32*, i32** %3
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%23 = load i32, i32* @False
%24 = call i32 @XInternAtom(i32* %21, i8* %22, i32 %23)
store i32 %24, i32* %6
%25 = load i32*, i32** %3
%26 = load i32, i32* %6
%27 = call i64 @XGetSelectionOwner(i32* %25, i32 %26)
%28 = load i64, i64* @None
%29 = icmp ne i64 %27, %28
%30 = zext i1 %29 to i32
store i32 %30, i32* %2
br label %31
31: ; preds = %20, %18
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@.str = [15 x i8] c"_NET_WM_CM_S%d\00"
@.str.1 = [45 x i8] c"Wow, pretty long screen number you got there\00"
@False = global i32 0
@None = global i64 0
define i32 @HaveCompositor(i32* %0) {
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @DefaultScreen(i32* %0)
%5 = trunc i64 %4 to i32
%6 = call i32 @snprintf(i8* %3, i32 64, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = add i32 %6, -64
%8 = icmp ult i32 %7, -63
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @Log(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
br label %18
11: ; preds = %1
%12 = load i32, i32* @False
%13 = call i32 @XInternAtom(i32* %0, i8* %3, i32 %12)
%14 = call i64 @XGetSelectionOwner(i32* %0, i32 %13)
%15 = load i64, i64* @None
%16 = icmp ne i64 %14, %15
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %11, %9
%19 = phi i32 [ 0, %9 ], [ %17, %11 ]
ret i32 %19
}