#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*/ Widget;
typedef int Position;
typedef int Dimension;

/* Variables and functions */
int HeightOfScreen(int /*<<< orphan*/);
int WidthOfScreen(int /*<<< orphan*/);
int /*<<< orphan*/ XtNborderWidth;
int /*<<< orphan*/ XtNheight;
int /*<<< orphan*/ XtNwidth;
int /*<<< orphan*/ XtNwinGravity;
int /*<<< orphan*/ XtNx;
int /*<<< orphan*/ XtNy;
int /*<<< orphan*/ XtScreen(int /*<<< orphan*/);
int /*<<< orphan*/ XtVaGetValues(int /*<<< orphan*/, int /*<<< orphan*/, int *,
                                 int /*<<< orphan*/, int *, int /*<<< orphan*/,
                                 int *, int /*<<< orphan*/ *);
int /*<<< orphan*/ XtVaSetValues(int /*<<< orphan*/, int /*<<< orphan*/, int,
                                 int /*<<< orphan*/, int, int /*<<< orphan*/,
                                 int, int /*<<< orphan*/ *);
void position_near(Widget shell, int x, int y) {
  int max_x, max_y;
  Dimension width, height, border;
  int gravity;
  XtVaGetValues(shell, XtNwidth, &width, XtNheight, &height, XtNborderWidth,
                &border, NULL);
  width += 2 * border;
  height += 2 * border;
  max_x = WidthOfScreen(XtScreen(shell));
  max_y = HeightOfScreen(XtScreen(shell));
  gravity = 1;
  if (x > max_x / 3)
    gravity += 1;
  if (x > max_x * 2 / 3)
    gravity += 1;
  if (y > max_y / 3)
    gravity += 3;
  if (y > max_y * 2 / 3)
    gravity += 3;
  max_x -= width;
  max_y -= height;
  x -= ((Position)width / 2);
  if (x < 0)
    x = 0;
  if (x > max_x)
    x = max_x;
  y -= ((Position)height / 2);
  if (y < 0)
    y = 0;
  if (y > max_y)
    y = max_y;
  XtVaSetValues(shell, XtNx, (Position)x, XtNy, (Position)y, XtNwinGravity,
                gravity, NULL);
}


x86 assembly (clang, -O0):
<position_near>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
mov    0x2e3c(%rip),%rax
mov    (%rax),%ecx
mov    0x2e63(%rip),%rax
mov    (%rax),%r9d
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%r8
lea    -0x20(%rbp),%rax
xor    %r10d,%r10d
mov    %rax,(%rsp)
movq   $0x0,0x8(%rsp)
call   1060 <XtVaGetValues@plt>
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <XtScreen@plt>
mov    %eax,%edi
call   1050 <WidthOfScreen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <XtScreen@plt>
mov    %eax,%edi
call   1070 <HeightOfScreen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jle    120b <position_near+0xbb>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jle    1235 <position_near+0xe5>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
jle    125c <position_near+0x10c>
mov    -0x24(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jle    1286 <position_near+0x136>
mov    -0x24(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x8(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    12c2 <position_near+0x172>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    12d4 <position_near+0x184>
mov    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    12fa <position_near+0x1aa>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    130c <position_near+0x1bc>
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2cda(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    0x2ca6(%rip),%rax
mov    (%rax),%ecx
mov    -0xc(%rbp),%r8d
mov    0x2ca9(%rip),%rax
mov    (%rax),%r9d
mov    -0x24(%rbp),%eax
xor    %r10d,%r10d
mov    %eax,(%rsp)
movq   $0x0,0x8(%rsp)
call   1030 <XtVaSetValues@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<position_near>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r12d
mov    %esi,%ebp
mov    %edi,%r14d
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
mov    0x2e3c(%rip),%rax
mov    (%rax),%ecx
mov    0x2e63(%rip),%rax
mov    (%rax),%r9d
lea    0xc(%rsp),%rax
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%r8
push   $0x0
push   %rax
call   1060 <XtVaGetValues@plt>
add    $0x10,%rsp
mov    0xc(%rsp),%eax
add    %eax,%eax
add    %eax,0x8(%rsp)
add    %eax,0x4(%rsp)
mov    %r14d,%edi
call   1040 <XtScreen@plt>
mov    %eax,%edi
call   1050 <WidthOfScreen@plt>
mov    %eax,%r15d
mov    %r14d,%edi
call   1040 <XtScreen@plt>
mov    %eax,%edi
call   1070 <HeightOfScreen@plt>
movslq %r15d,%rcx
imul   $0x55555556,%rcx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
shr    $0x20,%rdx
add    %esi,%edx
xor    %esi,%esi
cmp    %ebp,%edx
setl   %sil
lea    (%rcx,%rcx,1),%edx
movslq %edx,%rdx
imul   $0x55555556,%rdx,%rdx
mov    %rdx,%rdi
shr    $0x3f,%rdi
shr    $0x20,%rdx
add    %edi,%edx
xor    %edi,%edi
cmp    %ebp,%edx
setl   %dil
add    %esi,%edi
cltq
imul   $0x55555556,%rax,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
shr    $0x20,%rdx
add    %esi,%edx
xor    %esi,%esi
cmp    %r12d,%edx
setl   %sil
lea    (%rsi,%rsi,2),%r8d
add    %edi,%r8d
lea    (%rax,%rax,1),%esi
movslq %esi,%rsi
imul   $0x55555556,%rsi,%rsi
mov    %rsi,%rdi
shr    $0x3f,%rdi
shr    $0x20,%rsi
add    %edi,%esi
xor    %edi,%edi
cmp    %r12d,%esi
setl   %dil
mov    0x8(%rsp),%edx
sub    %edx,%ecx
mov    0x4(%rsp),%ebx
sub    %ebx,%eax
mov    %edx,%esi
shr    $0x1f,%esi
add    %edx,%esi
sar    %esi
xor    %edx,%edx
sub    %esi,%ebp
cmovs  %edx,%ebp
lea    (%rdi,%rdi,2),%esi
cmp    %ecx,%ebp
cmovg  %ecx,%ebp
lea    (%rsi,%r8,1),%r10d
add    $0x1,%r10d
mov    %ebx,%ecx
shr    $0x1f,%ecx
add    %ebx,%ecx
sar    %ecx
sub    %ecx,%r12d
cmovs  %edx,%r12d
cmp    %eax,%r12d
cmovg  %eax,%r12d
mov    0x2d50(%rip),%rax
mov    (%rax),%esi
mov    0x2d1f(%rip),%rax
mov    (%rax),%ecx
mov    0x2d26(%rip),%rax
mov    (%rax),%r9d
mov    %r14d,%edi
mov    %ebp,%edx
mov    %r12d,%r8d
push   $0x0
push   %r10
call   1030 <XtVaSetValues@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@XtNwidth = global i32 0
@XtNheight = global i32 0
@XtNborderWidth = global i32 0
@XtNx = global i32 0
@XtNy = global i32 0
@XtNwinGravity = global i32 0
define void @position_near(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%13 = load i32, i32* %4
%14 = load i32, i32* @XtNwidth
%15 = load i32, i32* @XtNheight
%16 = load i32, i32* @XtNborderWidth
%17 = call i32 @XtVaGetValues(i32 %13, i32 %14, i32* %9, i32 %15, i32* %10, i32 %16, i32* %11, i32* null)
%18 = load i32, i32* %11
%19 = mul nsw i32 2, %18
%20 = load i32, i32* %9
%21 = add nsw i32 %20, %19
store i32 %21, i32* %9
%22 = load i32, i32* %11
%23 = mul nsw i32 2, %22
%24 = load i32, i32* %10
%25 = add nsw i32 %24, %23
store i32 %25, i32* %10
%26 = load i32, i32* %4
%27 = call i32 @XtScreen(i32 %26)
%28 = call i32 @WidthOfScreen(i32 %27)
store i32 %28, i32* %7
%29 = load i32, i32* %4
%30 = call i32 @XtScreen(i32 %29)
%31 = call i32 @HeightOfScreen(i32 %30)
store i32 %31, i32* %8
store i32 1, i32* %12
%32 = load i32, i32* %5
%33 = load i32, i32* %7
%34 = sdiv i32 %33, 3
%35 = icmp sgt i32 %32, %34
br i1 %35, label %36, label %39
36: ; preds = %3
%37 = load i32, i32* %12
%38 = add nsw i32 %37, 1
store i32 %38, i32* %12
br label %39
39: ; preds = %36, %3
%40 = load i32, i32* %5
%41 = load i32, i32* %7
%42 = mul nsw i32 %41, 2
%43 = sdiv i32 %42, 3
%44 = icmp sgt i32 %40, %43
br i1 %44, label %45, label %48
45: ; preds = %39
%46 = load i32, i32* %12
%47 = add nsw i32 %46, 1
store i32 %47, i32* %12
br label %48
48: ; preds = %45, %39
%49 = load i32, i32* %6
%50 = load i32, i32* %8
%51 = sdiv i32 %50, 3
%52 = icmp sgt i32 %49, %51
br i1 %52, label %53, label %56
53: ; preds = %48
%54 = load i32, i32* %12
%55 = add nsw i32 %54, 3
store i32 %55, i32* %12
br label %56
56: ; preds = %53, %48
%57 = load i32, i32* %6
%58 = load i32, i32* %8
%59 = mul nsw i32 %58, 2
%60 = sdiv i32 %59, 3
%61 = icmp sgt i32 %57, %60
br i1 %61, label %62, label %65
62: ; preds = %56
%63 = load i32, i32* %12
%64 = add nsw i32 %63, 3
store i32 %64, i32* %12
br label %65
65: ; preds = %62, %56
%66 = load i32, i32* %9
%67 = load i32, i32* %7
%68 = sub nsw i32 %67, %66
store i32 %68, i32* %7
%69 = load i32, i32* %10
%70 = load i32, i32* %8
%71 = sub nsw i32 %70, %69
store i32 %71, i32* %8
%72 = load i32, i32* %9
%73 = sdiv i32 %72, 2
%74 = load i32, i32* %5
%75 = sub nsw i32 %74, %73
store i32 %75, i32* %5
%76 = load i32, i32* %5
%77 = icmp slt i32 %76, 0
br i1 %77, label %78, label %79
78: ; preds = %65
store i32 0, i32* %5
br label %79
79: ; preds = %78, %65
%80 = load i32, i32* %5
%81 = load i32, i32* %7
%82 = icmp sgt i32 %80, %81
br i1 %82, label %83, label %85
83: ; preds = %79
%84 = load i32, i32* %7
store i32 %84, i32* %5
br label %85
85: ; preds = %83, %79
%86 = load i32, i32* %10
%87 = sdiv i32 %86, 2
%88 = load i32, i32* %6
%89 = sub nsw i32 %88, %87
store i32 %89, i32* %6
%90 = load i32, i32* %6
%91 = icmp slt i32 %90, 0
br i1 %91, label %92, label %93
92: ; preds = %85
store i32 0, i32* %6
br label %93
93: ; preds = %92, %85
%94 = load i32, i32* %6
%95 = load i32, i32* %8
%96 = icmp sgt i32 %94, %95
br i1 %96, label %97, label %99
97: ; preds = %93
%98 = load i32, i32* %8
store i32 %98, i32* %6
br label %99
99: ; preds = %97, %93
%100 = load i32, i32* %4
%101 = load i32, i32* @XtNx
%102 = load i32, i32* %5
%103 = load i32, i32* @XtNy
%104 = load i32, i32* %6
%105 = load i32, i32* @XtNwinGravity
%106 = load i32, i32* %12
%107 = call i32 @XtVaSetValues(i32 %100, i32 %101, i32 %102, i32 %103, i32 %104, i32 %105, i32 %106, i32* null)
ret void
}

LLVM IR (-O2):
@XtNwidth = global i32 0
@XtNheight = global i32 0
@XtNborderWidth = global i32 0
@XtNx = global i32 0
@XtNy = global i32 0
@XtNwinGravity = global i32 0
define void @position_near(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = bitcast i32* %6 to i8*
%10 = load i32, i32* @XtNwidth
%11 = load i32, i32* @XtNheight
%12 = load i32, i32* @XtNborderWidth
%13 = call i32 @XtVaGetValues(i32 %0, i32 %10, i32* %4, i32 %11, i32* %5, i32 %12, i32* %6, i32* null)
%14 = load i32, i32* %6
%15 = shl nsw i32 %14, 1
%16 = load i32, i32* %4
%17 = add nsw i32 %16, %15
store i32 %17, i32* %4
%18 = load i32, i32* %5
%19 = add nsw i32 %18, %15
store i32 %19, i32* %5
%20 = call i32 @XtScreen(i32 %0)
%21 = call i32 @WidthOfScreen(i32 %20)
%22 = call i32 @XtScreen(i32 %0)
%23 = call i32 @HeightOfScreen(i32 %22)
%24 = sdiv i32 %21, 3
%25 = icmp slt i32 %24, %1
%26 = select i1 %25, i32 2, i32 1
%27 = shl nsw i32 %21, 1
%28 = sdiv i32 %27, 3
%29 = icmp slt i32 %28, %1
%30 = zext i1 %29 to i32
%31 = add nuw nsw i32 %26, %30
%32 = sdiv i32 %23, 3
%33 = icmp slt i32 %32, %2
%34 = add nuw nsw i32 %31, 3
%35 = select i1 %33, i32 %34, i32 %31
%36 = shl nsw i32 %23, 1
%37 = sdiv i32 %36, 3
%38 = icmp slt i32 %37, %2
%39 = add nuw nsw i32 %35, 3
%40 = select i1 %38, i32 %39, i32 %35
%41 = load i32, i32* %4
%42 = sub nsw i32 %21, %41
%43 = load i32, i32* %5
%44 = sub nsw i32 %23, %43
%45 = sdiv i32 %41, -2
%46 = add i32 %45, %1
%47 = icmp sgt i32 %46, 0
%48 = select i1 %47, i32 %46, i32 0
%49 = icmp sgt i32 %48, %42
%50 = select i1 %49, i32 %42, i32 %48
%51 = sdiv i32 %43, -2
%52 = add i32 %51, %2
%53 = icmp sgt i32 %52, 0
%54 = select i1 %53, i32 %52, i32 0
%55 = icmp sgt i32 %54, %44
%56 = select i1 %55, i32 %44, i32 %54
%57 = load i32, i32* @XtNx
%58 = load i32, i32* @XtNy
%59 = load i32, i32* @XtNwinGravity
%60 = call i32 @XtVaSetValues(i32 %0, i32 %57, i32 %50, i32 %58, i32 %56, i32 %59, i32 %40, i32* null)
ret void
}