#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 */
int /*<<< orphan*/ execSysCall(int, int, int, int /*<<< orphan*/);
int getChar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putChar(char);
void ringingKeyboard() {
  int c, i = 0;
  printf("Write after this message:\n>");
  while ((c = getChar()) != '\n') {
    if (c == '\b') {
      if (i > 0) {
        putChar(c);
        i--;
      }
      execSysCall(0x0C80, 500, 440 + (c * 100), 0);
    } else {
      putChar(c);
      execSysCall(0x0C80, 500, 440 + (c * 100), 0);
      i++;
    }
  }
  putChar('\n');
}


x86 assembly (clang, -O0):
<ringingKeyboard>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
lea    0xeaa(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <getChar@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xa,%eax
je     11ea <ringingKeyboard+0xaa>
cmpl   $0x8,-0x4(%rbp)
jne    11b6 <ringingKeyboard+0x76>
cmpl   $0x0,-0x8(%rbp)
jle    1196 <ringingKeyboard+0x56>
mov    -0x4(%rbp),%eax
movsbl %al,%edi
call   1050 <putChar@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
imul   $0x64,-0x4(%rbp),%edx
add    $0x1b8,%edx
mov    $0xc80,%edi
mov    $0x1f4,%esi
xor    %ecx,%ecx
call   1060 <execSysCall@plt>
jmp    11e5 <ringingKeyboard+0xa5>
mov    -0x4(%rbp),%eax
movsbl %al,%edi
call   1050 <putChar@plt>
imul   $0x64,-0x4(%rbp),%edx
add    $0x1b8,%edx
mov    $0xc80,%edi
mov    $0x1f4,%esi
xor    %ecx,%ecx
call   1060 <execSysCall@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    115b <ringingKeyboard+0x1b>
mov    $0xa,%edi
call   1050 <putChar@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ringingKeyboard>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
call   1040 <printf@plt>
xor    %ebp,%ebp
jmp    1176 <ringingKeyboard+0x36>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0xc80,%edi
mov    $0x1f4,%esi
mov    $0x4d8,%edx
xor    %ecx,%ecx
call   1060 <execSysCall@plt>
xor    %eax,%eax
call   1030 <getChar@plt>
cmp    $0x8,%eax
je     11b0 <ringingKeyboard+0x70>
mov    %eax,%ebx
cmp    $0xa,%eax
je     11c3 <ringingKeyboard+0x83>
movsbl %bl,%edi
call   1050 <putChar@plt>
imul   $0x64,%ebx,%edx
add    $0x1b8,%edx
mov    $0xc80,%edi
mov    $0x1f4,%esi
xor    %ecx,%ecx
call   1060 <execSysCall@plt>
add    $0x1,%ebp
jmp    1176 <ringingKeyboard+0x36>
test   %ebp,%ebp
jle    1160 <ringingKeyboard+0x20>
mov    $0x8,%edi
call   1050 <putChar@plt>
add    $0xffffffff,%ebp
jmp    1160 <ringingKeyboard+0x20>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <putChar@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"Write after this message:\0A>\00"
define void @ringingKeyboard() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %2
%3 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %34, %0
%5 = call i32 (...) @getChar()
store i32 %5, i32* %1
%6 = icmp ne i32 %5, 10
br i1 %6, label %7, label %35
7: ; preds = %4
%8 = load i32, i32* %1
%9 = icmp eq i32 %8, 8
br i1 %9, label %10, label %24
10: ; preds = %7
%11 = load i32, i32* %2
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i32, i32* %1
%15 = trunc i32 %14 to i8
%16 = call i32 @putChar(i8 signext %15)
%17 = load i32, i32* %2
%18 = add nsw i32 %17, -1
store i32 %18, i32* %2
br label %19
19: ; preds = %13, %10
%20 = load i32, i32* %1
%21 = mul nsw i32 %20, 100
%22 = add nsw i32 440, %21
%23 = call i32 @execSysCall(i32 3200, i32 500, i32 %22, i32 0)
br label %34
24: ; preds = %7
%25 = load i32, i32* %1
%26 = trunc i32 %25 to i8
%27 = call i32 @putChar(i8 signext %26)
%28 = load i32, i32* %1
%29 = mul nsw i32 %28, 100
%30 = add nsw i32 440, %29
%31 = call i32 @execSysCall(i32 3200, i32 500, i32 %30, i32 0)
%32 = load i32, i32* %2
%33 = add nsw i32 %32, 1
store i32 %33, i32* %2
br label %34
34: ; preds = %24, %19
br label %4
35: ; preds = %4
%36 = call i32 @putChar(i8 signext 10)
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"Write after this message:\0A>\00"
define void @ringingKeyboard() {
%1 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %2
2: ; preds = %20, %0
%3 = phi i32 [ 0, %0 ], [ %21, %20 ]
%4 = tail call i32 (...) @getChar()
switch i32 %4, label %13 [
i32 10, label %22
i32 8, label %5
]
5: ; preds = %2
%6 = icmp sgt i32 %3, 0
br i1 %6, label %7, label %10
7: ; preds = %5
%8 = tail call i32 @putChar(i8 signext 8)
%9 = add nsw i32 %3, -1
br label %10
10: ; preds = %7, %5
%11 = phi i32 [ %9, %7 ], [ %3, %5 ]
%12 = tail call i32 @execSysCall(i32 3200, i32 500, i32 1240, i32 0)
br label %20
13: ; preds = %2
%14 = trunc i32 %4 to i8
%15 = tail call i32 @putChar(i8 signext %14)
%16 = mul nsw i32 %4, 100
%17 = add nsw i32 %16, 440
%18 = tail call i32 @execSysCall(i32 3200, i32 500, i32 %17, i32 0)
%19 = add nsw i32 %3, 1
br label %20
20: ; preds = %13, %10
%21 = phi i32 [ %11, %10 ], [ %19, %13 ]
br label %2
22: ; preds = %2
%23 = tail call i32 @putChar(i8 signext 10)
ret void
}