#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_8__ TYPE_3__;
typedef struct TYPE_7__ TYPE_2__;
typedef struct TYPE_6__ TYPE_1__;

/* Type definitions */
struct TYPE_6__ {
  int width;
  int height;
  scalar_t__ override_redirect;
};
typedef TYPE_1__ XWindowAttributes;
struct TYPE_7__ {
  int /*<<< orphan*/ window;
};
typedef TYPE_2__ XMapRequestEvent;
struct TYPE_8__ {
  TYPE_2__ xmaprequest;
};
typedef TYPE_3__ XEvent;
typedef int /*<<< orphan*/ Window;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ DefaultRootWindow(int /*<<< orphan*/ *);
int /*<<< orphan*/ None;
scalar_t__ XGetTransientForHint(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                int /*<<< orphan*/ *);
int /*<<< orphan*/ XGetWindowAttributes(int /*<<< orphan*/ *,
                                        int /*<<< orphan*/, TYPE_1__ *);
int /*<<< orphan*/ XMoveResizeWindow(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                     int, int, int, int);
void place_center(Display *d, XEvent *e) {
  static XWindowAttributes r_wa;
  static XWindowAttributes c_wa;
  Window r = DefaultRootWindow(d);
  Window trans = None;
  XMapRequestEvent *ev = &e->xmaprequest;
  int x, y;
  if (!XGetWindowAttributes(d, r, &r_wa))
    return;
  if (!XGetWindowAttributes(d, ev->window, &c_wa))
    return;
  if (c_wa.override_redirect)
    return;
  if (XGetTransientForHint(d, ev->window, &trans))
    return;
  x = r_wa.width / 2 - c_wa.width / 2;
  y = r_wa.height / 2 - c_wa.height / 2;
  if (x < 0)
    x = 0;
  if (y < 0)
    y = 0;
  XMoveResizeWindow(d, ev->window, x, y,
                    c_wa.width > r_wa.width ? r_wa.width : c_wa.width,
                    c_wa.height > r_wa.height ? r_wa.height : c_wa.height);
}


x86 assembly (clang, -O0):
<place_center>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <DefaultRootWindow@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0x2eca(%rip),%rdx
call   1060 <XGetWindowAttributes@plt>
cmp    $0x0,%eax
jne    1191 <place_center+0x51>
jmp    12ed <place_center+0x1ad>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0x2eb6(%rip),%rdx
call   1060 <XGetWindowAttributes@plt>
cmp    $0x0,%eax
jne    11b5 <place_center+0x75>
jmp    12ed <place_center+0x1ad>
cmpq   $0x0,0x2ea3(%rip)
je     11c8 <place_center+0x88>
jmp    12ed <place_center+0x1ad>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1050 <XGetTransientForHint@plt>
cmp    $0x0,%rax
je     11ea <place_center+0xaa>
jmp    12ed <place_center+0x1ad>
mov    0x2e58(%rip),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x30(%rbp)
mov    0x2e57(%rip),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    0x2e33(%rip),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
mov    0x2e32(%rip),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    124d <place_center+0x10d>
movl   $0x0,-0x24(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    125e <place_center+0x11e>
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    0x2dd7(%rip),%eax
cmp    0x2dc1(%rip),%eax
jle    129b <place_center+0x15b>
mov    0x2db5(%rip),%eax
mov    %eax,-0x4c(%rbp)
jmp    12a4 <place_center+0x164>
mov    0x2db7(%rip),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    0x2dac(%rip),%eax
cmp    0x2d96(%rip),%eax
jle    12ca <place_center+0x18a>
mov    0x2d8a(%rip),%eax
mov    %eax,-0x54(%rbp)
jmp    12d3 <place_center+0x193>
mov    0x2d8c(%rip),%eax
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%r8d
mov    -0x34(%rbp),%ecx
mov    -0x38(%rbp),%edx
mov    -0x3c(%rbp),%esi
mov    -0x48(%rbp),%rdi
mov    -0x54(%rbp),%r9d
call   1040 <XMoveResizeWindow@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<place_center>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <DefaultRootWindow@plt>
mov    0x2e92(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x4(%rsp)
lea    0x2ee5(%rip),%rdx
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <XGetWindowAttributes@plt>
test   %eax,%eax
je     121d <place_center+0xdd>
mov    (%r14),%esi
lea    0x2ed9(%rip),%rdx
mov    %rbx,%rdi
call   1060 <XGetWindowAttributes@plt>
test   %eax,%eax
je     121d <place_center+0xdd>
cmpq   $0x0,0x2ec9(%rip)
jne    121d <place_center+0xdd>
mov    (%r14),%esi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <XGetTransientForHint@plt>
test   %rax,%rax
jne    121d <place_center+0xdd>
mov    0x2e90(%rip),%eax
mov    %eax,%edx
shr    $0x1f,%edx
add    %eax,%edx
sar    %edx
mov    0x2e90(%rip),%r8d
mov    %r8d,%ecx
shr    $0x1f,%ecx
add    %r8d,%ecx
sar    %ecx
sub    %ecx,%edx
mov    0x2e71(%rip),%edi
mov    %edi,%ecx
shr    $0x1f,%ecx
add    %edi,%ecx
sar    %ecx
mov    0x2e71(%rip),%r9d
mov    %r9d,%esi
shr    $0x1f,%esi
add    %r9d,%esi
sar    %esi
sub    %esi,%ecx
xor    %esi,%esi
test   %edx,%edx
cmovs  %esi,%edx
test   %ecx,%ecx
cmovs  %esi,%ecx
cmp    %eax,%r8d
cmovg  %eax,%r8d
mov    (%r14),%esi
cmp    %edi,%r9d
cmovg  %edi,%r9d
mov    %rbx,%rdi
call   1040 <XMoveResizeWindow@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.TYPE_6__ = type { i32, i32, i64 }
%struct.TYPE_8__ = type { %struct.TYPE_7__ }
%struct.TYPE_7__ = type { i32 }
@place_center.r_wa = internal global %struct.TYPE_6__ zeroinitializer
@place_center.c_wa = internal global %struct.TYPE_6__ zeroinitializer
@None = global i32 0
define void @place_center(i32* %0, %struct.TYPE_8__* %1) {
%3 = alloca i32*
%4 = alloca %struct.TYPE_8__*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.TYPE_7__*
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %3
store %struct.TYPE_8__* %1, %struct.TYPE_8__** %4
%10 = load i32*, i32** %3
%11 = call i32 @DefaultRootWindow(i32* %10)
store i32 %11, i32* %5
%12 = load i32, i32* @None
store i32 %12, i32* %6
%13 = load %struct.TYPE_8__*, %struct.TYPE_8__** %4
%14 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %13, i32 0, i32 0
store %struct.TYPE_7__* %14, %struct.TYPE_7__** %7
%15 = load i32*, i32** %3
%16 = load i32, i32* %5
%17 = call i32 @XGetWindowAttributes(i32* %15, i32 %16, %struct.TYPE_6__* @place_center.r_wa)
%18 = icmp ne i32 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %2
br label %84
20: ; preds = %2
%21 = load i32*, i32** %3
%22 = load %struct.TYPE_7__*, %struct.TYPE_7__** %7
%23 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @XGetWindowAttributes(i32* %21, i32 %24, %struct.TYPE_6__* @place_center.c_wa)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %20
br label %84
28: ; preds = %20
%29 = load i64, i64* getelementptr inbounds (%struct.TYPE_6__, %struct.TYPE_6__* @place_center.c_wa, i32 0, i32 2)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %28
br label %84
32: ; preds = %28
%33 = load i32*, i32** %3
%34 = load %struct.TYPE_7__*, %struct.TYPE_7__** %7
%35 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i64 @XGetTransientForHint(i32* %33, i32 %36, i32* %6)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %32
br label %84
40: ; preds = %32
%41 = load i32, i32* getelementptr inbounds (%struct.TYPE_6__, %struct.TYPE_6__* @place_center.r_wa, i32 0, i32 0)
%42 = sdiv i32 %41, 2
%43 = load i32, i32* getelementptr inbounds (%struct.TYPE_6__, %struct.TYPE_6__* @place_center.c_wa, i32 0, i32 0)
%44 = sdiv i32 %43, 2
%45 = sub nsw i32 %42, %44
store i32 %45, i32* %8
%46 = load i32, i32* getelementptr inbounds (%struct.TYPE_6__, %struct.TYPE_6__* @place_center.r_wa, i32 0, i32 1)
%47 = sdiv i32 %46, 2
%48 = load i32, i32* getelementptr inbounds (%struct.TYPE_6__, %struct.TYPE_6__* @place_center.c_wa, i32 0, i32 1)
%49 = sdiv i32 %48, 2
%50 = sub nsw i32 %47, %49
store i32 %50, i32* %9
%51 = load i32, i32* %8
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %40
store i32 0, i32* %8
br label %54
54: ; preds = %53, %40
%55 = load i32, i32* %9
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %54
store i32 0, i32* %9
br label %58
58: ; preds = %57, %54
%59 = load i32*, i32** %3
%60 = load %struct.TYPE_7__*, %struct.TYPE_7__** %7
%61 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %60, i32 0, i32 0
%62 = load i32, i32* %61
%63 = load i32, i32* %8
%64 = load i32, i32* %9
%65 = load i32, i32* getelementptr inbounds (%struct.TYPE_6__, %struct.TYPE_6__* @place_center.c_wa, i32 0, i32 0)
%66 = load i32, i32* getelementptr inbounds (%struct.TYPE_6__, %struct.TYPE_6__* @place_center.r_wa, i32 0, i32 0)
%67 = icmp sgt i32 %65, %66
br i1 %67, label %68, label %70
68: ; preds = %58
%69 = load i32, i32* getelementptr inbounds (%struct.TYPE_6__, %struct.TYPE_6__* @place_center.r_wa, i32 0, i32 0)
br label %72
70: ; preds = %58
%71 = load i32, i32* getelementptr inbounds (%struct.TYPE_6__, %struct.TYPE_6__* @place_center.c_wa, i32 0, i32 0)
br label %72
72: ; preds = %70, %68
%73 = phi i32 [ %69, %68 ], [ %71, %70 ]
%74 = load i32, i32* getelementptr inbounds (%struct.TYPE_6__, %struct.TYPE_6__* @place_center.c_wa, i32 0, i32 1)
%75 = load i32, i32* getelementptr inbounds (%struct.TYPE_6__, %struct.TYPE_6__* @place_center.r_wa, i32 0, i32 1)
%76 = icmp sgt i32 %74, %75
br i1 %76, label %77, label %79
77: ; preds = %72
%78 = load i32, i32* getelementptr inbounds (%struct.TYPE_6__, %struct.TYPE_6__* @place_center.r_wa, i32 0, i32 1)
br label %81
79: ; preds = %72
%80 = load i32, i32* getelementptr inbounds (%struct.TYPE_6__, %struct.TYPE_6__* @place_center.c_wa, i32 0, i32 1)
br label %81
81: ; preds = %79, %77
%82 = phi i32 [ %78, %77 ], [ %80, %79 ]
%83 = call i32 @XMoveResizeWindow(i32* %59, i32 %62, i32 %63, i32 %64, i32 %73, i32 %82)
br label %84
84: ; preds = %81, %39, %31, %27, %19
ret void
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i32, i32, i64 }
%struct.TYPE_8__ = type { %struct.TYPE_7__ }
%struct.TYPE_7__ = type { i32 }
@place_center.r_wa = internal global %struct.TYPE_6__ zeroinitializer
@place_center.c_wa = internal global %struct.TYPE_6__ zeroinitializer
@None = global i32 0
define void @place_center(i32* %0, %struct.TYPE_8__* nocapture %1) {
%3 = alloca i32
%4 = tail call i32 @DefaultRootWindow(i32* %0)
%5 = bitcast i32* %3 to i8*
%6 = load i32, i32* @None
store i32 %6, i32* %3
%7 = tail call i32 @XGetWindowAttributes(i32* %0, i32 %4, %struct.TYPE_6__* @place_center.r_wa)
%8 = icmp eq i32 %7, 0
br i1 %8, label %42, label %9
9: ; preds = %2
%10 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %1, i64 0, i32 0, i32 0
%11 = load i32, i32* %10
%12 = tail call i32 @XGetWindowAttributes(i32* %0, i32 %11, %struct.TYPE_6__* @place_center.c_wa)
%13 = icmp ne i32 %12, 0
%14 = load i64, i64* getelementptr inbounds (%struct.TYPE_6__, %struct.TYPE_6__* @place_center.c_wa, i64 0, i32 2)
%15 = icmp eq i64 %14, 0
%16 = select i1 %13, i1 %15, i1 false
br i1 %16, label %17, label %42
17: ; preds = %9
%18 = load i32, i32* %10
%19 = call i64 @XGetTransientForHint(i32* %0, i32 %18, i32* %3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %42
21: ; preds = %17
%22 = load i32, i32* getelementptr inbounds (%struct.TYPE_6__, %struct.TYPE_6__* @place_center.r_wa, i64 0, i32 0)
%23 = sdiv i32 %22, 2
%24 = load i32, i32* getelementptr inbounds (%struct.TYPE_6__, %struct.TYPE_6__* @place_center.c_wa, i64 0, i32 0)
%25 = sdiv i32 %24, -2
%26 = add nsw i32 %25, %23
%27 = load i32, i32* getelementptr inbounds (%struct.TYPE_6__, %struct.TYPE_6__* @place_center.r_wa, i64 0, i32 1)
%28 = sdiv i32 %27, 2
%29 = load i32, i32* getelementptr inbounds (%struct.TYPE_6__, %struct.TYPE_6__* @place_center.c_wa, i64 0, i32 1)
%30 = sdiv i32 %29, -2
%31 = add nsw i32 %30, %28
%32 = icmp sgt i32 %26, 0
%33 = select i1 %32, i32 %26, i32 0
%34 = icmp sgt i32 %31, 0
%35 = select i1 %34, i32 %31, i32 0
%36 = load i32, i32* %10
%37 = icmp sgt i32 %24, %22
%38 = select i1 %37, i32 %22, i32 %24
%39 = icmp sgt i32 %29, %27
%40 = select i1 %39, i32 %27, i32 %29
%41 = call i32 @XMoveResizeWindow(i32* %0, i32 %36, i32 %33, i32 %35, i32 %38, i32 %40)
br label %42
42: ; preds = %17, %9, %2, %21
ret void
}