#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 */
typedef scalar_t__ uint8_t;
struct mcp23017 {
  int dummy;
};
struct hd44780 {
  int dummy;
};
typedef int int8_t;

/* Variables and functions */
int /*<<< orphan*/ hd44780WriteByte(struct mcp23017 *, struct hd44780 *,
                                    scalar_t__, int /*<<< orphan*/);
int8_t hd44780Goto(struct mcp23017 *mcp23017, struct hd44780 *hd44780,
                   uint8_t row, uint8_t pos) {
  if ((pos < 0) | (pos > 16 - 1))
    return -1;
  if ((row < 0) | (row > 2 - 1))
    return -1;
  uint8_t rows[4] = {0x00, 0x40, 0x14, 0x54};
  hd44780WriteByte(mcp23017, hd44780, (0x80 | rows[row]) + pos, 0);
  return 0;
}


x86 assembly (clang, -O0):
<hd44780Goto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%eax
cmpq   $0xf,-0x28(%rbp)
setg   %cl
and    $0x1,%cl
movzbl %cl,%ecx
or     %ecx,%eax
cmp    $0x0,%eax
je     115a <hd44780Goto+0x4a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <hd44780Goto+0xd2>
cmpq   $0x0,-0x20(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%eax
cmpq   $0x1,-0x20(%rbp)
setg   %cl
and    $0x1,%cl
movzbl %cl,%ecx
or     %ecx,%eax
cmp    $0x0,%eax
je     118c <hd44780Goto+0x7c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <hd44780Goto+0xd2>
mov    0xe6d(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe6a(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe67(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe64(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x50(%rbp,%rax,8),%rdx
or     $0x80,%rdx
add    -0x28(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <hd44780WriteByte@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hd44780Goto>:
push   %rbp
push   %rbx
push   %rax
mov    %rcx,%rax
shr    $0x3f,%rax
xor    %ebx,%ebx
cmp    $0x10,%rcx
setge  %bl
mov    $0xffffffff,%ebp
or     %eax,%ebx
jne    1160 <hd44780Goto+0x50>
mov    %rdx,%rax
shr    $0x3f,%rax
xor    %ebx,%ebx
cmp    $0x2,%rdx
setge  %bl
or     %eax,%ebx
jne    1160 <hd44780Goto+0x50>
lea    0xeb9(%rip),%rbp
mov    $0x80,%eax
or     0x0(%rbp,%rdx,8),%rax
add    %rcx,%rax
xor    %ebp,%ebp
mov    %rax,%rdx
xor    %ecx,%ecx
call   1030 <hd44780WriteByte@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.mcp23017 = type { i32 }
%struct.hd44780 = type { i32 }
@__const.hd44780Goto.rows = [4 x i64] [i64 0, i64 64, i64 20, i64 84]
define i32 @hd44780Goto(%struct.mcp23017* %0, %struct.hd44780* %1, i64 %2, i64 %3) {
%5 = alloca i32
%6 = alloca %struct.mcp23017*
%7 = alloca %struct.hd44780*
%8 = alloca i64
%9 = alloca i64
%10 = alloca [4 x i64]
store %struct.mcp23017* %0, %struct.mcp23017** %6
store %struct.hd44780* %1, %struct.hd44780** %7
store i64 %2, i64* %8
store i64 %3, i64* %9
%11 = load i64, i64* %9
%12 = icmp slt i64 %11, 0
%13 = zext i1 %12 to i32
%14 = load i64, i64* %9
%15 = icmp sgt i64 %14, 15
%16 = zext i1 %15 to i32
%17 = or i32 %13, %16
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %4
store i32 -1, i32* %5
br label %41
20: ; preds = %4
%21 = load i64, i64* %8
%22 = icmp slt i64 %21, 0
%23 = zext i1 %22 to i32
%24 = load i64, i64* %8
%25 = icmp sgt i64 %24, 1
%26 = zext i1 %25 to i32
%27 = or i32 %23, %26
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %20
store i32 -1, i32* %5
br label %41
30: ; preds = %20
%31 = bitcast [4 x i64]* %10 to i8*
%32 = load %struct.mcp23017*, %struct.mcp23017** %6
%33 = load %struct.hd44780*, %struct.hd44780** %7
%34 = load i64, i64* %8
%35 = getelementptr inbounds [4 x i64], [4 x i64]* %10, i64 0, i64 %34
%36 = load i64, i64* %35
%37 = or i64 128, %36
%38 = load i64, i64* %9
%39 = add nsw i64 %37, %38
%40 = call i32 @hd44780WriteByte(%struct.mcp23017* %32, %struct.hd44780* %33, i64 %39, i32 0)
store i32 0, i32* %5
br label %41
41: ; preds = %30, %29, %19
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
%struct.mcp23017 = type { i32 }
%struct.hd44780 = type { i32 }
@__const.hd44780Goto.rows = [4 x i64] [i64 0, i64 64, i64 20, i64 84]
define i32 @hd44780Goto(%struct.mcp23017* %0, %struct.hd44780* %1, i64 %2, i64 %3) {
%5 = lshr i64 %3, 63
%6 = trunc i64 %5 to i32
%7 = icmp sgt i64 %3, 15
%8 = zext i1 %7 to i32
%9 = or i32 %6, %8
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %4
%12 = lshr i64 %2, 63
%13 = trunc i64 %12 to i32
%14 = icmp sgt i64 %2, 1
%15 = zext i1 %14 to i32
%16 = or i32 %13, %15
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %11
%19 = getelementptr inbounds [4 x i64], [4 x i64]* @__const.hd44780Goto.rows, i64 0, i64 %2
%20 = load i64, i64* %19
%21 = or i64 %20, 128
%22 = add nsw i64 %21, %3
%23 = tail call i32 @hd44780WriteByte(%struct.mcp23017* %0, %struct.hd44780* %1, i64 %22, i32 0)
br label %24
24: ; preds = %11, %4, %18
%25 = phi i32 [ 0, %18 ], [ -1, %4 ], [ -1, %11 ]
ret i32 %25
}