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

/* Variables and functions */
int /*<<< orphan*/ AnyPropertyType;
int /*<<< orphan*/ DefaultRootWindow(int /*<<< orphan*/ *);
int /*<<< orphan*/ False;
scalar_t__ None;
#define XA_CARDINAL 130
#define XA_INTEGER 129
#define XA_WINDOW 128
int /*<<< orphan*/ XFree(unsigned char *);
scalar_t__ XGetWindowProperty(int /*<<< orphan*/ *, int /*<<< orphan*/,
                              scalar_t__, int /*<<< orphan*/, int,
                              int /*<<< orphan*/, int /*<<< orphan*/,
                              scalar_t__ *, int *, unsigned long *,
                              unsigned long *, unsigned char **);
scalar_t__ XInternAtom(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int mbp_get_x_vtnum(Display *dpy) {
  Atom prop;
  Atom actualtype;
  int actualformat;
  unsigned long nitems;
  unsigned long bytes_after;
  unsigned char *buf;
  int num;
  prop = XInternAtom(dpy, "XFree86_VT", False);
  if (prop == None)
    return -1;
  if (XGetWindowProperty(dpy, DefaultRootWindow(dpy), prop, 0, 1, False,
                         AnyPropertyType, &actualtype, &actualformat, &nitems,
                         &bytes_after, &buf)) {
    return -1;
  }
  if (nitems != 1) {
    XFree(buf);
    return -1;
  }
  switch (actualtype) {
  case XA_CARDINAL:
  case XA_INTEGER:
  case XA_WINDOW:
    switch (actualformat) {
    case 8:
      num = (*(uint8_t *)(void *)buf);
      break;
    case 16:
      num = (*(uint16_t *)(void *)buf);
      break;
    case 32:
      num = (*(uint32_t *)(void *)buf);
      break;
    default:
      XFree(buf);
      return -1;
    }
    break;
  default:
    XFree(buf);
    return -1;
  }
  XFree(buf);
  return num;
}


x86 assembly (clang, -O0):
<mbp_get_x_vtnum>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rdi,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%edx
lea    0xe98(%rip),%rsi
call   1050 <XInternAtom@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2e5c(%rip),%rcx
cmp    (%rcx),%rax
jne    1191 <mbp_get_x_vtnum+0x51>
movl   $0xffffffff,-0x1c(%rbp)
jmp    12e9 <mbp_get_x_vtnum+0x1a9>
mov    -0x28(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <DefaultRootWindow@plt>
mov    -0x68(%rbp),%rdi
mov    %eax,%esi
mov    -0x30(%rbp),%rdx
mov    0x2e2d(%rip),%rax
mov    (%rax),%r9d
mov    0x2e33(%rip),%rax
mov    (%rax),%r15d
xor    %ecx,%ecx
mov    $0x1,%r8d
lea    -0x38(%rbp),%r14
lea    -0x3c(%rbp),%rbx
lea    -0x48(%rbp),%r11
lea    -0x50(%rbp),%r10
lea    -0x58(%rbp),%rax
mov    %r15d,(%rsp)
mov    %r14,0x8(%rsp)
mov    %rbx,0x10(%rsp)
mov    %r11,0x18(%rsp)
mov    %r10,0x20(%rsp)
mov    %rax,0x28(%rsp)
call   1060 <XGetWindowProperty@plt>
cmp    $0x0,%rax
je     1214 <mbp_get_x_vtnum+0xd4>
movl   $0xffffffff,-0x1c(%rbp)
jmp    12e9 <mbp_get_x_vtnum+0x1a9>
cmpq   $0x1,-0x48(%rbp)
je     1234 <mbp_get_x_vtnum+0xf4>
mov    -0x58(%rbp),%rdi
call   1040 <XFree@plt>
movl   $0xffffffff,-0x1c(%rbp)
jmp    12e9 <mbp_get_x_vtnum+0x1a9>
mov    -0x38(%rbp),%rax
add    $0xffffffffffffff80,%rax
sub    $0x2,%rax
ja     12c5 <mbp_get_x_vtnum+0x185>
jmp    124b <mbp_get_x_vtnum+0x10b>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x6c(%rbp)
sub    $0x8,%eax
je     1281 <mbp_get_x_vtnum+0x141>
jmp    125f <mbp_get_x_vtnum+0x11f>
mov    -0x6c(%rbp),%eax
sub    $0x10,%eax
je     128f <mbp_get_x_vtnum+0x14f>
jmp    1270 <mbp_get_x_vtnum+0x130>
mov    -0x6c(%rbp),%eax
sub    $0x20,%eax
je     129d <mbp_get_x_vtnum+0x15d>
jmp    12ab <mbp_get_x_vtnum+0x16b>
mov    -0x58(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
jmp    12c0 <mbp_get_x_vtnum+0x180>
mov    -0x58(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
jmp    12c0 <mbp_get_x_vtnum+0x180>
mov    -0x58(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
jmp    12c0 <mbp_get_x_vtnum+0x180>
mov    -0x58(%rbp),%rdi
call   1040 <XFree@plt>
movl   $0xffffffff,-0x1c(%rbp)
jmp    12e9 <mbp_get_x_vtnum+0x1a9>
jmp    12da <mbp_get_x_vtnum+0x19a>
mov    -0x58(%rbp),%rdi
call   1040 <XFree@plt>
movl   $0xffffffff,-0x1c(%rbp)
jmp    12e9 <mbp_get_x_vtnum+0x1a9>
mov    -0x58(%rbp),%rdi
call   1040 <XFree@plt>
mov    -0x5c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<mbp_get_x_vtnum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
mov    0x2e88(%rip),%r15
mov    (%r15),%edx
lea    0xe9e(%rip),%rsi
call   1050 <XInternAtom@plt>
mov    %rax,%rbp
mov    0x2e67(%rip),%rax
mov    $0xffffffff,%r14d
cmp    (%rax),%rbp
je     1218 <mbp_get_x_vtnum+0xd8>
mov    %rbx,%rdi
call   1030 <DefaultRootWindow@plt>
mov    (%r15),%r9d
mov    0x2e5e(%rip),%rcx
mov    (%rcx),%r10d
mov    %rsp,%r11
lea    0x20(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r13
mov    %rbx,%rdi
mov    %eax,%esi
mov    %rbp,%rdx
xor    %ecx,%ecx
mov    $0x1,%r8d
push   %r11
push   %r15
push   %r12
push   %r13
lea    0x38(%rsp),%rax
push   %rax
push   %r10
call   1060 <XGetWindowProperty@plt>
add    $0x30,%rsp
test   %rax,%rax
jne    1218 <mbp_get_x_vtnum+0xd8>
cmpq   $0x1,0x10(%rsp)
jne    120f <mbp_get_x_vtnum+0xcf>
mov    0x18(%rsp),%rax
add    $0xffffffffffffff80,%rax
cmp    $0x2,%rax
ja     120f <mbp_get_x_vtnum+0xcf>
mov    0xc(%rsp),%eax
cmp    $0x20,%rax
ja     120f <mbp_get_x_vtnum+0xcf>
movabs $0x100010100,%rcx
bt     %rax,%rcx
jae    120f <mbp_get_x_vtnum+0xcf>
mov    (%rsp),%rdi
mov    (%rdi),%r14d
jmp    1213 <mbp_get_x_vtnum+0xd3>
mov    (%rsp),%rdi
call   1040 <XFree@plt>
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"XFree86_VT\00"
@False = global i32 0
@None = global i64 0
@AnyPropertyType = global i32 0
define i32 @mbp_get_x_vtnum(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
store i32* %0, i32** %3
%11 = load i32*, i32** %3
%12 = load i32, i32* @False
%13 = call i64 @XInternAtom(i32* %11, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %12)
store i64 %13, i64* %4
%14 = load i64, i64* %4
%15 = load i64, i64* @None
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %1
store i32 -1, i32* %2
br label %61
18: ; preds = %1
%19 = load i32*, i32** %3
%20 = load i32*, i32** %3
%21 = call i32 @DefaultRootWindow(i32* %20)
%22 = load i64, i64* %4
%23 = load i32, i32* @False
%24 = load i32, i32* @AnyPropertyType
%25 = call i64 @XGetWindowProperty(i32* %19, i32 %21, i64 %22, i32 0, i32 1, i32 %23, i32 %24, i64* %5, i32* %6, i64* %7, i64* %8, i8** %9)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %18
store i32 -1, i32* %2
br label %61
28: ; preds = %18
%29 = load i64, i64* %7
%30 = icmp ne i64 %29, 1
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i8*, i8** %9
%33 = call i32 @XFree(i8* %32)
store i32 -1, i32* %2
br label %61
34: ; preds = %28
%35 = load i64, i64* %5
switch i64 %35, label %54 [
i64 130, label %36
i64 129, label %36
i64 128, label %36
]
36: ; preds = %34, %34, %34
%37 = load i32, i32* %6
switch i32 %37, label %50 [
i32 8, label %38
i32 16, label %42
i32 32, label %46
]
38: ; preds = %36
%39 = load i8*, i8** %9
%40 = bitcast i8* %39 to i32*
%41 = load i32, i32* %40
store i32 %41, i32* %10
br label %53
42: ; preds = %36
%43 = load i8*, i8** %9
%44 = bitcast i8* %43 to i32*
%45 = load i32, i32* %44
store i32 %45, i32* %10
br label %53
46: ; preds = %36
%47 = load i8*, i8** %9
%48 = bitcast i8* %47 to i32*
%49 = load i32, i32* %48
store i32 %49, i32* %10
br label %53
50: ; preds = %36
%51 = load i8*, i8** %9
%52 = call i32 @XFree(i8* %51)
store i32 -1, i32* %2
br label %61
53: ; preds = %46, %42, %38
br label %57
54: ; preds = %34
%55 = load i8*, i8** %9
%56 = call i32 @XFree(i8* %55)
store i32 -1, i32* %2
br label %61
57: ; preds = %53
%58 = load i8*, i8** %9
%59 = call i32 @XFree(i8* %58)
%60 = load i32, i32* %10
store i32 %60, i32* %2
br label %61
61: ; preds = %57, %54, %50, %31, %27, %17
%62 = load i32, i32* %2
ret i32 %62
}

LLVM IR (-O2):
@.str = [11 x i8] c"XFree86_VT\00"
@False = global i32 0
@None = global i64 0
@AnyPropertyType = global i32 0
define i32 @mbp_get_x_vtnum(i32* %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
%7 = bitcast i64* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = bitcast i64* %4 to i8*
%10 = bitcast i64* %5 to i8*
%11 = bitcast i8** %6 to i8*
%12 = load i32, i32* @False
%13 = tail call i64 @XInternAtom(i32* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i64, i64* @None
%15 = icmp eq i64 %13, %14
br i1 %15, label %46, label %16
16: ; preds = %1
%17 = tail call i32 @DefaultRootWindow(i32* %0)
%18 = load i32, i32* @False
%19 = load i32, i32* @AnyPropertyType
%20 = call i64 @XGetWindowProperty(i32* %0, i32 %17, i64 %13, i32 0, i32 1, i32 %18, i32 %19, i64* %2, i32* %3, i64* %4, i64* %5, i8** %6)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %46
22: ; preds = %16
%23 = load i64, i64* %4
%24 = icmp eq i64 %23, 1
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load i8*, i8** %6
%27 = call i32 @XFree(i8* %26)
br label %46
28: ; preds = %22
%29 = load i64, i64* %2
%30 = add i64 %29, -128
%31 = icmp ult i64 %30, 3
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = load i32, i32* %3
switch i32 %33, label %34 [
i32 8, label %40
i32 16, label %40
i32 32, label %40
]
34: ; preds = %32
%35 = load i8*, i8** %6
%36 = call i32 @XFree(i8* %35)
br label %46
37: ; preds = %28
%38 = load i8*, i8** %6
%39 = call i32 @XFree(i8* %38)
br label %46
40: ; preds = %32, %32, %32
%41 = bitcast i8** %6 to i32**
%42 = load i32*, i32** %41
%43 = load i32, i32* %42
%44 = bitcast i32* %42 to i8*
%45 = call i32 @XFree(i8* %44)
br label %46
46: ; preds = %16, %1, %40, %37, %34, %25
%47 = phi i32 [ -1, %25 ], [ -1, %37 ], [ -1, %34 ], [ %43, %40 ], [ -1, %1 ], [ -1, %16 ]
ret i32 %47
}