#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 psmouse {
  int dummy;
};

/* Variables and functions */
scalar_t__ psmouse_command(struct psmouse *, unsigned char *, int);
int synaptics_reset(struct psmouse *psmouse) {
  unsigned char r[2];
  if (psmouse_command(psmouse, r, 0x02ff))
    return -1;
  if (r[0] == 0xaa && r[1] == 0x00)
    return 0;
  return -1;
}


x86 assembly (clang, -O0):
<synaptics_reset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x12(%rbp),%rsi
mov    $0x2ff,%edx
call   1030 <psmouse_command@plt>
cmp    $0x0,%rax
je     1144 <synaptics_reset+0x34>
movl   $0xffffffff,-0x4(%rbp)
jmp    1173 <synaptics_reset+0x63>
movzbl -0x12(%rbp),%eax
cmp    $0xaa,%eax
jne    116c <synaptics_reset+0x5c>
movzbl -0x11(%rbp),%eax
cmp    $0x0,%eax
jne    116c <synaptics_reset+0x5c>
movl   $0x0,-0x4(%rbp)
jmp    1173 <synaptics_reset+0x63>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<synaptics_reset>:
push   %rax
lea    0x6(%rsp),%rsi
mov    $0x2ff,%edx
call   1030 <psmouse_command@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
je     112f <synaptics_reset+0x1f>
pop    %rcx
ret
mov    0x6(%rsp),%cl
xor    $0xaa,%cl
xor    %eax,%eax
or     0x7(%rsp),%cl
setne  %al
neg    %eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.psmouse = type { i32 }
define i32 @synaptics_reset(%struct.psmouse* %0) {
%2 = alloca i32
%3 = alloca %struct.psmouse*
%4 = alloca [2 x i8]
store %struct.psmouse* %0, %struct.psmouse** %3
%5 = load %struct.psmouse*, %struct.psmouse** %3
%6 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%7 = call i64 @psmouse_command(%struct.psmouse* %5, i8* %6, i32 767)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %22
10: ; preds = %1
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = icmp eq i32 %13, 170
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 0, i32* %2
br label %22
21: ; preds = %15, %10
store i32 -1, i32* %2
br label %22
22: ; preds = %21, %20, %9
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
%struct.psmouse = type { i32 }
define i32 @synaptics_reset(%struct.psmouse* %0) {
%2 = alloca [2 x i8]
%3 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%4 = call i64 @psmouse_command(%struct.psmouse* %0, i8* %3, i32 767)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %1
%7 = load i8, i8* %3
%8 = icmp ne i8 %7, -86
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 1
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
%12 = select i1 %8, i1 true, i1 %11
%13 = sext i1 %12 to i32
br label %14
14: ; preds = %6, %1
%15 = phi i32 [ -1, %1 ], [ %13, %6 ]
ret i32 %15
}