#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 */
struct tsdev {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ getxy_validate(struct tsdev *, int *, int *);
int /*<<< orphan*/ printf(char *, char *, int, int, int, int, char *);
int /*<<< orphan*/ put_cross(int, int, int);
int /*<<< orphan*/ usleep(int);
int validate_sample(struct tsdev *ts, int x, int y, char *name, int boundary) {
  static int last_x = -1, last_y;
  int read_x, read_y;
  int ret;
  if (last_x != -1) {
    int dx = ((x - last_x) << 16) / 10;
    int dy = ((y - last_y) << 16) / 10;
    int i;
    last_x <<= 16;
    last_y <<= 16;
    for (i = 0; i < 10; i++) {
      put_cross(last_x >> 16, last_y >> 16, 2 | 0x80000000);
      usleep(1000);
      put_cross(last_x >> 16, last_y >> 16, 2 | 0x80000000);
      last_x += dx;
      last_y += dy;
    }
  }
  put_cross(x, y, 2 | 0x80000000);
  getxy_validate(ts, &read_x, &read_y);
  if ((read_x > x - boundary) && (read_x < x + boundary) &&
      (read_y > y - boundary) && (read_y < y + boundary)) {
    ret = 0;
  } else {
    ret = -1;
  }
  put_cross(x, y, 2 | 0x80000000);
  last_x = x;
  last_y = y;
  printf("%s : X = %4d(%4d) Y = %4d(%4d) %s\n", name, read_x, x, read_y, y,
         ret ? "fail" : "pass");
  return ret;
}


x86 assembly (clang, -O0):
<validate_sample>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
cmpl   $0xffffffff,0x2edf(%rip)
je     1237 <validate_sample+0xf7>
mov    -0xc(%rbp),%eax
sub    0x2ed0(%rip),%eax
shl    $0x10,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%eax
sub    0x2ec1(%rip),%eax
shl    $0x10,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x30(%rbp)
mov    0x2ea5(%rip),%eax
shl    $0x10,%eax
mov    %eax,0x2e9c(%rip)
mov    0x2e9e(%rip),%eax
shl    $0x10,%eax
mov    %eax,0x2e95(%rip)
movl   $0x0,-0x34(%rbp)
cmpl   $0xa,-0x34(%rbp)
jge    1232 <validate_sample+0xf2>
mov    0x2e76(%rip),%edi
sar    $0x10,%edi
mov    0x2e75(%rip),%esi
sar    $0x10,%esi
mov    $0x80000002,%edx
call   1050 <put_cross@plt>
mov    $0x3e8,%edi
call   1060 <usleep@plt>
mov    0x2e50(%rip),%edi
sar    $0x10,%edi
mov    0x2e4f(%rip),%esi
sar    $0x10,%esi
mov    $0x80000002,%edx
call   1050 <put_cross@plt>
mov    -0x2c(%rbp),%eax
add    0x2e31(%rip),%eax
mov    %eax,0x2e2b(%rip)
mov    -0x30(%rbp),%eax
add    0x2e2a(%rip),%eax
mov    %eax,0x2e24(%rip)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11ba <validate_sample+0x7a>
jmp    1237 <validate_sample+0xf7>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    $0x80000002,%edx
call   1050 <put_cross@plt>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1040 <getxy_validate@plt>
mov    -0x20(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jle    12a8 <validate_sample+0x168>
mov    -0x20(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jge    12a8 <validate_sample+0x168>
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jle    12a8 <validate_sample+0x168>
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%ecx
add    -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jge    12a8 <validate_sample+0x168>
movl   $0x0,-0x28(%rbp)
jmp    12af <validate_sample+0x16f>
movl   $0xffffffff,-0x28(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    $0x80000002,%edx
call   1050 <put_cross@plt>
mov    -0xc(%rbp),%eax
mov    %eax,0x2d78(%rip)
mov    -0x10(%rbp),%eax
mov    %eax,0x2d77(%rip)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x10(%rbp),%r9d
mov    -0x28(%rbp),%r10d
lea    0xd3a(%rip),%rax
lea    0xd2e(%rip),%rdi
cmp    $0x0,%r10d
cmovne %rdi,%rax
lea    0xcfc(%rip),%rdi
mov    %rax,(%rsp)
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_sample>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%r15d
mov    %rcx,0x20(%rsp)
mov    %edx,%r13d
mov    %esi,%ebx
mov    %rdi,0x18(%rsp)
mov    0x2eda(%rip),%edi
cmp    $0xffffffff,%edi
je     1225 <validate_sample+0xe5>
mov    %ebx,%eax
sub    %edi,%eax
shl    $0x10,%eax
cltq
imul   $0x66666667,%rax,%rbp
mov    %rbp,%rax
shr    $0x3f,%rax
sar    $0x22,%rbp
add    %eax,%ebp
mov    0x2eb6(%rip),%esi
mov    %r13d,%eax
sub    %esi,%eax
shl    $0x10,%eax
cltq
imul   $0x66666667,%rax,%r14
mov    %r14,%rax
shr    $0x3f,%rax
sar    $0x22,%r14
add    %eax,%r14d
shl    $0x10,%edi
mov    %edi,0x2e86(%rip)
shl    $0x10,%esi
mov    %esi,0x2e85(%rip)
mov    $0xa,%r12d
nopl   0x0(%rax)
sar    $0x10,%edi
sar    $0x10,%esi
mov    $0x80000002,%edx
call   1050 <put_cross@plt>
mov    $0x3e8,%edi
call   1060 <usleep@plt>
movswl 0x2e51(%rip),%edi
movswl 0x2e52(%rip),%esi
mov    $0x80000002,%edx
call   1050 <put_cross@plt>
mov    0x2e38(%rip),%edi
add    %ebp,%edi
mov    %edi,0x2e30(%rip)
mov    0x2e32(%rip),%esi
add    %r14d,%esi
mov    %esi,0x2e29(%rip)
add    $0xffffffff,%r12d
jne    11d0 <validate_sample+0x90>
mov    %ebx,%edi
mov    %r13d,%esi
mov    $0x80000002,%edx
call   1050 <put_cross@plt>
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    0x18(%rsp),%rdi
call   1040 <getxy_validate@plt>
mov    0x14(%rsp),%eax
mov    %ebx,%ecx
sub    %r15d,%ecx
cmp    %ecx,%eax
jle    127f <validate_sample+0x13f>
lea    (%r15,%rbx,1),%ecx
cmp    %ecx,%eax
jge    127f <validate_sample+0x13f>
mov    0x10(%rsp),%eax
mov    %r13d,%ecx
sub    %r15d,%ecx
cmp    %ecx,%eax
jle    127f <validate_sample+0x13f>
add    %r13d,%r15d
cmp    %r15d,%eax
jge    127f <validate_sample+0x13f>
xor    %r15d,%r15d
lea    0xdab(%rip),%rbp
jmp    128c <validate_sample+0x14c>
mov    $0xffffffff,%r15d
lea    0xd97(%rip),%rbp
mov    %ebx,%edi
mov    %r13d,%esi
mov    $0x80000002,%edx
call   1050 <put_cross@plt>
mov    %ebx,0x2d9f(%rip)
mov    %r13d,0x2da0(%rip)
mov    0x14(%rsp),%edx
mov    0x10(%rsp),%r8d
mov    %rbp,(%rsp)
lea    0xd44(%rip),%rdi
mov    0x20(%rsp),%rsi
mov    %ebx,%ecx
mov    %r13d,%r9d
call   1030 <printf@plt>
mov    %r15d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tsdev = type { i32 }
@validate_sample.last_x = internal global i32 -1
@validate_sample.last_y = internal global i32 0
@.str = [35 x i8] c"%s : X = %4d(%4d) Y = %4d(%4d) %s\0A\00"
@.str.1 = [5 x i8] c"fail\00"
@.str.2 = [5 x i8] c"pass\00"
define i32 @validate_sample(%struct.tsdev* %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca %struct.tsdev*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store %struct.tsdev* %0, %struct.tsdev** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%17 = load i32, i32* @validate_sample.last_x
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %59
19: ; preds = %5
%20 = load i32, i32* %7
%21 = load i32, i32* @validate_sample.last_x
%22 = sub nsw i32 %20, %21
%23 = shl i32 %22, 16
%24 = sdiv i32 %23, 10
store i32 %24, i32* %14
%25 = load i32, i32* %8
%26 = load i32, i32* @validate_sample.last_y
%27 = sub nsw i32 %25, %26
%28 = shl i32 %27, 16
%29 = sdiv i32 %28, 10
store i32 %29, i32* %15
%30 = load i32, i32* @validate_sample.last_x
%31 = shl i32 %30, 16
store i32 %31, i32* @validate_sample.last_x
%32 = load i32, i32* @validate_sample.last_y
%33 = shl i32 %32, 16
store i32 %33, i32* @validate_sample.last_y
store i32 0, i32* %16
br label %34
34: ; preds = %55, %19
%35 = load i32, i32* %16
%36 = icmp slt i32 %35, 10
br i1 %36, label %37, label %58
37: ; preds = %34
%38 = load i32, i32* @validate_sample.last_x
%39 = ashr i32 %38, 16
%40 = load i32, i32* @validate_sample.last_y
%41 = ashr i32 %40, 16
%42 = call i32 @put_cross(i32 %39, i32 %41, i32 -2147483646)
%43 = call i32 @usleep(i32 1000)
%44 = load i32, i32* @validate_sample.last_x
%45 = ashr i32 %44, 16
%46 = load i32, i32* @validate_sample.last_y
%47 = ashr i32 %46, 16
%48 = call i32 @put_cross(i32 %45, i32 %47, i32 -2147483646)
%49 = load i32, i32* %14
%50 = load i32, i32* @validate_sample.last_x
%51 = add nsw i32 %50, %49
store i32 %51, i32* @validate_sample.last_x
%52 = load i32, i32* %15
%53 = load i32, i32* @validate_sample.last_y
%54 = add nsw i32 %53, %52
store i32 %54, i32* @validate_sample.last_y
br label %55
55: ; preds = %37
%56 = load i32, i32* %16
%57 = add nsw i32 %56, 1
store i32 %57, i32* %16
br label %34
58: ; preds = %34
br label %59
59: ; preds = %58, %5
%60 = load i32, i32* %7
%61 = load i32, i32* %8
%62 = call i32 @put_cross(i32 %60, i32 %61, i32 -2147483646)
%63 = load %struct.tsdev*, %struct.tsdev** %6
%64 = call i32 @getxy_validate(%struct.tsdev* %63, i32* %11, i32* %12)
%65 = load i32, i32* %11
%66 = load i32, i32* %7
%67 = load i32, i32* %10
%68 = sub nsw i32 %66, %67
%69 = icmp sgt i32 %65, %68
br i1 %69, label %70, label %89
70: ; preds = %59
%71 = load i32, i32* %11
%72 = load i32, i32* %7
%73 = load i32, i32* %10
%74 = add nsw i32 %72, %73
%75 = icmp slt i32 %71, %74
br i1 %75, label %76, label %89
76: ; preds = %70
%77 = load i32, i32* %12
%78 = load i32, i32* %8
%79 = load i32, i32* %10
%80 = sub nsw i32 %78, %79
%81 = icmp sgt i32 %77, %80
br i1 %81, label %82, label %89
82: ; preds = %76
%83 = load i32, i32* %12
%84 = load i32, i32* %8
%85 = load i32, i32* %10
%86 = add nsw i32 %84, %85
%87 = icmp slt i32 %83, %86
br i1 %87, label %88, label %89
88: ; preds = %82
store i32 0, i32* %13
br label %90
89: ; preds = %82, %76, %70, %59
store i32 -1, i32* %13
br label %90
90: ; preds = %89, %88
%91 = load i32, i32* %7
%92 = load i32, i32* %8
%93 = call i32 @put_cross(i32 %91, i32 %92, i32 -2147483646)
%94 = load i32, i32* %7
store i32 %94, i32* @validate_sample.last_x
%95 = load i32, i32* %8
store i32 %95, i32* @validate_sample.last_y
%96 = load i8*, i8** %9
%97 = load i32, i32* %11
%98 = load i32, i32* %7
%99 = load i32, i32* %12
%100 = load i32, i32* %8
%101 = load i32, i32* %13
%102 = icmp ne i32 %101, 0
%103 = zext i1 %102 to i64
%104 = select i1 %102, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%105 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %96, i32 %97, i32 %98, i32 %99, i32 %100, i8* %104)
%106 = load i32, i32* %13
ret i32 %106
}

LLVM IR (-O2):
%struct.tsdev = type { i32 }
@validate_sample.last_x = internal unnamed_addr global i32 -1
@validate_sample.last_y = internal unnamed_addr global i32 0
@.str = [35 x i8] c"%s : X = %4d(%4d) Y = %4d(%4d) %s\0A\00"
@.str.1 = [5 x i8] c"fail\00"
@.str.2 = [5 x i8] c"pass\00"
define i32 @validate_sample(%struct.tsdev* %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %6 to i8*
%9 = bitcast i32* %7 to i8*
%10 = load i32, i32* @validate_sample.last_x
%11 = icmp eq i32 %10, -1
br i1 %11, label %41, label %12
12: ; preds = %5
%13 = sub nsw i32 %1, %10
%14 = shl i32 %13, 16
%15 = sdiv i32 %14, 10
%16 = load i32, i32* @validate_sample.last_y
%17 = sub nsw i32 %2, %16
%18 = shl i32 %17, 16
%19 = sdiv i32 %18, 10
%20 = shl i32 %10, 16
store i32 %20, i32* @validate_sample.last_x
%21 = shl i32 %16, 16
store i32 %21, i32* @validate_sample.last_y
br label %22
22: ; preds = %12, %22
%23 = phi i32 [ %21, %12 ], [ %38, %22 ]
%24 = phi i32 [ %20, %12 ], [ %36, %22 ]
%25 = phi i32 [ 0, %12 ], [ %39, %22 ]
%26 = ashr i32 %24, 16
%27 = ashr i32 %23, 16
%28 = tail call i32 @put_cross(i32 %26, i32 %27, i32 -2147483646)
%29 = tail call i32 @usleep(i32 1000)
%30 = load i32, i32* @validate_sample.last_x
%31 = ashr i32 %30, 16
%32 = load i32, i32* @validate_sample.last_y
%33 = ashr i32 %32, 16
%34 = tail call i32 @put_cross(i32 %31, i32 %33, i32 -2147483646)
%35 = load i32, i32* @validate_sample.last_x
%36 = add nsw i32 %35, %15
store i32 %36, i32* @validate_sample.last_x
%37 = load i32, i32* @validate_sample.last_y
%38 = add nsw i32 %37, %19
store i32 %38, i32* @validate_sample.last_y
%39 = add nuw nsw i32 %25, 1
%40 = icmp eq i32 %39, 10
br i1 %40, label %41, label %22
41: ; preds = %22, %5
%42 = tail call i32 @put_cross(i32 %1, i32 %2, i32 -2147483646)
%43 = call i32 @getxy_validate(%struct.tsdev* %0, i32* %6, i32* %7)
%44 = load i32, i32* %6
%45 = sub nsw i32 %1, %4
%46 = icmp sgt i32 %44, %45
%47 = add nsw i32 %4, %1
%48 = icmp slt i32 %44, %47
%49 = select i1 %46, i1 %48, i1 false
br i1 %49, label %50, label %57
50: ; preds = %41
%51 = load i32, i32* %7
%52 = sub nsw i32 %2, %4
%53 = icmp sgt i32 %51, %52
%54 = add nsw i32 %4, %2
%55 = icmp slt i32 %51, %54
%56 = select i1 %53, i1 %55, i1 false
br i1 %56, label %58, label %57
57: ; preds = %50, %41
br label %58
58: ; preds = %50, %57
%59 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %57 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %50 ]
%60 = phi i32 [ -1, %57 ], [ 0, %50 ]
%61 = call i32 @put_cross(i32 %1, i32 %2, i32 -2147483646)
store i32 %1, i32* @validate_sample.last_x
store i32 %2, i32* @validate_sample.last_y
%62 = load i32, i32* %6
%63 = load i32, i32* %7
%64 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %62, i32 %1, i32 %63, i32 %2, i8* %59)
ret i32 %60
}