#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 */

/* Variables and functions */
int abs(int);
int /*<<< orphan*/ bresline(int, int, int, int, int);
int /*<<< orphan*/ getmousepos(int *, int *, int *);
int /*<<< orphan*/ hidemouseptr();
int /*<<< orphan*/ showmouseptr();
void pencil() {
  int x, y, button, prevx, prevy;
  getmousepos(&button, &x, &y);
  if (button == 1) {
    hidemouseptr();
    prevx = x;
    prevy = y;
    while (button == 1) {
      if (!((abs(prevx - x)) <= 5 && (abs(prevy - y)) <= 5)) {
        bresline(prevx, prevy, x, y, 1);
        prevx = x;
        prevy = y;
      }
      getmousepos(&button, &x, &y);
    }
    showmouseptr();
  }
}


x86 assembly (clang, -O0):
<pencil>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0xc(%rbp),%rdi
lea    -0x4(%rbp),%rsi
lea    -0x8(%rbp),%rdx
call   1040 <getmousepos@plt>
cmpl   $0x1,-0xc(%rbp)
jne    11f8 <pencil+0xa8>
mov    $0x0,%al
call   1070 <hidemouseptr@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    11f1 <pencil+0xa1>
mov    -0x10(%rbp),%edi
sub    -0x4(%rbp),%edi
call   1030 <abs@plt>
cmp    $0x5,%eax
jg     11b8 <pencil+0x68>
mov    -0x14(%rbp),%edi
sub    -0x8(%rbp),%edi
call   1030 <abs@plt>
cmp    $0x5,%eax
jle    11db <pencil+0x8b>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
mov    $0x1,%r8d
call   1050 <bresline@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    -0xc(%rbp),%rdi
lea    -0x4(%rbp),%rsi
lea    -0x8(%rbp),%rdx
call   1040 <getmousepos@plt>
jmp    1186 <pencil+0x36>
mov    $0x0,%al
call   1060 <showmouseptr@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pencil>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0x4(%rsp),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1030 <getmousepos@plt>
cmpl   $0x1,0x4(%rsp)
jne    11fd <pencil+0xbd>
xor    %eax,%eax
call   1060 <hidemouseptr@plt>
cmpl   $0x1,0x4(%rsp)
jne    11f6 <pencil+0xb6>
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ebp
lea    0x4(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0x8(%rsp),%r12
mov    %edx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%eax
sub    %edx,%eax
mov    %eax,%esi
neg    %esi
cmovs  %eax,%esi
mov    0x8(%rsp),%ecx
cmp    $0x5,%esi
ja     11c4 <pencil+0x84>
mov    %ebp,%eax
sub    %ecx,%eax
mov    %eax,%esi
neg    %esi
cmovs  %eax,%esi
cmp    $0x6,%esi
jb     11db <pencil+0x9b>
mov    %ebx,%edi
mov    %ebp,%esi
mov    $0x1,%r8d
call   1040 <bresline@plt>
mov    0xc(%rsp),%ebx
mov    0x8(%rsp),%ebp
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <getmousepos@plt>
cmpl   $0x1,0x4(%rsp)
jne    11f6 <pencil+0xb6>
mov    0xc(%rsp),%edx
jmp    11a0 <pencil+0x60>
xor    %eax,%eax
call   1050 <showmouseptr@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @pencil() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = call i32 @getmousepos(i32* %3, i32* %1, i32* %2)
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %40
9: ; preds = %0
%10 = call i32 (...) @hidemouseptr()
%11 = load i32, i32* %1
store i32 %11, i32* %4
%12 = load i32, i32* %2
store i32 %12, i32* %5
br label %13
13: ; preds = %36, %9
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %38
16: ; preds = %13
%17 = load i32, i32* %4
%18 = load i32, i32* %1
%19 = sub nsw i32 %17, %18
%20 = call i32 @abs(i32 %19)
%21 = icmp sle i32 %20, 5
br i1 %21, label %22, label %28
22: ; preds = %16
%23 = load i32, i32* %5
%24 = load i32, i32* %2
%25 = sub nsw i32 %23, %24
%26 = call i32 @abs(i32 %25)
%27 = icmp sle i32 %26, 5
br i1 %27, label %36, label %28
28: ; preds = %22, %16
%29 = load i32, i32* %4
%30 = load i32, i32* %5
%31 = load i32, i32* %1
%32 = load i32, i32* %2
%33 = call i32 @bresline(i32 %29, i32 %30, i32 %31, i32 %32, i32 1)
%34 = load i32, i32* %1
store i32 %34, i32* %4
%35 = load i32, i32* %2
store i32 %35, i32* %5
br label %36
36: ; preds = %28, %22
%37 = call i32 @getmousepos(i32* %3, i32* %1, i32* %2)
br label %13
38: ; preds = %13
%39 = call i32 (...) @showmouseptr()
br label %40
40: ; preds = %38, %0
ret void
}

LLVM IR (-O2):
define void @pencil() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = call i32 @getmousepos(i32* %3, i32* %1, i32* %2)
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %43
10: ; preds = %0
%11 = call i32 (...) @hidemouseptr()
%12 = load i32, i32* %1
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %41
15: ; preds = %10
%16 = load i32, i32* %2
br label %17
17: ; preds = %39, %15
%18 = phi i32 [ %40, %39 ], [ %12, %15 ]
%19 = phi i32 [ %35, %39 ], [ %16, %15 ]
%20 = phi i32 [ %34, %39 ], [ %12, %15 ]
%21 = sub nsw i32 %20, %18
%22 = call i32 @llvm.abs.i32(i32 %21, i1 true)
%23 = icmp ult i32 %22, 6
%24 = load i32, i32* %2
br i1 %23, label %25, label %29
25: ; preds = %17
%26 = sub nsw i32 %19, %24
%27 = call i32 @llvm.abs.i32(i32 %26, i1 true)
%28 = icmp ult i32 %27, 6
br i1 %28, label %33, label %29
29: ; preds = %17, %25
%30 = call i32 @bresline(i32 %20, i32 %19, i32 %18, i32 %24, i32 1)
%31 = load i32, i32* %1
%32 = load i32, i32* %2
br label %33
33: ; preds = %29, %25
%34 = phi i32 [ %20, %25 ], [ %31, %29 ]
%35 = phi i32 [ %19, %25 ], [ %32, %29 ]
%36 = call i32 @getmousepos(i32* %3, i32* %1, i32* %2)
%37 = load i32, i32* %3
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %41
39: ; preds = %33
%40 = load i32, i32* %1
br label %17
41: ; preds = %33, %10
%42 = call i32 (...) @showmouseptr()
br label %43
43: ; preds = %41, %0
ret void
}