#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 */
char SH_GetChar();
int /*<<< orphan*/ bsp_delayMs(int);
int /*<<< orphan*/ bsp_init();
int /*<<< orphan*/ led_toggle(int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  bsp_init();
  char console_in;
  int counter;
  counter = 0;
  while (1) {
    bsp_delayMs(1000);
    led_toggle(1);
    counter = (counter + 1) % 100;
    printf("counter:%03d\n\r", counter);
    printf("Presione una tecla y enter:\n\r");
    console_in = SH_GetChar();
    printf("Se presiono:0x%02X\n\r", console_in);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <bsp_init@plt>
movl   $0x0,-0xc(%rbp)
mov    $0x3e8,%edi
call   1060 <bsp_delayMs@plt>
mov    $0x1,%edi
call   1070 <led_toggle@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <SH_GetChar@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%esi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    116d <main+0x1d>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <bsp_init@plt>
lea    0xe9a(%rip),%r14
lea    0xea2(%rip),%r15
lea    0xeb9(%rip),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    $0x3e8,%edi
call   1060 <bsp_delayMs@plt>
mov    $0x1,%edi
call   1070 <led_toggle@plt>
add    $0x1,%ebx
movslq %ebx,%rbx
imul   $0x51eb851f,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <SH_GetChar@plt>
movsbl %al,%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1180 <main+0x30>

LLVM IR (-O0):
@.str = [15 x i8] c"counter:%03d\0A\0D\00"
@.str.1 = [30 x i8] c"Presione una tecla y enter:\0A\0D\00"
@.str.2 = [21 x i8] c"Se presiono:0x%02X\0A\0D\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @bsp_init()
store i32 0, i32* %3
br label %5
5: ; preds = %0, %5
%6 = call i32 @bsp_delayMs(i32 1000)
%7 = call i32 @led_toggle(i32 1)
%8 = load i32, i32* %3
%9 = add nsw i32 %8, 1
%10 = srem i32 %9, 100
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%14 = call signext i8 (...) @SH_GetChar()
store i8 %14, i8* %2
%15 = load i8, i8* %2
%16 = sext i8 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %5
}

LLVM IR (-O2):
@.str = [15 x i8] c"counter:%03d\0A\0D\00"
@.str.1 = [30 x i8] c"Presione una tecla y enter:\0A\0D\00"
@.str.2 = [21 x i8] c"Se presiono:0x%02X\0A\0D\00"
define i32 @main() {
%1 = tail call i32 (...) @bsp_init()
br label %2
2: ; preds = %2, %0
%3 = phi i32 [ 0, %0 ], [ %7, %2 ]
%4 = tail call i32 @bsp_delayMs(i32 1000)
%5 = tail call i32 @led_toggle(i32 1)
%6 = add nsw i32 %3, 1
%7 = srem i32 %6, 100
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call signext i8 (...) @SH_GetChar()
%11 = sext i8 %10 to i32
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %11)
br label %2
}