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

/* Variables and functions */
int /*<<< orphan*/ CurrentTime;
scalar_t__ DefaultRootWindow(int /*<<< orphan*/ *);
int /*<<< orphan*/ False;
scalar_t__ None;
int /*<<< orphan*/ XFlush(int /*<<< orphan*/ *);
scalar_t__ XGetSelectionOwner(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XGrabServer(int /*<<< orphan*/ *);
int /*<<< orphan*/ XInternAtom(int /*<<< orphan*/ *, char *,
                               int /*<<< orphan*/);
int /*<<< orphan*/ XSetSelectionOwner(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                      scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ XUngrabServer(int /*<<< orphan*/ *);
int _DtGetLock(Display *display, char *lock_name) {
  Atom lock_atom;
  Window selection_owner;
  Window root_window;
  lock_atom = XInternAtom(display, lock_name, False);
  root_window = DefaultRootWindow(display);
  XGrabServer(display);
  if ((selection_owner = XGetSelectionOwner(display, lock_atom)) == None)
    XSetSelectionOwner(display, lock_atom, root_window, CurrentTime);
  XUngrabServer(display);
  XFlush(display);
  if (selection_owner == None)
    return (1);
  else
    return (0);
}


x86 assembly (clang, -O0):
<_DtGetLock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e51(%rip),%rax
mov    (%rax),%edx
call   1060 <XInternAtom@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <DefaultRootWindow@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <XGrabServer@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <XGetSelectionOwner@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e12(%rip),%rcx
cmp    (%rcx),%rax
jne    11e8 <_DtGetLock+0x78>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    0x2e07(%rip),%rax
mov    (%rax),%ecx
call   1080 <XSetSelectionOwner@plt>
mov    -0x10(%rbp),%rdi
call   1040 <XUngrabServer@plt>
mov    -0x10(%rbp),%rdi
call   1090 <XFlush@plt>
mov    -0x28(%rbp),%rax
mov    0x2dd3(%rip),%rcx
cmp    (%rcx),%rax
jne    121a <_DtGetLock+0xaa>
movl   $0x1,-0x4(%rbp)
jmp    1221 <_DtGetLock+0xb1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_DtGetLock>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
mov    0x2e5e(%rip),%rax
mov    (%rax),%edx
call   1060 <XInternAtom@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <DefaultRootWindow@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1070 <XGrabServer@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1050 <XGetSelectionOwner@plt>
mov    %rax,%rbp
mov    0x2e24(%rip),%r12
cmp    (%r12),%rax
jne    11d1 <_DtGetLock+0x61>
mov    0x2e27(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r15,%rdx
call   1080 <XSetSelectionOwner@plt>
mov    %rbx,%rdi
call   1040 <XUngrabServer@plt>
mov    %rbx,%rdi
call   1090 <XFlush@plt>
xor    %eax,%eax
cmp    (%r12),%rbp
sete   %al
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@False = global i32 0
@None = global i64 0
@CurrentTime = global i32 0
define i32 @_DtGetLock(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
store i32* %0, i32** %4
store i8* %1, i8** %5
%9 = load i32*, i32** %4
%10 = load i8*, i8** %5
%11 = load i32, i32* @False
%12 = call i32 @XInternAtom(i32* %9, i8* %10, i32 %11)
store i32 %12, i32* %6
%13 = load i32*, i32** %4
%14 = call i64 @DefaultRootWindow(i32* %13)
store i64 %14, i64* %8
%15 = load i32*, i32** %4
%16 = call i32 @XGrabServer(i32* %15)
%17 = load i32*, i32** %4
%18 = load i32, i32* %6
%19 = call i64 @XGetSelectionOwner(i32* %17, i32 %18)
store i64 %19, i64* %7
%20 = load i64, i64* @None
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %28
22: ; preds = %2
%23 = load i32*, i32** %4
%24 = load i32, i32* %6
%25 = load i64, i64* %8
%26 = load i32, i32* @CurrentTime
%27 = call i32 @XSetSelectionOwner(i32* %23, i32 %24, i64 %25, i32 %26)
br label %28
28: ; preds = %22, %2
%29 = load i32*, i32** %4
%30 = call i32 @XUngrabServer(i32* %29)
%31 = load i32*, i32** %4
%32 = call i32 @XFlush(i32* %31)
%33 = load i64, i64* %7
%34 = load i64, i64* @None
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %37
36: ; preds = %28
store i32 1, i32* %3
br label %38
37: ; preds = %28
store i32 0, i32* %3
br label %38
38: ; preds = %37, %36
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@False = global i32 0
@None = global i64 0
@CurrentTime = global i32 0
define i32 @_DtGetLock(i32* %0, i8* %1) {
%3 = load i32, i32* @False
%4 = tail call i32 @XInternAtom(i32* %0, i8* %1, i32 %3)
%5 = tail call i64 @DefaultRootWindow(i32* %0)
%6 = tail call i32 @XGrabServer(i32* %0)
%7 = tail call i64 @XGetSelectionOwner(i32* %0, i32 %4)
%8 = load i64, i64* @None
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @CurrentTime
%12 = tail call i32 @XSetSelectionOwner(i32* %0, i32 %4, i64 %5, i32 %11)
br label %13
13: ; preds = %10, %2
%14 = tail call i32 @XUngrabServer(i32* %0)
%15 = tail call i32 @XFlush(i32* %0)
%16 = load i64, i64* @None
%17 = icmp eq i64 %7, %16
%18 = zext i1 %17 to i32
ret i32 %18
}