#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__ {
  scalar_t__ map_state;
};
typedef TYPE_1__ XWindowAttributes;
typedef int /*<<< orphan*/ Widget;
typedef int Position;
typedef int Dimension;
typedef size_t Cardinal;
typedef int Boolean;
typedef int Bool;
typedef int /*<<< orphan*/ Arg;

/* Variables and functions */
int False;
scalar_t__ IsViewable;
scalar_t__ XGetWindowAttributes(int /*<<< orphan*/, int /*<<< orphan*/,
                                TYPE_1__ *);
int /*<<< orphan*/ XtDisplay(int /*<<< orphan*/);
int /*<<< orphan*/ XtGetValues(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               size_t);
scalar_t__ XtIsManaged(int /*<<< orphan*/);
int /*<<< orphan*/ XtIsRectObj(int /*<<< orphan*/);
scalar_t__ XtIsWidget(int /*<<< orphan*/);
int /*<<< orphan*/ XtNborderWidth;
int /*<<< orphan*/ XtNheight;
int /*<<< orphan*/ XtNmappedWhenManaged;
int /*<<< orphan*/ XtNwidth;
int /*<<< orphan*/ XtNx;
int /*<<< orphan*/ XtNy;
int /*<<< orphan*/ XtSetArg(int /*<<< orphan*/, int /*<<< orphan*/, int *);
int /*<<< orphan*/ XtWindow(int /*<<< orphan*/);
Bool PositionInChild(Widget child, int x, int y) {
  Arg args[6];
  Cardinal num;
  Dimension width, height, border_width;
  Position child_x, child_y;
  Boolean mapped_when_managed;
  if (!XtIsRectObj(child))
    return (False);
  num = 0;
  XtSetArg(args[num], XtNmappedWhenManaged, &mapped_when_managed);
  num++;
  XtSetArg(args[num], XtNwidth, &width);
  num++;
  XtSetArg(args[num], XtNheight, &height);
  num++;
  XtSetArg(args[num], XtNx, &child_x);
  num++;
  XtSetArg(args[num], XtNy, &child_y);
  num++;
  XtSetArg(args[num], XtNborderWidth, &border_width);
  num++;
  XtGetValues(child, args, num);
  if (XtIsWidget(child) && !(mapped_when_managed && XtIsManaged(child))) {
    XWindowAttributes attrs;
    if (XGetWindowAttributes(XtDisplay(child), XtWindow(child), &attrs) &&
        attrs.map_state != IsViewable)
      return (False);
  }
  return ((x >= child_x) &&
          (x <= (child_x + (Position)width + 2 * (Position)border_width)) &&
          (y >= child_y) &&
          (y <= (child_y + (Position)height + 2 * (Position)border_width)));
}


x86 assembly (clang, -O0):
<PositionInChild>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <XtIsRectObj@plt>
cmp    $0x0,%eax
jne    11b3 <PositionInChild+0x33>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1396 <PositionInChild+0x216>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdx
call   1050 <XtSetArg@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edi
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
lea    -0x3c(%rbp),%rdx
call   1050 <XtSetArg@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edi
mov    0x2d8a(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   1050 <XtSetArg@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edi
mov    0x2db4(%rip),%rax
mov    (%rax),%esi
lea    -0x48(%rbp),%rdx
call   1050 <XtSetArg@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edi
mov    0x2d5e(%rip),%rax
mov    (%rax),%esi
lea    -0x4c(%rbp),%rdx
call   1050 <XtSetArg@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edi
mov    0x2d50(%rip),%rax
mov    (%rax),%esi
lea    -0x44(%rbp),%rdx
call   1050 <XtSetArg@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1030 <XtGetValues@plt>
mov    -0x8(%rbp),%edi
call   10a0 <XtIsWidget@plt>
cmp    $0x0,%rax
je     1332 <PositionInChild+0x1b2>
cmpl   $0x0,-0x50(%rbp)
je     12dd <PositionInChild+0x15d>
mov    -0x8(%rbp),%edi
call   1080 <XtIsManaged@plt>
cmp    $0x0,%rax
jne    1332 <PositionInChild+0x1b2>
mov    -0x8(%rbp),%edi
call   1070 <XtDisplay@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <XtWindow@plt>
mov    -0x5c(%rbp),%edi
mov    %eax,%esi
lea    -0x58(%rbp),%rdx
call   1090 <XGetWindowAttributes@plt>
cmp    $0x0,%rax
je     132d <PositionInChild+0x1ad>
mov    -0x58(%rbp),%rax
mov    0x2c9d(%rip),%rcx
cmp    (%rcx),%rax
je     132d <PositionInChild+0x1ad>
mov    0x2cbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1396 <PositionInChild+0x216>
jmp    1332 <PositionInChild+0x1b2>
mov    -0xc(%rbp),%ecx
xor    %eax,%eax
cmp    -0x48(%rbp),%ecx
mov    %al,-0x5d(%rbp)
jl     138b <PositionInChild+0x20b>
mov    -0xc(%rbp),%ecx
mov    -0x48(%rbp),%edx
add    -0x3c(%rbp),%edx
mov    -0x44(%rbp),%eax
shl    $0x1,%eax
add    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x5d(%rbp)
jg     138b <PositionInChild+0x20b>
mov    -0x10(%rbp),%ecx
xor    %eax,%eax
cmp    -0x4c(%rbp),%ecx
mov    %al,-0x5d(%rbp)
jl     138b <PositionInChild+0x20b>
mov    -0x10(%rbp),%eax
mov    -0x4c(%rbp),%ecx
add    -0x40(%rbp),%ecx
mov    -0x44(%rbp),%edx
shl    $0x1,%edx
add    %edx,%ecx
cmp    %ecx,%eax
setle  %al
mov    %al,-0x5d(%rbp)
mov    -0x5d(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PositionInChild>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%ebx
call   1060 <XtIsRectObj@plt>
test   %eax,%eax
je     12a8 <PositionInChild+0x128>
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1050 <XtSetArg@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
lea    0x14(%rsp),%rdx
call   1050 <XtSetArg@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
call   1050 <XtSetArg@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1050 <XtSetArg@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
call   1050 <XtSetArg@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
call   1050 <XtSetArg@plt>
lea    0x20(%rsp),%rsi
mov    $0x6,%edx
mov    %ebx,%edi
call   1030 <XtGetValues@plt>
mov    %ebx,%edi
call   10a0 <XtIsWidget@plt>
test   %rax,%rax
je     1272 <PositionInChild+0xf2>
cmpl   $0x0,(%rsp)
je     123e <PositionInChild+0xbe>
mov    %ebx,%edi
call   1080 <XtIsManaged@plt>
test   %rax,%rax
jne    1272 <PositionInChild+0xf2>
mov    %ebx,%edi
call   1070 <XtDisplay@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1040 <XtWindow@plt>
lea    0x18(%rsp),%rdx
mov    %ebp,%edi
mov    %eax,%esi
call   1090 <XGetWindowAttributes@plt>
test   %rax,%rax
je     1272 <PositionInChild+0xf2>
mov    0x18(%rsp),%rax
mov    0x2d43(%rip),%rcx
cmp    (%rcx),%rax
jne    12a8 <PositionInChild+0x128>
mov    0x8(%rsp),%edx
xor    %eax,%eax
cmp    %r15d,%edx
jg     12b1 <PositionInChild+0x131>
add    0x14(%rsp),%edx
mov    0xc(%rsp),%ecx
lea    (%rdx,%rcx,2),%edx
cmp    %r15d,%edx
jl     12b1 <PositionInChild+0x131>
mov    0x4(%rsp),%edx
cmp    %r14d,%edx
jg     12b1 <PositionInChild+0x131>
add    %ecx,%ecx
add    %ecx,%edx
add    0x10(%rsp),%edx
xor    %eax,%eax
cmp    %r14d,%edx
setge  %al
jmp    12b1 <PositionInChild+0x131>
mov    0x2d31(%rip),%rax
mov    (%rax),%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64 }
@False = global i32 0
@XtNmappedWhenManaged = global i32 0
@XtNwidth = global i32 0
@XtNheight = global i32 0
@XtNx = global i32 0
@XtNy = global i32 0
@XtNborderWidth = global i32 0
@IsViewable = global i64 0
define i32 @PositionInChild(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [6 x i32]
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca %struct.TYPE_3__
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%17 = load i32, i32* %5
%18 = call i32 @XtIsRectObj(i32 %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %3
%21 = load i32, i32* @False
store i32 %21, i32* %4
br label %123
22: ; preds = %3
store i64 0, i64* %9
%23 = load i64, i64* %9
%24 = getelementptr inbounds [6 x i32], [6 x i32]* %8, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = load i32, i32* @XtNmappedWhenManaged
%27 = call i32 @XtSetArg(i32 %25, i32 %26, i32* %15)
%28 = load i64, i64* %9
%29 = add i64 %28, 1
store i64 %29, i64* %9
%30 = load i64, i64* %9
%31 = getelementptr inbounds [6 x i32], [6 x i32]* %8, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = load i32, i32* @XtNwidth
%34 = call i32 @XtSetArg(i32 %32, i32 %33, i32* %10)
%35 = load i64, i64* %9
%36 = add i64 %35, 1
store i64 %36, i64* %9
%37 = load i64, i64* %9
%38 = getelementptr inbounds [6 x i32], [6 x i32]* %8, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = load i32, i32* @XtNheight
%41 = call i32 @XtSetArg(i32 %39, i32 %40, i32* %11)
%42 = load i64, i64* %9
%43 = add i64 %42, 1
store i64 %43, i64* %9
%44 = load i64, i64* %9
%45 = getelementptr inbounds [6 x i32], [6 x i32]* %8, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = load i32, i32* @XtNx
%48 = call i32 @XtSetArg(i32 %46, i32 %47, i32* %13)
%49 = load i64, i64* %9
%50 = add i64 %49, 1
store i64 %50, i64* %9
%51 = load i64, i64* %9
%52 = getelementptr inbounds [6 x i32], [6 x i32]* %8, i64 0, i64 %51
%53 = load i32, i32* %52
%54 = load i32, i32* @XtNy
%55 = call i32 @XtSetArg(i32 %53, i32 %54, i32* %14)
%56 = load i64, i64* %9
%57 = add i64 %56, 1
store i64 %57, i64* %9
%58 = load i64, i64* %9
%59 = getelementptr inbounds [6 x i32], [6 x i32]* %8, i64 0, i64 %58
%60 = load i32, i32* %59
%61 = load i32, i32* @XtNborderWidth
%62 = call i32 @XtSetArg(i32 %60, i32 %61, i32* %12)
%63 = load i64, i64* %9
%64 = add i64 %63, 1
store i64 %64, i64* %9
%65 = load i32, i32* %5
%66 = getelementptr inbounds [6 x i32], [6 x i32]* %8, i64 0, i64 0
%67 = load i64, i64* %9
%68 = call i32 @XtGetValues(i32 %65, i32* %66, i64 %67)
%69 = load i32, i32* %5
%70 = call i64 @XtIsWidget(i32 %69)
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %94
72: ; preds = %22
%73 = load i32, i32* %15
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %79
75: ; preds = %72
%76 = load i32, i32* %5
%77 = call i64 @XtIsManaged(i32 %76)
%78 = icmp ne i64 %77, 0
br i1 %78, label %94, label %79
79: ; preds = %75, %72
%80 = load i32, i32* %5
%81 = call i32 @XtDisplay(i32 %80)
%82 = load i32, i32* %5
%83 = call i32 @XtWindow(i32 %82)
%84 = call i64 @XGetWindowAttributes(i32 %81, i32 %83, %struct.TYPE_3__* %16)
%85 = icmp ne i64 %84, 0
br i1 %85, label %86, label %93
86: ; preds = %79
%87 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %16, i32 0, i32 0
%88 = load i64, i64* %87
%89 = load i64, i64* @IsViewable
%90 = icmp ne i64 %88, %89
br i1 %90, label %91, label %93
91: ; preds = %86
%92 = load i32, i32* @False
store i32 %92, i32* %4
br label %123
93: ; preds = %86, %79
br label %94
94: ; preds = %93, %75, %22
%95 = load i32, i32* %6
%96 = load i32, i32* %13
%97 = icmp sge i32 %95, %96
br i1 %97, label %98, label %120
98: ; preds = %94
%99 = load i32, i32* %6
%100 = load i32, i32* %13
%101 = load i32, i32* %10
%102 = add nsw i32 %100, %101
%103 = load i32, i32* %12
%104 = mul nsw i32 2, %103
%105 = add nsw i32 %102, %104
%106 = icmp sle i32 %99, %105
br i1 %106, label %107, label %120
107: ; preds = %98
%108 = load i32, i32* %7
%109 = load i32, i32* %14
%110 = icmp sge i32 %108, %109
br i1 %110, label %111, label %120
111: ; preds = %107
%112 = load i32, i32* %7
%113 = load i32, i32* %14
%114 = load i32, i32* %11
%115 = add nsw i32 %113, %114
%116 = load i32, i32* %12
%117 = mul nsw i32 2, %116
%118 = add nsw i32 %115, %117
%119 = icmp sle i32 %112, %118
br label %120
120: ; preds = %111, %107, %98, %94
%121 = phi i1 [ false, %107 ], [ false, %98 ], [ false, %94 ], [ %119, %111 ]
%122 = zext i1 %121 to i32
store i32 %122, i32* %4
br label %123
123: ; preds = %120, %91, %20
%124 = load i32, i32* %4
ret i32 %124
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64 }
@False = global i32 0
@XtNmappedWhenManaged = global i32 0
@XtNwidth = global i32 0
@XtNheight = global i32 0
@XtNx = global i32 0
@XtNy = global i32 0
@XtNborderWidth = global i32 0
@IsViewable = global i64 0
define i32 @PositionInChild(i32 %0, i32 %1, i32 %2) {
%4 = alloca [6 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.TYPE_3__
%12 = bitcast [6 x i32]* %4 to i8*
%13 = bitcast i32* %5 to i8*
%14 = bitcast i32* %6 to i8*
%15 = bitcast i32* %7 to i8*
%16 = bitcast i32* %8 to i8*
%17 = bitcast i32* %9 to i8*
%18 = bitcast i32* %10 to i8*
%19 = tail call i32 @XtIsRectObj(i32 %0)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %3
%22 = load i32, i32* @False
br label %78
23: ; preds = %3
%24 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 0
%25 = load i32, i32* @XtNmappedWhenManaged
%26 = call i32 @XtSetArg(i32 undef, i32 %25, i32* %10)
%27 = load i32, i32* @XtNwidth
%28 = call i32 @XtSetArg(i32 undef, i32 %27, i32* %5)
%29 = load i32, i32* @XtNheight
%30 = call i32 @XtSetArg(i32 undef, i32 %29, i32* %6)
%31 = load i32, i32* @XtNx
%32 = call i32 @XtSetArg(i32 undef, i32 %31, i32* %8)
%33 = load i32, i32* @XtNy
%34 = call i32 @XtSetArg(i32 undef, i32 %33, i32* %9)
%35 = load i32, i32* @XtNborderWidth
%36 = call i32 @XtSetArg(i32 undef, i32 %35, i32* %7)
%37 = call i32 @XtGetValues(i32 %0, i32* %24, i64 6)
%38 = call i64 @XtIsWidget(i32 %0)
%39 = icmp eq i64 %38, 0
br i1 %39, label %59, label %40
40: ; preds = %23
%41 = load i32, i32* %10
%42 = icmp eq i32 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %40
%44 = call i64 @XtIsManaged(i32 %0)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %59
46: ; preds = %43, %40
%47 = bitcast %struct.TYPE_3__* %11 to i8*
%48 = call i32 @XtDisplay(i32 %0)
%49 = call i32 @XtWindow(i32 %0)
%50 = call i64 @XGetWindowAttributes(i32 %48, i32 %49, %struct.TYPE_3__* %11)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %46
br label %59
53: ; preds = %46
%54 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i64 0, i32 0
%55 = load i64, i64* %54
%56 = load i64, i64* @IsViewable
%57 = icmp eq i64 %55, %56
%58 = load i32, i32* @False
br i1 %57, label %59, label %78
59: ; preds = %52, %53, %43, %23
%60 = load i32, i32* %8
%61 = icmp sgt i32 %60, %1
br i1 %61, label %78, label %62
62: ; preds = %59
%63 = load i32, i32* %5
%64 = add nsw i32 %63, %60
%65 = load i32, i32* %7
%66 = shl nsw i32 %65, 1
%67 = add nsw i32 %64, %66
%68 = icmp slt i32 %67, %1
br i1 %68, label %78, label %69
69: ; preds = %62
%70 = load i32, i32* %9
%71 = icmp sgt i32 %70, %2
br i1 %71, label %78, label %72
72: ; preds = %69
%73 = load i32, i32* %6
%74 = add i32 %70, %66
%75 = add i32 %74, %73
%76 = icmp sge i32 %75, %2
%77 = zext i1 %76 to i32
br label %78
78: ; preds = %59, %62, %69, %72, %53, %21
%79 = phi i32 [ %58, %53 ], [ %22, %21 ], [ 0, %69 ], [ 0, %62 ], [ 0, %59 ], [ %77, %72 ]
ret i32 %79
}