#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  unsigned long x;
  unsigned long y;
  unsigned long width;
  unsigned long height;
  int /*<<< orphan*/ border_width;
  int /*<<< orphan*/ root;
};
typedef TYPE_1__ XWindowAttributes;
typedef int /*<<< orphan*/ Window;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int XGetWindowAttributes(int /*<<< orphan*/ *, int /*<<< orphan*/, TYPE_1__ *);
int /*<<< orphan*/ XMoveResizeWindow(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                     unsigned long, unsigned long,
                                     unsigned long, unsigned long);
int XTranslateCoordinates(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/, unsigned long *, unsigned long *,
                          int /*<<< orphan*/ *);
unsigned long clamp_value(unsigned long, int /*<<< orphan*/, unsigned long);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int /*<<< orphan*/);
unsigned long get_randnum(int, int);
int /*<<< orphan*/ send_client_msg(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                   char *, int /*<<< orphan*/, unsigned long,
                                   unsigned long, unsigned long, unsigned long);
int /*<<< orphan*/ stderr;
scalar_t__ wm_supports(int /*<<< orphan*/ *, char *);
void slide_window(Display *disp, Window *win, unsigned long desk_w,
                  unsigned long desk_h) {
  unsigned long x, y;
  unsigned long w, h;
  XWindowAttributes moo;
  Window junk;
  if (XGetWindowAttributes(disp, *win, &moo) != 1) {
    fprintf(stderr, "Cannot get attributes of window 0x%lx.\n", *win);
    return;
  }
  if (XTranslateCoordinates(disp, *win, moo.root, -moo.border_width,
                            -moo.border_width, &moo.x, &moo.y, &junk) != 1) {
    fprintf(stderr, "Cannot translate coordinates of window 0x%lx.\n", *win);
    return;
  }
  x = moo.x + get_randnum(-32, 32);
  y = moo.y + get_randnum(-32, 32);
  w = moo.width + get_randnum(-32, 32);
  h = moo.height + get_randnum(-32, 32);
  x = clamp_value(x, 0, desk_w);
  y = clamp_value(y, 0, desk_h);
  w = clamp_value(w, 0, desk_w);
  h = clamp_value(h, 0, desk_h);
  if (wm_supports(disp, "_NET_MOVERESIZE_WINDOW")) {
    send_client_msg(disp, *win, "_NET_MOVERESIZE_WINDOW", 0, x, y, w, h);
  } else {
    XMoveResizeWindow(disp, *win, x, y, w, h);
  }
}


x86 assembly (clang, -O0):
<slide_window>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    -0x68(%rbp),%rdx
call   1090 <XGetWindowAttributes@plt>
cmp    $0x1,%eax
je     11d7 <slide_window+0x57>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xe33(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1392 <slide_window+0x212>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x44(%rbp),%edx
xor    %ecx,%ecx
sub    -0x48(%rbp),%ecx
xor    %r8d,%r8d
sub    -0x48(%rbp),%r8d
lea    -0x68(%rbp),%r9
lea    -0x68(%rbp),%r10
add    $0x8,%r10
lea    -0x6c(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <XTranslateCoordinates@plt>
cmp    $0x1,%eax
je     1237 <slide_window+0xb7>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xdfb(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1392 <slide_window+0x212>
mov    -0x68(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    $0xffffffe0,%edi
mov    $0x20,%esi
call   1060 <get_randnum@plt>
mov    %rax,%rcx
mov    -0x90(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    $0xffffffe0,%edi
mov    $0x20,%esi
call   1060 <get_randnum@plt>
mov    %rax,%rcx
mov    -0x88(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    $0xffffffe0,%edi
mov    $0x20,%esi
call   1060 <get_randnum@plt>
mov    %rax,%rcx
mov    -0x80(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    $0xffffffe0,%edi
mov    $0x20,%esi
call   1060 <get_randnum@plt>
mov    %rax,%rcx
mov    -0x78(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   10a0 <clamp_value@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   10a0 <clamp_value@plt>
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   10a0 <clamp_value@plt>
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   10a0 <clamp_value@plt>
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xd29(%rip),%rsi
call   1070 <wm_supports@plt>
cmp    $0x0,%rax
je     1373 <slide_window+0x1f3>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    -0x38(%rbp),%r10
mov    -0x40(%rbp),%rax
lea    0xcf9(%rip),%rdx
xor    %ecx,%ecx
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1080 <send_client_msg@plt>
jmp    1392 <slide_window+0x212>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    -0x40(%rbp),%r9
call   1040 <XMoveResizeWindow@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slide_window>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rsi),%esi
lea    0x20(%rsp),%rdx
call   1090 <XGetWindowAttributes@plt>
cmp    $0x1,%eax
jne    12cb <slide_window+0x14b>
mov    (%rbx),%esi
mov    0x44(%rsp),%edx
xor    %ecx,%ecx
sub    0x40(%rsp),%ecx
lea    0x28(%rsp),%rax
lea    0x1c(%rsp),%rbp
lea    0x20(%rsp),%r9
mov    %r14,%rdi
mov    %ecx,%r8d
push   %rbp
push   %rax
call   1030 <XTranslateCoordinates@plt>
add    $0x10,%rsp
cmp    $0x1,%eax
jne    12e4 <slide_window+0x164>
mov    0x20(%rsp),%rbp
mov    $0xffffffe0,%edi
mov    $0x20,%esi
call   1060 <get_randnum@plt>
add    %rax,%rbp
mov    %rbp,(%rsp)
mov    0x28(%rsp),%rbp
mov    $0xffffffe0,%edi
mov    $0x20,%esi
call   1060 <get_randnum@plt>
add    %rax,%rbp
mov    %r15,0x10(%rsp)
mov    0x30(%rsp),%r15
mov    $0xffffffe0,%edi
mov    $0x20,%esi
call   1060 <get_randnum@plt>
add    %rax,%r15
mov    0x38(%rsp),%r13
mov    $0xffffffe0,%edi
mov    $0x20,%esi
call   1060 <get_randnum@plt>
add    %rax,%r13
mov    (%rsp),%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   10a0 <clamp_value@plt>
mov    %rax,(%rsp)
mov    %rbp,%rdi
xor    %esi,%esi
mov    0x10(%rsp),%rbp
mov    %rbp,%rdx
call   10a0 <clamp_value@plt>
mov    %rax,0x8(%rsp)
mov    %r15,%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   10a0 <clamp_value@plt>
mov    %rax,%r15
mov    %r13,%rdi
xor    %esi,%esi
mov    %rbp,%rdx
call   10a0 <clamp_value@plt>
mov    %rax,%rbp
lea    0xdbe(%rip),%rsi
mov    %r14,%rdi
call   1070 <wm_supports@plt>
mov    (%rbx),%esi
test   %rax,%rax
je     12fd <slide_window+0x17d>
lea    0xda8(%rip),%rdx
mov    %r14,%rdi
xor    %ecx,%ecx
mov    (%rsp),%r8
mov    0x8(%rsp),%r9
push   %rbp
push   %r15
call   1080 <send_client_msg@plt>
add    $0x10,%rsp
jmp    1314 <slide_window+0x194>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%edx
lea    0xd23(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1314 <slide_window+0x194>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%edx
lea    0xd32(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1314 <slide_window+0x194>
mov    %r14,%rdi
mov    (%rsp),%rdx
mov    0x8(%rsp),%rcx
mov    %r15,%r8
mov    %rbp,%r9
call   1040 <XMoveResizeWindow@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64, i64, i64, i64, i32, i32 }
@stderr = global i32 0
@.str = [40 x i8] c"Cannot get attributes of window 0x%lx.\0A\00"
@.str.1 = [47 x i8] c"Cannot translate coordinates of window 0x%lx.\0A\00"
@.str.2 = [23 x i8] c"_NET_MOVERESIZE_WINDOW\00"
define void @slide_window(i32* %0, i32* %1, i64 %2, i64 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca %struct.TYPE_3__
%14 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%15 = load i32*, i32** %5
%16 = load i32*, i32** %6
%17 = load i32, i32* %16
%18 = call i32 @XGetWindowAttributes(i32* %15, i32 %17, %struct.TYPE_3__* %13)
%19 = icmp ne i32 %18, 1
br i1 %19, label %20, label %25
20: ; preds = %4
%21 = load i32, i32* @stderr
%22 = load i32*, i32** %6
%23 = load i32, i32* %22
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %96
25: ; preds = %4
%26 = load i32*, i32** %5
%27 = load i32*, i32** %6
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %13, i32 0, i32 5
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %13, i32 0, i32 4
%32 = load i32, i32* %31
%33 = sub nsw i32 0, %32
%34 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %13, i32 0, i32 4
%35 = load i32, i32* %34
%36 = sub nsw i32 0, %35
%37 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %13, i32 0, i32 0
%38 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %13, i32 0, i32 1
%39 = call i32 @XTranslateCoordinates(i32* %26, i32 %28, i32 %30, i32 %33, i32 %36, i64* %37, i64* %38, i32* %14)
%40 = icmp ne i32 %39, 1
br i1 %40, label %41, label %46
41: ; preds = %25
%42 = load i32, i32* @stderr
%43 = load i32*, i32** %6
%44 = load i32, i32* %43
%45 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %44)
br label %96
46: ; preds = %25
%47 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %13, i32 0, i32 0
%48 = load i64, i64* %47
%49 = call i64 @get_randnum(i32 -32, i32 32)
%50 = add i64 %48, %49
store i64 %50, i64* %9
%51 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %13, i32 0, i32 1
%52 = load i64, i64* %51
%53 = call i64 @get_randnum(i32 -32, i32 32)
%54 = add i64 %52, %53
store i64 %54, i64* %10
%55 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %13, i32 0, i32 2
%56 = load i64, i64* %55
%57 = call i64 @get_randnum(i32 -32, i32 32)
%58 = add i64 %56, %57
store i64 %58, i64* %11
%59 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %13, i32 0, i32 3
%60 = load i64, i64* %59
%61 = call i64 @get_randnum(i32 -32, i32 32)
%62 = add i64 %60, %61
store i64 %62, i64* %12
%63 = load i64, i64* %9
%64 = load i64, i64* %7
%65 = call i64 @clamp_value(i64 %63, i32 0, i64 %64)
store i64 %65, i64* %9
%66 = load i64, i64* %10
%67 = load i64, i64* %8
%68 = call i64 @clamp_value(i64 %66, i32 0, i64 %67)
store i64 %68, i64* %10
%69 = load i64, i64* %11
%70 = load i64, i64* %7
%71 = call i64 @clamp_value(i64 %69, i32 0, i64 %70)
store i64 %71, i64* %11
%72 = load i64, i64* %12
%73 = load i64, i64* %8
%74 = call i64 @clamp_value(i64 %72, i32 0, i64 %73)
store i64 %74, i64* %12
%75 = load i32*, i32** %5
%76 = call i64 @wm_supports(i32* %75, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %87
78: ; preds = %46
%79 = load i32*, i32** %5
%80 = load i32*, i32** %6
%81 = load i32, i32* %80
%82 = load i64, i64* %9
%83 = load i64, i64* %10
%84 = load i64, i64* %11
%85 = load i64, i64* %12
%86 = call i32 @send_client_msg(i32* %79, i32 %81, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 0, i64 %82, i64 %83, i64 %84, i64 %85)
br label %96
87: ; preds = %46
%88 = load i32*, i32** %5
%89 = load i32*, i32** %6
%90 = load i32, i32* %89
%91 = load i64, i64* %9
%92 = load i64, i64* %10
%93 = load i64, i64* %11
%94 = load i64, i64* %12
%95 = call i32 @XMoveResizeWindow(i32* %88, i32 %90, i64 %91, i64 %92, i64 %93, i64 %94)
br label %96
96: ; preds = %20, %41, %87, %78
ret void
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i64, i64, i64, i32, i32 }
@stderr = global i32 0
@.str = [40 x i8] c"Cannot get attributes of window 0x%lx.\0A\00"
@.str.1 = [47 x i8] c"Cannot translate coordinates of window 0x%lx.\0A\00"
@.str.2 = [23 x i8] c"_NET_MOVERESIZE_WINDOW\00"
define void @slide_window(i32* %0, i32* nocapture %1, i64 %2, i64 %3) {
%5 = alloca %struct.TYPE_3__
%6 = alloca i32
%7 = bitcast %struct.TYPE_3__* %5 to i8*
%8 = bitcast i32* %6 to i8*
%9 = load i32, i32* %1
%10 = call i32 @XGetWindowAttributes(i32* %0, i32 %9, %struct.TYPE_3__* %5)
%11 = icmp eq i32 %10, 1
br i1 %11, label %16, label %12
12: ; preds = %4
%13 = load i32, i32* @stderr
%14 = load i32, i32* %1
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %57
16: ; preds = %4
%17 = load i32, i32* %1
%18 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i64 0, i32 5
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i64 0, i32 4
%21 = load i32, i32* %20
%22 = sub nsw i32 0, %21
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i64 0, i32 0
%24 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i64 0, i32 1
%25 = call i32 @XTranslateCoordinates(i32* %0, i32 %17, i32 %19, i32 %22, i32 %22, i64* %23, i64* %24, i32* %6)
%26 = icmp eq i32 %25, 1
br i1 %26, label %31, label %27
27: ; preds = %16
%28 = load i32, i32* @stderr
%29 = load i32, i32* %1
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %29)
br label %57
31: ; preds = %16
%32 = load i64, i64* %23
%33 = call i64 @get_randnum(i32 -32, i32 32)
%34 = add i64 %33, %32
%35 = load i64, i64* %24
%36 = call i64 @get_randnum(i32 -32, i32 32)
%37 = add i64 %36, %35
%38 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i64 0, i32 2
%39 = load i64, i64* %38
%40 = call i64 @get_randnum(i32 -32, i32 32)
%41 = add i64 %40, %39
%42 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i64 0, i32 3
%43 = load i64, i64* %42
%44 = call i64 @get_randnum(i32 -32, i32 32)
%45 = add i64 %44, %43
%46 = call i64 @clamp_value(i64 %34, i32 0, i64 %2)
%47 = call i64 @clamp_value(i64 %37, i32 0, i64 %3)
%48 = call i64 @clamp_value(i64 %41, i32 0, i64 %2)
%49 = call i64 @clamp_value(i64 %45, i32 0, i64 %3)
%50 = call i64 @wm_supports(i32* %0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
%52 = load i32, i32* %1
br i1 %51, label %55, label %53
53: ; preds = %31
%54 = call i32 @send_client_msg(i32* %0, i32 %52, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 0, i64 %46, i64 %47, i64 %48, i64 %49)
br label %57
55: ; preds = %31
%56 = call i32 @XMoveResizeWindow(i32* %0, i32 %52, i64 %46, i64 %47, i64 %48, i64 %49)
br label %57
57: ; preds = %53, %55, %27, %12
ret void
}