#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 */

/* Variables and functions */
scalar_t__ KEYPAD_Hit();
int /*<<< orphan*/ KEYPAD_Init(int *);
int /*<<< orphan*/ LCD_Goto(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ LCD_Init();
int /*<<< orphan*/ LCD_WriteString(char *);
int /*<<< orphan*/ LED_GetState();
int /*<<< orphan*/ LED_Init(int, int);
int /*<<< orphan*/ LED_SetState(int);
int /*<<< orphan*/ TIMER0_Init(int);
int /*<<< orphan*/ delay(int);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/);
int main() {
  LCD_Init();
  LED_Init(1, 1);
  int keypad[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '0', '#'};
  KEYPAD_Init(keypad);
  TIMER0_Init(1000);
  delay(2);
  char buff[80];
  int i = 0;
  while (1) {
    if (KEYPAD_Hit()) {
      sprintf(buff, "%d", i++);
      LCD_Goto(0, 0);
      LCD_WriteString(buff);
      LED_SetState(!LED_GetState());
      while (KEYPAD_Hit())
        ;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10a0 <LCD_Init@plt>
mov    $0x1,%esi
mov    %esi,%edi
call   1030 <LED_Init@plt>
lea    -0x40(%rbp),%rdi
lea    0xe10(%rip),%rsi
mov    $0x30,%edx
call   1070 <memcpy@plt>
lea    -0x40(%rbp),%rdi
call   1080 <KEYPAD_Init@plt>
mov    $0x3e8,%edi
call   10b0 <TIMER0_Init@plt>
mov    $0x2,%edi
call   1060 <delay@plt>
movl   $0x0,-0x94(%rbp)
mov    $0x0,%al
call   10c0 <KEYPAD_Hit@plt>
cmp    $0x0,%rax
je     129f <main+0xdf>
lea    -0x90(%rbp),%rdi
mov    -0x94(%rbp),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
lea    0xddf(%rip),%rsi
call   10e0 <sprintf@plt>
xor    %esi,%esi
mov    %esi,%edi
call   1090 <LCD_Goto@plt>
lea    -0x90(%rbp),%rdi
call   1050 <LCD_WriteString@plt>
mov    $0x0,%al
call   1040 <LED_GetState@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   10d0 <LED_SetState@plt>
mov    $0x0,%al
call   10c0 <KEYPAD_Hit@plt>
cmp    $0x0,%rax
je     129a <main+0xda>
jmp    1284 <main+0xc4>
jmp    129f <main+0xdf>
jmp    1221 <main+0x61>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
xor    %eax,%eax
call   1090 <LCD_Init@plt>
mov    $0x1,%edi
mov    $0x1,%esi
call   1030 <LED_Init@plt>
movaps 0xe48(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe2c(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe10(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
call   1070 <KEYPAD_Init@plt>
mov    $0x3e8,%edi
call   10a0 <TIMER0_Init@plt>
mov    $0x2,%edi
call   1060 <delay@plt>
lea    0xe19(%rip),%r14
lea    0x30(%rsp),%rbx
xor    %ebp,%ebp
xchg   %ax,%ax
xor    %eax,%eax
call   10b0 <KEYPAD_Hit@plt>
test   %rax,%rax
je     1220 <main+0x70>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   10d0 <sprintf@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1080 <LCD_Goto@plt>
mov    %rbx,%rdi
call   1050 <LCD_WriteString@plt>
xor    %eax,%eax
call   1040 <LED_GetState@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <LED_SetState@plt>
xchg   %ax,%ax
xor    %eax,%eax
call   10b0 <KEYPAD_Hit@plt>
test   %rax,%rax
jne    1260 <main+0xb0>
add    $0x1,%ebp
jmp    1220 <main+0x70>

LLVM IR (-O0):
@__const.main.keypad = [12 x i32] [i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 42, i32 48, i32 35]
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [12 x i32]
%3 = alloca [80 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (...) @LCD_Init()
%6 = call i32 @LED_Init(i32 1, i32 1)
%7 = bitcast [12 x i32]* %2 to i8*
%8 = getelementptr inbounds [12 x i32], [12 x i32]* %2, i64 0, i64 0
%9 = call i32 @KEYPAD_Init(i32* %8)
%10 = call i32 @TIMER0_Init(i32 1000)
%11 = call i32 @delay(i32 2)
store i32 0, i32* %4
br label %12
12: ; preds = %0, %33
%13 = call i64 (...) @KEYPAD_Hit()
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %33
15: ; preds = %12
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
%19 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %17)
%20 = call i32 @LCD_Goto(i32 0, i32 0)
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%22 = call i32 @LCD_WriteString(i8* %21)
%23 = call i32 (...) @LED_GetState()
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
%26 = zext i1 %25 to i32
%27 = call i32 @LED_SetState(i32 %26)
br label %28
28: ; preds = %31, %15
%29 = call i64 (...) @KEYPAD_Hit()
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %28
br label %28
32: ; preds = %28
br label %33
33: ; preds = %32, %12
br label %12
}

LLVM IR (-O2):
@__const.main.keypad = [12 x i32] [i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 42, i32 48, i32 35]
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca [12 x i32]
%2 = alloca [80 x i8]
%3 = tail call i32 (...) @LCD_Init()
%4 = tail call i32 @LED_Init(i32 1, i32 1)
%5 = bitcast [12 x i32]* %1 to i8*
%6 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 0
%7 = call i32 @KEYPAD_Init(i32* %6)
%8 = call i32 @TIMER0_Init(i32 1000)
%9 = call i32 @delay(i32 2)
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
br label %11
11: ; preds = %27, %0
%12 = phi i32 [ %28, %27 ], [ 0, %0 ]
br label %13
13: ; preds = %11, %13
%14 = call i64 (...) @KEYPAD_Hit()
%15 = icmp eq i64 %14, 0
br i1 %15, label %13, label %16
16: ; preds = %13
%17 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %12)
%18 = call i32 @LCD_Goto(i32 0, i32 0)
%19 = call i32 @LCD_WriteString(i8* %10)
%20 = call i32 (...) @LED_GetState()
%21 = icmp eq i32 %20, 0
%22 = zext i1 %21 to i32
%23 = call i32 @LED_SetState(i32 %22)
br label %24
24: ; preds = %24, %16
%25 = call i64 (...) @KEYPAD_Hit()
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %24
27: ; preds = %24
%28 = add nuw nsw i32 %12, 1
br label %11
}