#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 scalar_t__ Atom;

/* Variables and functions */
int /*<<< orphan*/ False;
scalar_t__ None;
scalar_t__ XGetSelectionOwner(int /*<<< orphan*/ *, scalar_t__);
scalar_t__ XInternAtom(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  char remote[4096];
  Display *display;
  Atom atom;
  Window win;
  if (argc != 2) {
    usage(argv[0]);
    return 2;
  }
  if (!strcmp("--help", argv[1])) {
    usage(argv[0]);
    return 0;
  }
  sprintf(remote, "xpdf_%s", argv[1]);
  display = XOpenDisplay(NULL);
  if (!display)
    return 2;
  atom = XInternAtom(display, remote, False);
  if (atom == None)
    return 2;
  win = XGetSelectionOwner(display, atom);
  return (win == None) ? 1 : 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119b <main+0x3b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
movl   $0x2,-0x4(%rbp)
jmp    1296 <main+0x136>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe56(%rip),%rdi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11d0 <main+0x70>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    1296 <main+0x136>
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe21(%rip),%rsi
call   1080 <sprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <XOpenDisplay@plt>
mov    %rax,-0x1018(%rbp)
cmpq   $0x0,-0x1018(%rbp)
jne    1215 <main+0xb5>
movl   $0x2,-0x4(%rbp)
jmp    1296 <main+0x136>
mov    -0x1018(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
mov    0x2dbe(%rip),%rax
mov    (%rax),%edx
call   1060 <XInternAtom@plt>
mov    %rax,-0x1020(%rbp)
mov    -0x1020(%rbp),%rax
mov    0x2d9a(%rip),%rcx
cmp    (%rcx),%rax
jne    125b <main+0xfb>
movl   $0x2,-0x4(%rbp)
jmp    1296 <main+0x136>
mov    -0x1018(%rbp),%rdi
mov    -0x1020(%rbp),%rsi
call   1050 <XGetSelectionOwner@plt>
mov    %rax,-0x1028(%rbp)
mov    -0x1028(%rbp),%rdx
mov    0x2d5d(%rip),%rax
mov    (%rax),%rsi
xor    %eax,%eax
mov    $0x1,%ecx
cmp    %rsi,%rdx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11e6 <main+0x86>
mov    0x8(%rbx),%r14
lea    0xe81(%rip),%rdi
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11f5 <main+0x95>
lea    0xe75(%rip),%rsi
mov    %rsp,%rdi
mov    %r14,%rdx
call   1080 <sprintf@plt>
xor    %edi,%edi
call   1040 <XOpenDisplay@plt>
mov    $0x2,%ebx
test   %rax,%rax
je     11ff <main+0x9f>
mov    %rax,%r14
mov    0x2e30(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rsi
mov    %r14,%rdi
call   1060 <XInternAtom@plt>
mov    0x2e14(%rip),%r15
cmp    (%r15),%rax
je     11ff <main+0x9f>
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <XGetSelectionOwner@plt>
xor    %ebx,%ebx
cmp    (%r15),%rax
sete   %bl
jmp    11ff <main+0x9f>
mov    (%rbx),%rdi
call   1070 <usage@plt>
mov    $0x2,%ebx
jmp    11ff <main+0x9f>
mov    (%rbx),%rdi
call   1070 <usage@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"--help\00"
@.str.1 = [8 x i8] c"xpdf_%s\00"
@False = global i32 0
@None = global i64 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4096 x i8]
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @usage(i8* %15)
store i32 2, i32* %3
br label %56
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %17
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 @usage(i8* %26)
store i32 0, i32* %3
br label %56
28: ; preds = %17
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = call i32* @XOpenDisplay(i32* null)
store i32* %34, i32** %7
%35 = load i32*, i32** %7
%36 = icmp ne i32* %35, null
br i1 %36, label %38, label %37
37: ; preds = %28
store i32 2, i32* %3
br label %56
38: ; preds = %28
%39 = load i32*, i32** %7
%40 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%41 = load i32, i32* @False
%42 = call i64 @XInternAtom(i32* %39, i8* %40, i32 %41)
store i64 %42, i64* %8
%43 = load i64, i64* %8
%44 = load i64, i64* @None
%45 = icmp eq i64 %43, %44
br i1 %45, label %46, label %47
46: ; preds = %38
store i32 2, i32* %3
br label %56
47: ; preds = %38
%48 = load i32*, i32** %7
%49 = load i64, i64* %8
%50 = call i64 @XGetSelectionOwner(i32* %48, i64 %49)
store i64 %50, i64* %9
%51 = load i64, i64* %9
%52 = load i64, i64* @None
%53 = icmp eq i64 %51, %52
%54 = zext i1 %53 to i64
%55 = select i1 %53, i32 1, i32 0
store i32 %55, i32* %3
br label %56
56: ; preds = %47, %46, %37, %23, %12
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [7 x i8] c"--help\00"
@.str.1 = [8 x i8] c"xpdf_%s\00"
@False = global i32 0
@None = global i64 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @usage(i8* %7)
br label %31
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @strcmp(i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* dereferenceable(1) %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i8*, i8** %1
%16 = tail call i32 @usage(i8* %15)
br label %31
17: ; preds = %9
%18 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%19 = tail call i32* @XOpenDisplay(i32* null)
%20 = icmp eq i32* %19, null
br i1 %20, label %31, label %21
21: ; preds = %17
%22 = load i32, i32* @False
%23 = call i64 @XInternAtom(i32* %19, i8* %4, i32 %22)
%24 = load i64, i64* @None
%25 = icmp eq i64 %23, %24
br i1 %25, label %31, label %26
26: ; preds = %21
%27 = call i64 @XGetSelectionOwner(i32* %19, i64 %23)
%28 = load i64, i64* @None
%29 = icmp eq i64 %27, %28
%30 = zext i1 %29 to i32
br label %31
31: ; preds = %21, %17, %26, %14, %6
%32 = phi i32 [ 2, %6 ], [ %30, %26 ], [ 0, %14 ], [ 2, %17 ], [ 2, %21 ]
ret i32 %32
}