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

/* Variables and functions */
int /*<<< orphan*/ False;
scalar_t__ Success;
int /*<<< orphan*/ XFree(unsigned char *);
scalar_t__ XGetWindowProperty(int /*<<< orphan*/ *, int /*<<< orphan*/,
                              scalar_t__, int /*<<< orphan*/, int,
                              int /*<<< orphan*/, scalar_t__, scalar_t__ *,
                              int *, unsigned long *, unsigned long *,
                              unsigned char **);
scalar_t__ XInternAtom(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
char *calloc(unsigned long, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memcpy(char *, unsigned char *, unsigned long);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
char *get_property(Display *disp, Window win, Atom xa_prop_type,
                   char *prop_name, unsigned long *size, unsigned long *items) {
  Atom xa_prop_name;
  Atom xa_ret_type;
  int ret_format;
  unsigned long ret_nitems;
  unsigned long ret_bytes_after;
  unsigned long tmp_size;
  unsigned char *ret_prop;
  char *ret;
  xa_prop_name = XInternAtom(disp, prop_name, False);
  if (XGetWindowProperty(disp, win, xa_prop_name, 0, 4096 / 4, False,
                         xa_prop_type, &xa_ret_type, &ret_format, &ret_nitems,
                         &ret_bytes_after, &ret_prop) != Success) {
    fprintf(stderr, "Cannot get %s property.\n", prop_name);
    return NULL;
  }
  if (xa_ret_type != xa_prop_type) {
    fprintf(stderr, "Invalid type of %s property.\n", prop_name);
    XFree(ret_prop);
    return NULL;
  }
  if (ret_format == 32 && strcmp(prop_name, "_NET_CLIENT_LIST") == 0 &&
      sizeof(Window) == 8) {
    ret_format *= 2;
  }
  tmp_size = (ret_format / 8) * ret_nitems;
  ret = calloc(tmp_size + 1, 1);
  if (!ret) {
    perror("get_property malloc failed");
    return NULL;
  }
  memcpy(ret, ret_prop, tmp_size);
  ret[tmp_size] = '\0';
  if (size) {
    *size = ret_format / 8;
  }
  if (items) {
    *items = ret_nitems;
  }
  XFree(ret_prop);
  return ret;
}


x86 assembly (clang, -O0):
<get_property>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0xa8,%rsp
mov    %rdi,-0x28(%rbp)
mov    %esi,-0x2c(%rbp)
mov    %rdx,-0x38(%rbp)
mov    %rcx,-0x40(%rbp)
mov    %r8,-0x48(%rbp)
mov    %r9,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    0x2e2a(%rip),%rax
mov    (%rax),%edx
call   1080 <XInternAtom@plt>
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x58(%rbp),%rdx
mov    0x2e0d(%rip),%rax
mov    (%rax),%r9d
mov    -0x38(%rbp),%r15
xor    %ecx,%ecx
mov    $0x400,%r8d
lea    -0x60(%rbp),%r14
lea    -0x64(%rbp),%rbx
lea    -0x70(%rbp),%r11
lea    -0x78(%rbp),%r10
lea    -0x88(%rbp),%rax
mov    %r15,(%rsp)
mov    %r14,0x8(%rsp)
mov    %rbx,0x10(%rsp)
mov    %r11,0x18(%rsp)
mov    %r10,0x20(%rsp)
mov    %rax,0x28(%rsp)
call   10a0 <XGetWindowProperty@plt>
mov    0x2dd6(%rip),%rcx
cmp    (%rcx),%rax
je     1251 <get_property+0xd1>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rdx
lea    0xdc1(%rip),%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x20(%rbp)
jmp    1396 <get_property+0x216>
mov    -0x60(%rbp),%rax
cmp    -0x38(%rbp),%rax
je     1291 <get_property+0x111>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rdx
lea    0xda6(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x88(%rbp),%rdi
call   1030 <XFree@plt>
movq   $0x0,-0x20(%rbp)
jmp    1396 <get_property+0x216>
cmpl   $0x20,-0x64(%rbp)
jne    12cd <get_property+0x14d>
mov    -0x40(%rbp),%rdi
lea    0xd91(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12cd <get_property+0x14d>
xor    %eax,%eax
test   $0x1,%al
jne    12c4 <get_property+0x144>
jmp    12cd <get_property+0x14d>
mov    -0x64(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cltq
imul   -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x90(%rbp)
cmpq   $0x0,-0x90(%rbp)
jne    1323 <get_property+0x1a3>
lea    0xd37(%rip),%rdi
call   1090 <perror@plt>
movq   $0x0,-0x20(%rbp)
jmp    1396 <get_property+0x216>
mov    -0x90(%rbp),%rdi
mov    -0x88(%rbp),%rsi
mov    -0x80(%rbp),%rdx
call   1070 <memcpy@plt>
mov    -0x90(%rbp),%rax
mov    -0x80(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpq   $0x0,-0x48(%rbp)
je     1369 <get_property+0x1e9>
mov    -0x64(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
movslq %eax,%rcx
mov    -0x48(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x50(%rbp)
je     137f <get_property+0x1ff>
mov    -0x70(%rbp),%rcx
mov    -0x50(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x88(%rbp),%rdi
call   1030 <XFree@plt>
mov    -0x90(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0xa8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_property>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,0x20(%rsp)
mov    %r8,0x18(%rsp)
mov    %rcx,%r12
mov    %rdx,%r13
mov    %esi,%ebp
mov    %rdi,%rbx
mov    0x2e36(%rip),%r14
mov    (%r14),%edx
mov    %rcx,%rsi
call   1080 <XInternAtom@plt>
mov    (%r14),%r9d
lea    0x8(%rsp),%r10
lea    0x30(%rsp),%r11
lea    0x10(%rsp),%r14
lea    0x4(%rsp),%r15
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
xor    %ecx,%ecx
mov    $0x400,%r8d
push   %r10
push   %r11
push   %r14
push   %r15
lea    0x48(%rsp),%rax
push   %rax
push   %r13
call   10a0 <XGetWindowProperty@plt>
add    $0x30,%rsp
mov    0x2dfc(%rip),%rcx
cmp    (%rcx),%rax
jne    12ad <get_property+0x12d>
cmp    %r13,0x28(%rsp)
jne    12c7 <get_property+0x147>
mov    0x4(%rsp),%eax
cmp    $0x20,%eax
jne    122c <get_property+0xac>
lea    0xe17(%rip),%rsi
mov    %r12,%rdi
call   1050 <strcmp@plt>
mov    0x4(%rsp),%eax
lea    0x7(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x3,%ecx
movslq %ecx,%r12
imul   0x10(%rsp),%r12
lea    0x1(%r12),%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     12fd <get_property+0x17d>
mov    %rax,%rbx
mov    0x8(%rsp),%rsi
mov    %rax,%rdi
mov    %r12,%rdx
call   1070 <memcpy@plt>
movb   $0x0,(%rbx,%r12,1)
mov    0x18(%rsp),%rdx
test   %rdx,%rdx
je     128f <get_property+0x10f>
mov    0x4(%rsp),%eax
lea    0x7(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x3,%ecx
movslq %ecx,%rax
mov    %rax,(%rdx)
mov    0x20(%rsp),%rcx
test   %rcx,%rcx
je     12a1 <get_property+0x121>
mov    0x10(%rsp),%rax
mov    %rax,(%rcx)
mov    0x8(%rsp),%rdi
call   1030 <XFree@plt>
jmp    12eb <get_property+0x16b>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
lea    0xd43(%rip),%rsi
mov    %r12,%rdx
call   1060 <fprintf@plt>
jmp    12e9 <get_property+0x169>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
lea    0xd42(%rip),%rsi
mov    %r12,%rdx
call   1060 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1030 <XFree@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd44(%rip),%rdi
call   1090 <perror@plt>
jmp    12e9 <get_property+0x169>

LLVM IR (-O0):
@False = global i32 0
@Success = global i64 0
@stderr = global i32 0
@.str = [25 x i8] c"Cannot get %s property.\0A\00"
@.str.1 = [30 x i8] c"Invalid type of %s property.\0A\00"
@.str.2 = [17 x i8] c"_NET_CLIENT_LIST\00"
@.str.3 = [27 x i8] c"get_property malloc failed\00"
define i8* @get_property(i32* %0, i32 %1, i64 %2, i8* %3, i64* %4, i64* %5) {
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i64*
%13 = alloca i64*
%14 = alloca i64
%15 = alloca i64
%16 = alloca i32
%17 = alloca i64
%18 = alloca i64
%19 = alloca i64
%20 = alloca i8*
%21 = alloca i8*
store i32* %0, i32** %8
store i32 %1, i32* %9
store i64 %2, i64* %10
store i8* %3, i8** %11
store i64* %4, i64** %12
store i64* %5, i64** %13
%22 = load i32*, i32** %8
%23 = load i8*, i8** %11
%24 = load i32, i32* @False
%25 = call i64 @XInternAtom(i32* %22, i8* %23, i32 %24)
store i64 %25, i64* %14
%26 = load i32*, i32** %8
%27 = load i32, i32* %9
%28 = load i64, i64* %14
%29 = load i32, i32* @False
%30 = load i64, i64* %10
%31 = call i64 @XGetWindowProperty(i32* %26, i32 %27, i64 %28, i32 0, i32 1024, i32 %29, i64 %30, i64* %15, i32* %16, i64* %17, i64* %18, i8** %20)
%32 = load i64, i64* @Success
%33 = icmp ne i64 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %6
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %11
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %36)
store i8* null, i8** %7
br label %97
38: ; preds = %6
%39 = load i64, i64* %15
%40 = load i64, i64* %10
%41 = icmp ne i64 %39, %40
br i1 %41, label %42, label %48
42: ; preds = %38
%43 = load i32, i32* @stderr
%44 = load i8*, i8** %11
%45 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %44)
%46 = load i8*, i8** %20
%47 = call i32 @XFree(i8* %46)
store i8* null, i8** %7
br label %97
48: ; preds = %38
%49 = load i32, i32* %16
%50 = icmp eq i32 %49, 32
br i1 %50, label %51, label %59
51: ; preds = %48
%52 = load i8*, i8** %11
%53 = call i64 @strcmp(i8* %52, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %51
br i1 false, label %56, label %59
56: ; preds = %55
%57 = load i32, i32* %16
%58 = mul nsw i32 %57, 2
store i32 %58, i32* %16
br label %59
59: ; preds = %56, %55, %51, %48
%60 = load i32, i32* %16
%61 = sdiv i32 %60, 8
%62 = sext i32 %61 to i64
%63 = load i64, i64* %17
%64 = mul i64 %62, %63
store i64 %64, i64* %19
%65 = load i64, i64* %19
%66 = add i64 %65, 1
%67 = call i8* @calloc(i64 %66, i32 1)
store i8* %67, i8** %21
%68 = load i8*, i8** %21
%69 = icmp ne i8* %68, null
br i1 %69, label %72, label %70
70: ; preds = %59
%71 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i8* null, i8** %7
br label %97
72: ; preds = %59
%73 = load i8*, i8** %21
%74 = load i8*, i8** %20
%75 = load i64, i64* %19
%76 = call i32 @memcpy(i8* %73, i8* %74, i64 %75)
%77 = load i8*, i8** %21
%78 = load i64, i64* %19
%79 = getelementptr inbounds i8, i8* %77, i64 %78
store i8 0, i8* %79
%80 = load i64*, i64** %12
%81 = icmp ne i64* %80, null
br i1 %81, label %82, label %87
82: ; preds = %72
%83 = load i32, i32* %16
%84 = sdiv i32 %83, 8
%85 = sext i32 %84 to i64
%86 = load i64*, i64** %12
store i64 %85, i64* %86
br label %87
87: ; preds = %82, %72
%88 = load i64*, i64** %13
%89 = icmp ne i64* %88, null
br i1 %89, label %90, label %93
90: ; preds = %87
%91 = load i64, i64* %17
%92 = load i64*, i64** %13
store i64 %91, i64* %92
br label %93
93: ; preds = %90, %87
%94 = load i8*, i8** %20
%95 = call i32 @XFree(i8* %94)
%96 = load i8*, i8** %21
store i8* %96, i8** %7
br label %97
97: ; preds = %93, %70, %42, %34
%98 = load i8*, i8** %7
ret i8* %98
}

LLVM IR (-O2):
@False = global i32 0
@Success = global i64 0
@stderr = global i32 0
@.str = [25 x i8] c"Cannot get %s property.\0A\00"
@.str.1 = [30 x i8] c"Invalid type of %s property.\0A\00"
@.str.2 = [17 x i8] c"_NET_CLIENT_LIST\00"
@.str.3 = [27 x i8] c"get_property malloc failed\00"
define i8* @get_property(i32* %0, i32 %1, i64 %2, i8* %3, i64* writeonly %4, i64* writeonly %5) {
%7 = alloca i64
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
%12 = bitcast i64* %7 to i8*
%13 = bitcast i32* %8 to i8*
%14 = bitcast i64* %9 to i8*
%15 = bitcast i64* %10 to i8*
%16 = bitcast i8** %11 to i8*
%17 = load i32, i32* @False
%18 = tail call i64 @XInternAtom(i32* %0, i8* %3, i32 %17)
%19 = load i32, i32* @False
%20 = call i64 @XGetWindowProperty(i32* %0, i32 %1, i64 %18, i32 0, i32 1024, i32 %19, i64 %2, i64* %7, i32* %8, i64* %9, i64* %10, i8** %11)
%21 = load i64, i64* @Success
%22 = icmp eq i64 %20, %21
br i1 %22, label %26, label %23
23: ; preds = %6
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %67
26: ; preds = %6
%27 = load i64, i64* %7
%28 = icmp eq i64 %27, %2
br i1 %28, label %34, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%32 = load i8*, i8** %11
%33 = call i32 @XFree(i8* %32)
br label %67
34: ; preds = %26
%35 = load i32, i32* %8
%36 = icmp eq i32 %35, 32
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* %8
br label %40
40: ; preds = %37, %34
%41 = phi i32 [ %39, %37 ], [ %35, %34 ]
%42 = sdiv i32 %41, 8
%43 = sext i32 %42 to i64
%44 = load i64, i64* %9
%45 = mul i64 %44, %43
%46 = add i64 %45, 1
%47 = call i8* @calloc(i64 %46, i32 1)
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %51
49: ; preds = %40
%50 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %67
51: ; preds = %40
%52 = load i8*, i8** %11
%53 = call i32 @memcpy(i8* %47, i8* %52, i64 %45)
%54 = getelementptr inbounds i8, i8* %47, i64 %45
store i8 0, i8* %54
%55 = icmp eq i64* %4, null
br i1 %55, label %60, label %56
56: ; preds = %51
%57 = load i32, i32* %8
%58 = sdiv i32 %57, 8
%59 = sext i32 %58 to i64
store i64 %59, i64* %4
br label %60
60: ; preds = %56, %51
%61 = icmp eq i64* %5, null
br i1 %61, label %64, label %62
62: ; preds = %60
%63 = load i64, i64* %9
store i64 %63, i64* %5
br label %64
64: ; preds = %62, %60
%65 = load i8*, i8** %11
%66 = call i32 @XFree(i8* %65)
br label %67
67: ; preds = %64, %49, %29, %23
%68 = phi i8* [ null, %23 ], [ null, %29 ], [ %47, %64 ], [ null, %49 ]
ret i8* %68
}