#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__ {
  int bstate;
  int /*<<< orphan*/ x;
  int /*<<< orphan*/ y;
  int /*<<< orphan*/ z;
};
typedef TYPE_1__ MEVENT;

/* Variables and functions */
int BUTTON1_PRESSED;
int BUTTON3_PRESSED;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int KEY_MOUSE;
scalar_t__ OK;
int REPORT_MOUSE_POSITION;
int /*<<< orphan*/ TRUE;
int /*<<< orphan*/ cbreak();
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ getmouse(TYPE_1__ *);
int /*<<< orphan*/ *initscr();
int /*<<< orphan*/ keypad(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mousemask(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ mvprintw(int, int, char *, ...);
int mvwgetch(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdscr;
int main(void) {
  MEVENT event;
  int input;
  if (initscr() == NULL) {
    fprintf(stderr, "initscr failure\n");
    exit(EXIT_FAILURE);
  }
  cbreak();
  keypad(stdscr, TRUE);
  mousemask(BUTTON1_PRESSED | BUTTON3_PRESSED | REPORT_MOUSE_POSITION, NULL);
  refresh();
  while ((input = mvwgetch(stdscr, 0, 0)) != 'q') {
    if (input == KEY_MOUSE) {
      mvprintw(2, 5, "mouse event");
      if (getmouse(&event) != OK) {
        mvprintw(3, 5, "getmouse failure");
        continue;
      }
      mvprintw(3, 5, "x = %d, y = %d, z = %d", event.x, event.y, event.z);
      if (event.bstate == BUTTON1_PRESSED) {
        mvprintw(event.y, event.x, "*");
      } else if (event.bstate == BUTTON3_PRESSED) {
        mvprintw(event.y, event.x, " ");
      }
      refresh();
    } else {
      mvprintw(2, 5, "not mouse event %c", input);
    }
  }
  endwin();
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <initscr@plt>
cmp    $0x0,%rax
jne    11f3 <main+0x43>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    $0x0,%al
call   1040 <cbreak@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
call   1060 <keypad@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
mov    0x2d77(%rip),%rax
or     (%rax),%edi
mov    0x2d7e(%rip),%rax
or     (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <mousemask@plt>
mov    $0x0,%al
call   10a0 <refresh@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1030 <mvwgetch@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x71,%eax
je     135f <main+0x1af>
mov    -0x1c(%rbp),%eax
mov    0x2d84(%rip),%rcx
cmp    (%rcx),%eax
jne    133f <main+0x18f>
mov    $0x2,%edi
mov    $0x5,%esi
lea    0xd94(%rip),%rdx
mov    $0x0,%al
call   10d0 <mvprintw@plt>
lea    -0x18(%rbp),%rdi
call   1090 <getmouse@plt>
mov    0x2d0c(%rip),%rcx
cmp    (%rcx),%rax
je     12ba <main+0x10a>
mov    $0x3,%edi
mov    $0x5,%esi
lea    0xd6f(%rip),%rdx
mov    $0x0,%al
call   10d0 <mvprintw@plt>
jmp    123c <main+0x8c>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%r8d
mov    -0xc(%rbp),%r9d
mov    $0x3,%edi
mov    $0x5,%esi
lea    0xd58(%rip),%rdx
mov    $0x0,%al
call   10d0 <mvprintw@plt>
mov    -0x18(%rbp),%eax
mov    0x2cd9(%rip),%rcx
cmp    (%rcx),%eax
jne    1308 <main+0x158>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
lea    0xd49(%rip),%rdx
mov    $0x0,%al
call   10d0 <mvprintw@plt>
jmp    1333 <main+0x183>
mov    -0x18(%rbp),%eax
mov    0x2c86(%rip),%rcx
cmp    (%rcx),%eax
jne    132e <main+0x17e>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
lea    0xd20(%rip),%rdx
mov    $0x0,%al
call   10d0 <mvprintw@plt>
jmp    1333 <main+0x183>
mov    $0x0,%al
call   10a0 <refresh@plt>
jmp    135a <main+0x1aa>
mov    -0x1c(%rbp),%ecx
mov    $0x2,%edi
mov    $0x5,%esi
lea    0xcf6(%rip),%rdx
mov    $0x0,%al
call   10d0 <mvprintw@plt>
jmp    123c <main+0x8c>
mov    $0x0,%al
call   10b0 <endwin@plt>
mov    0x2c43(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1070 <initscr@plt>
test   %rax,%rax
jne    11ed <main+0x3d>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
xor    %eax,%eax
call   1040 <cbreak@plt>
mov    0x2de5(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dd3(%rip),%rax
mov    (%rax),%esi
call   1060 <keypad@plt>
mov    0x2dad(%rip),%rax
mov    0x2d7e(%rip),%rcx
mov    (%rcx),%edi
or     (%rax),%edi
mov    0x2d83(%rip),%rax
or     (%rax),%edi
xor    %esi,%esi
call   1050 <mousemask@plt>
xor    %eax,%eax
call   10a0 <refresh@plt>
mov    0x0(%rbp),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <mvwgetch@plt>
cmp    $0x71,%eax
jne    125b <main+0xab>
xor    %eax,%eax
call   10b0 <endwin@plt>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2d86(%rip),%r15
lea    0xda8(%rip),%r14
lea    0x8(%rsp),%r13
mov    0x2d2b(%rip),%r12
lea    0xdcd(%rip),%rbx
jmp    12a7 <main+0xf7>
xchg   %ax,%ax
mov    $0x2,%edi
mov    $0x5,%esi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   10d0 <mvprintw@plt>
mov    0x0(%rbp),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <mvwgetch@plt>
cmp    $0x71,%eax
je     1246 <main+0x96>
cmp    (%r15),%eax
jne    1280 <main+0xd0>
mov    $0x2,%edi
mov    $0x5,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   10d0 <mvprintw@plt>
mov    %r13,%rdi
call   1090 <getmouse@plt>
cmp    (%r12),%rax
jne    1340 <main+0x190>
mov    0xc(%rsp),%ecx
mov    0x10(%rsp),%r8d
mov    0x14(%rsp),%r9d
mov    $0x3,%edi
mov    $0x5,%esi
lea    0xd41(%rip),%rdx
xor    %eax,%eax
call   10d0 <mvprintw@plt>
mov    0x8(%rsp),%eax
lea    0xd46(%rip),%rdx
mov    0x2cba(%rip),%rcx
cmp    (%rcx),%eax
je     131c <main+0x16c>
lea    0xd36(%rip),%rdx
mov    0x2c80(%rip),%rcx
cmp    (%rcx),%eax
jne    132b <main+0x17b>
mov    0xc(%rsp),%esi
mov    0x10(%rsp),%edi
xor    %eax,%eax
call   10d0 <mvprintw@plt>
xor    %eax,%eax
call   10a0 <refresh@plt>
jmp    1296 <main+0xe6>
nopw   0x0(%rax,%rax,1)
mov    $0x3,%edi
mov    $0x5,%esi
lea    0xccc(%rip),%rdx
xor    %eax,%eax
call   10d0 <mvprintw@plt>
jmp    1296 <main+0xe6>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32, i32, i32 }
@stderr = global i32 0
@.str = [17 x i8] c"initscr failure\0A\00"
@EXIT_FAILURE = global i32 0
@stdscr = global i32 0
@TRUE = global i32 0
@BUTTON1_PRESSED = global i32 0
@BUTTON3_PRESSED = global i32 0
@REPORT_MOUSE_POSITION = global i32 0
@KEY_MOUSE = global i32 0
@.str.1 = [12 x i8] c"mouse event\00"
@OK = global i64 0
@.str.2 = [17 x i8] c"getmouse failure\00"
@.str.3 = [23 x i8] c"x = %d, y = %d, z = %d\00"
@.str.4 = [2 x i8] c"*\00"
@.str.5 = [2 x i8] c" \00"
@.str.6 = [19 x i8] c"not mouse event %c\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.TYPE_3__
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32* (...) @initscr()
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = call i32 (...) @cbreak()
%13 = load i32, i32* @stdscr
%14 = load i32, i32* @TRUE
%15 = call i32 @keypad(i32 %13, i32 %14)
%16 = load i32, i32* @BUTTON1_PRESSED
%17 = load i32, i32* @BUTTON3_PRESSED
%18 = or i32 %16, %17
%19 = load i32, i32* @REPORT_MOUSE_POSITION
%20 = or i32 %18, %19
%21 = call i32 @mousemask(i32 %20, i32* null)
%22 = call i32 (...) @refresh()
br label %23
23: ; preds = %73, %36, %11
%24 = load i32, i32* @stdscr
%25 = call i32 @mvwgetch(i32 %24, i32 0, i32 0)
store i32 %25, i32* %3
%26 = icmp ne i32 %25, 113
br i1 %26, label %27, label %74
27: ; preds = %23
%28 = load i32, i32* %3
%29 = load i32, i32* @KEY_MOUSE
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %70
31: ; preds = %27
%32 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 2, i32 5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%33 = call i64 @getmouse(%struct.TYPE_3__* %2)
%34 = load i64, i64* @OK
%35 = icmp ne i64 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 3, i32 5, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %23
38: ; preds = %31
%39 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 1
%40 = load i32, i32* %39
%41 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 2
%42 = load i32, i32* %41
%43 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 3
%44 = load i32, i32* %43
%45 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 3, i32 5, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %40, i32 %42, i32 %44)
%46 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 0
%47 = load i32, i32* %46
%48 = load i32, i32* @BUTTON1_PRESSED
%49 = icmp eq i32 %47, %48
br i1 %49, label %50, label %56
50: ; preds = %38
%51 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 2
%52 = load i32, i32* %51
%53 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 1
%54 = load i32, i32* %53
%55 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 %52, i32 %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %68
56: ; preds = %38
%57 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 0
%58 = load i32, i32* %57
%59 = load i32, i32* @BUTTON3_PRESSED
%60 = icmp eq i32 %58, %59
br i1 %60, label %61, label %67
61: ; preds = %56
%62 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 2
%63 = load i32, i32* %62
%64 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 1
%65 = load i32, i32* %64
%66 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 %63, i32 %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %67
67: ; preds = %61, %56
br label %68
68: ; preds = %67, %50
%69 = call i32 (...) @refresh()
br label %73
70: ; preds = %27
%71 = load i32, i32* %3
%72 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 2, i32 5, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %71)
br label %73
73: ; preds = %70, %68
br label %23
74: ; preds = %23
%75 = call i32 (...) @endwin()
%76 = load i32, i32* @EXIT_SUCCESS
%77 = call i32 @exit(i32 %76)
unreachable
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32, i32, i32 }
@stderr = global i32 0
@.str = [17 x i8] c"initscr failure\0A\00"
@EXIT_FAILURE = global i32 0
@stdscr = global i32 0
@TRUE = global i32 0
@BUTTON1_PRESSED = global i32 0
@BUTTON3_PRESSED = global i32 0
@REPORT_MOUSE_POSITION = global i32 0
@KEY_MOUSE = global i32 0
@.str.1 = [12 x i8] c"mouse event\00"
@OK = global i64 0
@.str.2 = [17 x i8] c"getmouse failure\00"
@.str.3 = [23 x i8] c"x = %d, y = %d, z = %d\00"
@.str.4 = [2 x i8] c"*\00"
@.str.5 = [2 x i8] c" \00"
@.str.6 = [19 x i8] c"not mouse event %c\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.TYPE_3__
%2 = bitcast %struct.TYPE_3__* %1 to i8*
%3 = tail call i32* (...) @initscr()
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = tail call i32 (...) @cbreak()
%12 = load i32, i32* @stdscr
%13 = load i32, i32* @TRUE
%14 = tail call i32 @keypad(i32 %12, i32 %13)
%15 = load i32, i32* @BUTTON1_PRESSED
%16 = load i32, i32* @BUTTON3_PRESSED
%17 = or i32 %16, %15
%18 = load i32, i32* @REPORT_MOUSE_POSITION
%19 = or i32 %17, %18
%20 = tail call i32 @mousemask(i32 %19, i32* null)
%21 = tail call i32 (...) @refresh()
%22 = load i32, i32* @stdscr
%23 = call i32 @mvwgetch(i32 %22, i32 0, i32 0)
%24 = icmp eq i32 %23, 113
br i1 %24, label %65, label %25
25: ; preds = %10
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 1
%27 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 2
%28 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 3
%29 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
br label %30
30: ; preds = %25, %41
%31 = phi i32 [ %23, %25 ], [ %43, %41 ]
%32 = load i32, i32* @KEY_MOUSE
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %63
34: ; preds = %30
%35 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 2, i32 5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%36 = call i64 @getmouse(%struct.TYPE_3__* %1)
%37 = load i64, i64* @OK
%38 = icmp eq i64 %36, %37
br i1 %38, label %45, label %39
39: ; preds = %34
%40 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 3, i32 5, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %61, %63, %39
%42 = load i32, i32* @stdscr
%43 = call i32 @mvwgetch(i32 %42, i32 0, i32 0)
%44 = icmp eq i32 %43, 113
br i1 %44, label %65, label %30
45: ; preds = %34
%46 = load i32, i32* %26
%47 = load i32, i32* %27
%48 = load i32, i32* %28
%49 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 3, i32 5, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %46, i32 %47, i32 %48)
%50 = load i32, i32* %29
%51 = load i32, i32* @BUTTON1_PRESSED
%52 = icmp eq i32 %50, %51
br i1 %52, label %56, label %53
53: ; preds = %45
%54 = load i32, i32* @BUTTON3_PRESSED
%55 = icmp eq i32 %50, %54
br i1 %55, label %56, label %61
56: ; preds = %53, %45
%57 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), %45 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), %53 ]
%58 = load i32, i32* %27
%59 = load i32, i32* %26
%60 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 %58, i32 %59, i8* %57)
br label %61
61: ; preds = %56, %53
%62 = call i32 (...) @refresh()
br label %41
63: ; preds = %30
%64 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 2, i32 5, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %31)
br label %41
65: ; preds = %41, %10
%66 = call i32 (...) @endwin()
%67 = load i32, i32* @EXIT_SUCCESS
%68 = call i32 @exit(i32 %67)
unreachable
}