#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;

/* Variables and functions */
int lcd_send_cmd(int);
int lcd_putc(char c) {
  int ret;
  uint8_t c1 = (c & 0xf0) >> 4;
  uint8_t c2 = c & 0x0f;
  ret = lcd_send_cmd(0x02);
  if (ret)
    return ret;
  ret = lcd_send_cmd(c1);
  if (ret)
    return ret;
  return lcd_send_cmd(c2);
}


x86 assembly (clang, -O0):
<lcd_putc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
and    $0xf0,%eax
sar    $0x4,%eax
mov    %eax,-0x10(%rbp)
movsbl -0x5(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x14(%rbp)
mov    $0x2,%edi
call   1030 <lcd_send_cmd@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1159 <lcd_putc+0x49>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1184 <lcd_putc+0x74>
mov    -0x10(%rbp),%edi
call   1030 <lcd_send_cmd@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1179 <lcd_putc+0x69>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1184 <lcd_putc+0x74>
mov    -0x14(%rbp),%edi
call   1030 <lcd_send_cmd@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lcd_putc>:
push   %rbx
mov    %edi,%ebx
mov    $0x2,%edi
call   1030 <lcd_send_cmd@plt>
test   %eax,%eax
jne    1130 <lcd_putc+0x20>
movzbl %bl,%edi
shr    $0x4,%edi
call   1030 <lcd_send_cmd@plt>
test   %eax,%eax
je     1132 <lcd_putc+0x22>
pop    %rbx
ret
and    $0xf,%ebx
mov    %ebx,%edi
pop    %rbx
jmp    1030 <lcd_send_cmd@plt>

LLVM IR (-O0):
define i32 @lcd_putc(i8 signext %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8 %0, i8* %3
%7 = load i8, i8* %3
%8 = sext i8 %7 to i32
%9 = and i32 %8, 240
%10 = ashr i32 %9, 4
store i32 %10, i32* %5
%11 = load i8, i8* %3
%12 = sext i8 %11 to i32
%13 = and i32 %12, 15
store i32 %13, i32* %6
%14 = call i32 @lcd_send_cmd(i32 2)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %1
%18 = load i32, i32* %4
store i32 %18, i32* %2
br label %29
19: ; preds = %1
%20 = load i32, i32* %5
%21 = call i32 @lcd_send_cmd(i32 %20)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = load i32, i32* %4
store i32 %25, i32* %2
br label %29
26: ; preds = %19
%27 = load i32, i32* %6
%28 = call i32 @lcd_send_cmd(i32 %27)
store i32 %28, i32* %2
br label %29
29: ; preds = %26, %24, %17
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
define i32 @lcd_putc(i8 signext %0) {
%2 = zext i8 %0 to i32
%3 = and i32 %2, 15
%4 = tail call i32 @lcd_send_cmd(i32 2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %1
%7 = lshr i32 %2, 4
%8 = tail call i32 @lcd_send_cmd(i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @lcd_send_cmd(i32 %3)
br label %12
12: ; preds = %6, %1, %10
%13 = phi i32 [ %11, %10 ], [ %4, %1 ], [ %8, %6 ]
ret i32 %13
}