#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 int uint8_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ send_gpio(int, int /*<<< orphan*/);
void lcd_goto(int line, int pos) {
  if (line < 2 && pos < 16) {
    uint8_t ddram_addr = 0;
    if (2 == 2) {
      switch (line) {
      case 0:
        ddram_addr = 0x00;
        break;
      case 1:
        ddram_addr = 0x40;
        break;
      }
    } else if (2 == 4) {
      switch (line) {
      case 0:
        ddram_addr = 0x00;
        break;
      case 1:
        ddram_addr = 16;
        break;
      case 2:
        ddram_addr = 0x40;
        break;
      case 3:
        ddram_addr = 0x40 + 16;
        break;
      }
    }
    ddram_addr += pos;
    uint16_t val = (0b0010000000 | (ddram_addr & 0x7F));
    send_gpio(val, 0);
  }
}


x86 assembly (clang, -O0):
<lcd_goto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x2,-0x4(%rbp)
jge    1191 <lcd_goto+0x81>
cmpl   $0x10,-0x8(%rbp)
jge    1191 <lcd_goto+0x81>
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
test   %eax,%eax
je     115d <lcd_goto+0x4d>
jmp    114c <lcd_goto+0x3c>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
je     1169 <lcd_goto+0x59>
jmp    1170 <lcd_goto+0x60>
movl   $0x0,-0xc(%rbp)
jmp    1170 <lcd_goto+0x60>
movl   $0x40,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x7f,%eax
or     $0x80,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
xor    %esi,%esi
call   1030 <send_gpio@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lcd_goto>:
cmp    $0x1,%edi
jg     113b <lcd_goto+0x2b>
cmp    $0xf,%esi
jg     113b <lcd_goto+0x2b>
xor    %eax,%eax
cmp    $0x1,%edi
sete   %al
shl    $0x6,%eax
test   %edi,%edi
cmove  %edi,%eax
add    %esi,%eax
or     $0x80,%eax
movzbl %al,%edi
xor    %esi,%esi
jmp    1030 <send_gpio@plt>
ret

LLVM IR (-O0):
define void @lcd_goto(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %25
9: ; preds = %2
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 16
br i1 %11, label %12, label %25
12: ; preds = %9
store i32 0, i32* %5
%13 = load i32, i32* %3
switch i32 %13, label %16 [
i32 0, label %14
i32 1, label %15
]
14: ; preds = %12
store i32 0, i32* %5
br label %16
15: ; preds = %12
store i32 64, i32* %5
br label %16
16: ; preds = %12, %15, %14
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = add nsw i32 %18, %17
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = and i32 %20, 127
%22 = or i32 128, %21
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = call i32 @send_gpio(i32 %23, i32 0)
br label %25
25: ; preds = %16, %9, %2
ret void
}

LLVM IR (-O2):
define void @lcd_goto(i32 %0, i32 %1) {
%3 = icmp slt i32 %0, 2
%4 = icmp slt i32 %1, 16
%5 = and i1 %3, %4
br i1 %5, label %6, label %15
6: ; preds = %2
%7 = icmp eq i32 %0, 1
%8 = select i1 %7, i32 64, i32 0
%9 = icmp eq i32 %0, 0
%10 = select i1 %9, i32 0, i32 %8
%11 = add nsw i32 %10, %1
%12 = and i32 %11, 127
%13 = or i32 %12, 128
%14 = tail call i32 @send_gpio(i32 %13, i32 0)
br label %15
15: ; preds = %6, %2
ret void
}